openrewrite / openrewrite/rewrite-migrate-java
Replace Optional.get with Optional::orElseThrow
Open
Nobody has claimed this yet.
recipe
- Dominant language
- Java
- Stars
- 156
- Forks
- 130
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 21
Description
Java 10 recommends orElseThrow instead of get:
https://docs.oracle.com/javase/10/docs/api/java/util/Optional.html#get()
Some background:
http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-April/040531.html
val value = Optional.of("").get();
val value = Optional.of("").orElseThrow(NoSuchElementException::new);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the migration recipe and its tests for Optional.get in this repository, then compare the requested Java 10 transformation with the linked Optional documentation. Done means the recipe replaces the shown get() call with the requested orElseThrow form and the relevant tests verify the resulting source.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100