Avoid work in Optional.orElse() calls

Any code inside the orElse() will always be called, even if the result
isn't used because the optional is present. This is wasteful at a
minimum and can be actively harmful (as seen in [1]) because of side
effects or performance impacts. Fix that by replacing all orElse() calls
that create new instances or do non-constant work with a call to
orElseGet().

It would be nice if there were an ErrorProne checker for this, but one
doesn't exist yet.

[1] https://gerrit-review.googlesource.com/c/gerrit/+/417915/comment/0ea287cd_bfecb7f2/

Release-Notes: skip
Change-Id: I2d3d59da88cd04a2e589b7255fc0877719a57432
2 files changed
tree: 66caa91bf43a431221dc930661469c0a75dd2b59
  1. src/
  2. .gitignore
  3. .zuul.yaml
  4. BUILD
  5. LICENSE
  6. README.md
README.md

plugin-manager

Gerrit web-based plugin manager.

To enable this plugin, please look at the configuration guide