RFR: Optional refactoring [v2]

Andrei Rybak duke at openjdk.org
Tue Mar 28 12:54:58 UTC 2023


> This is a follow-up to the email https://mail.openjdk.org/pipermail/jmh-dev/2023-January/003562.html
> 
> `java.util.Optional` isn't `Serializeable`. Because of that `org.openjdk.jmh.runner.options.TestOptions` fails with `java.io.NotSerializableException: java.util.Optional`, when  `org.openjdk.jmh.util.Optional` is completely replaced with `java.util.Optional`. See [test results on branch `java-util-optional`](https://github.com/rybak/jmh/actions/runs/4326921418), ([one commit](https://github.com/rybak/jmh/commit/25b9cb382be7285a51446976247d036ac855fc91) on top of initial state of this PR).
> 
> I didn't look further into possibility of removing `Optional`s as fields of class `CommandLineOptions`. I think that the refactoring up until the drop-in replacement to `java.util.Optional` might still be worth it, at least from the point of making it more approachable for people who are familiar with `java.util.Optional`.  So here are these changes for your consideration. Details are in the commit messages.

Andrei Rybak has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains two new commits since the last revision:

 - Runner: replace orAnother() with orElseGet()
   
   Refactor usage of method org.openjdk.jmh.util.Optional#orAnother in
   class Runner using new method orElseGet() with lazy `Supplier`s as per
   comment added in commit db1bc365 (7902576: Lazy query for current JVM
   args in Runner, 2020-01-20).  Clean up imports, while we're here.
 - OptionsBuilder: don't pass empty Optional to orAnother()
   
   Passing an empty Optional to method orAnother() of class
   org.openjdk.jmh.util.Optional is a no-op.  Stop doing it in getters
   getJvmArgs(), getJvmArgsAppend(), and getJvmArgsPrepend() of class
   OptionsBuilder.

-------------

Changes:
  - all: https://git.openjdk.org/jmh/pull/98/files
  - new: https://git.openjdk.org/jmh/pull/98/files/2d8146a5..1e847757

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jmh&pr=98&range=01
 - incr: https://webrevs.openjdk.org/?repo=jmh&pr=98&range=00-01

  Stats: 315 lines in 12 files changed: 114 ins; 8 del; 193 mod
  Patch: https://git.openjdk.org/jmh/pull/98.diff
  Fetch: git fetch https://git.openjdk.org/jmh.git pull/98/head:pull/98

PR: https://git.openjdk.org/jmh/pull/98


More information about the jmh-dev mailing list