RFR: 8314592: Add shortcut to SymbolLookup::find
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Apr 11 11:46:40 UTC 2024
On Mon, 25 Mar 2024 14:56:23 GMT, Per Minborg <pminborg at openjdk.org> wrote:
> While `SymbolLookup` correctly uses an `Optional` return to denote whether a symbol has been found by the lookup or not (which enables composition of symbol lookups), many clients end up just calling `Optional::get`, or `Optional::orElseThrow()` on the result.
>
> This PR proposes to add a convenience method `SymbolLookup::findOrThrow` that will do a lookup and, if no symbol can be found, throws an `IllegalArgumentException` with a relevant exception message.
src/java.base/share/classes/java/lang/foreign/SymbolLookup.java line 177:
> 175: }
> 176: throw new IllegalArgumentException(
> 177: "Unable to to find a symbol with the name: " + name);
Another, more succinct, text could be "Symbol not found: <name>"
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18474#discussion_r1560897671
More information about the core-libs-dev
mailing list