Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v7]

2024-04-24 Thread Per Minborg
On Mon, 22 Apr 2024 13:46:59 GMT, Maurizio Cimadamore  
wrote:

>> Per Minborg has updated the pull request with a new target base due to a 
>> merge or a rebase. The incremental webrev excludes the unrelated changes 
>> brought in by the merge/rebase. The pull request contains 12 additional 
>> commits since the last revision:
>> 
>>  - Simplify tests
>>  - Add a test for null arg
>>  - Add a test for findOrThrow()
>>  - Merge branch 'master' into symbol-lookup-findorthrow
>>  - Change exception type
>>  - Update src/java.base/share/classes/java/lang/foreign/package-info.java
>>
>>Co-authored-by: Jorn Vernee 
>>  - Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
>>
>>Co-authored-by: Maurizio Cimadamore 
>> <54672762+mcimadam...@users.noreply.github.com>
>>  - Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
>>
>>Co-authored-by: Maurizio Cimadamore 
>> <54672762+mcimadam...@users.noreply.github.com>
>>  - Fix typo
>>  - Update after PR comments
>>  - ... and 2 more: https://git.openjdk.org/jdk/compare/099a64e8...0e06e0d6
>
> test/jdk/java/foreign/loaderLookup/TestSymbolLookupFindOrThrow.java line 41:
> 
>> 39: 
>> 40: static {
>> 41: System.loadLibrary("Foo");
> 
> Where is this lib defined?

it is defined in the sub-folder `lookup` in the file `libFoo.c`.

-

PR Review Comment: https://git.openjdk.org/jdk/pull/18474#discussion_r1577755855


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v8]

2024-04-24 Thread Per Minborg
> 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.

Per Minborg has updated the pull request incrementally with one additional 
commit since the last revision:

  Remove redundant test

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18474/files
  - new: https://git.openjdk.org/jdk/pull/18474/files/0e06e0d6..31d92589

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18474=07
 - incr: https://webrevs.openjdk.org/?repo=jdk=18474=06-07

  Stats: 7 lines in 1 file changed: 0 ins; 7 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/18474.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18474/head:pull/18474

PR: https://git.openjdk.org/jdk/pull/18474


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v7]

2024-04-22 Thread Maurizio Cimadamore
On Mon, 22 Apr 2024 08:46:53 GMT, Per Minborg  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.
>
> Per Minborg has updated the pull request with a new target base due to a 
> merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains 12 additional 
> commits since the last revision:
> 
>  - Simplify tests
>  - Add a test for null arg
>  - Add a test for findOrThrow()
>  - Merge branch 'master' into symbol-lookup-findorthrow
>  - Change exception type
>  - Update src/java.base/share/classes/java/lang/foreign/package-info.java
>
>Co-authored-by: Jorn Vernee 
>  - Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
>
>Co-authored-by: Maurizio Cimadamore 
> <54672762+mcimadam...@users.noreply.github.com>
>  - Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
>
>Co-authored-by: Maurizio Cimadamore 
> <54672762+mcimadam...@users.noreply.github.com>
>  - Fix typo
>  - Update after PR comments
>  - ... and 2 more: https://git.openjdk.org/jdk/compare/9a68d47d...0e06e0d6

test/jdk/java/foreign/loaderLookup/TestSymbolLookupFindOrThrow.java line 41:

> 39: 
> 40: static {
> 41: System.loadLibrary("Foo");

Where is this lib defined?

test/jdk/java/foreign/loaderLookup/TestSymbolLookupFindOrThrow.java line 58:

> 56: @Test
> 57: void findOrThrowNullArg() {
> 58: assertThrows(NullPointerException.class, () ->

I believe this should already be checked by the TestNulls test - which is a 
test that automatically checks that _all_ API methods handle nulls accordingly. 
Please check that, and maybe remove this?

-

PR Review Comment: https://git.openjdk.org/jdk/pull/18474#discussion_r1574788219
PR Review Comment: https://git.openjdk.org/jdk/pull/18474#discussion_r1574786946


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v7]

2024-04-22 Thread Per Minborg
> 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.

Per Minborg has updated the pull request with a new target base due to a merge 
or a rebase. The incremental webrev excludes the unrelated changes brought in 
by the merge/rebase. The pull request contains 12 additional commits since the 
last revision:

 - Simplify tests
 - Add a test for null arg
 - Add a test for findOrThrow()
 - Merge branch 'master' into symbol-lookup-findorthrow
 - Change exception type
 - Update src/java.base/share/classes/java/lang/foreign/package-info.java
   
   Co-authored-by: Jorn Vernee 
 - Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
   
   Co-authored-by: Maurizio Cimadamore 
<54672762+mcimadam...@users.noreply.github.com>
 - Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
   
   Co-authored-by: Maurizio Cimadamore 
<54672762+mcimadam...@users.noreply.github.com>
 - Fix typo
 - Update after PR comments
 - ... and 2 more: https://git.openjdk.org/jdk/compare/76cd531f...0e06e0d6

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18474/files
  - new: https://git.openjdk.org/jdk/pull/18474/files/e2f6c4c9..0e06e0d6

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18474=06
 - incr: https://webrevs.openjdk.org/?repo=jdk=18474=05-06

  Stats: 91042 lines in 1455 files changed: 42444 ins; 38886 del; 9712 mod
  Patch: https://git.openjdk.org/jdk/pull/18474.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18474/head:pull/18474

PR: https://git.openjdk.org/jdk/pull/18474


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v6]

2024-04-18 Thread Phil Race
On Thu, 18 Apr 2024 11:32:13 GMT, Per Minborg  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.
>
> Per Minborg has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Change exception type

I'm OK with the minimal changes in the desktop code.

-

Marked as reviewed by prr (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/18474#pullrequestreview-2009552015


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v6]

2024-04-18 Thread Maurizio Cimadamore
On Thu, 18 Apr 2024 11:32:13 GMT, Per Minborg  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.
>
> Per Minborg has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Change exception type

We need a test for the new method, e.g. to check that the right exception is 
thrown, and the message is right. The fact that no test needed to be updated 
when you changed the exception type is a smell.

-

Changes requested by mcimadamore (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/18474#pullrequestreview-2009500390


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v6]

2024-04-18 Thread Jorn Vernee
On Thu, 18 Apr 2024 11:32:13 GMT, Per Minborg  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.
>
> Per Minborg has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Change exception type

Marked as reviewed by jvernee (Reviewer).

-

PR Review: https://git.openjdk.org/jdk/pull/18474#pullrequestreview-2008729407


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v6]

2024-04-18 Thread Per Minborg
> 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.

Per Minborg has updated the pull request incrementally with one additional 
commit since the last revision:

  Change exception type

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18474/files
  - new: https://git.openjdk.org/jdk/pull/18474/files/2ebac9fc..e2f6c4c9

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18474=05
 - incr: https://webrevs.openjdk.org/?repo=jdk=18474=04-05

  Stats: 4 lines in 1 file changed: 1 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/18474.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18474/head:pull/18474

PR: https://git.openjdk.org/jdk/pull/18474


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v5]

2024-04-17 Thread Per Minborg
> 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.

Per Minborg has updated the pull request incrementally with one additional 
commit since the last revision:

  Update src/java.base/share/classes/java/lang/foreign/package-info.java
  
  Co-authored-by: Jorn Vernee 

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18474/files
  - new: https://git.openjdk.org/jdk/pull/18474/files/fa86d837..2ebac9fc

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18474=04
 - incr: https://webrevs.openjdk.org/?repo=jdk=18474=03-04

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/18474.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18474/head:pull/18474

PR: https://git.openjdk.org/jdk/pull/18474


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v4]

2024-04-16 Thread Jorn Vernee
On Mon, 15 Apr 2024 14:02:56 GMT, Per Minborg  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.
>
> Per Minborg has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
>   
>   Co-authored-by: Maurizio Cimadamore 
> <54672762+mcimadam...@users.noreply.github.com>

src/java.base/share/classes/java/lang/foreign/package-info.java line 114:

> 112:  *
> 113:  * Here, we obtain a {@linkplain java.lang.foreign.Linker#nativeLinker() 
> native linker}
> 114:  * and we use it to {@linkplain 
> java.lang.foreign.SymbolLookup#findOrThrow(java.lang.String)}

Looks like the plain text was dropped here:
Suggestion:

 * and we use it to {@linkplain 
java.lang.foreign.SymbolLookup#findOrThrow(java.lang.String) look up}

-

PR Review Comment: https://git.openjdk.org/jdk/pull/18474#discussion_r1567435862


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v4]

2024-04-15 Thread Jorn Vernee
On Mon, 15 Apr 2024 14:02:56 GMT, Per Minborg  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.
>
> Per Minborg has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
>   
>   Co-authored-by: Maurizio Cimadamore 
> <54672762+mcimadam...@users.noreply.github.com>

Marked as reviewed by jvernee (Reviewer).

-

PR Review: https://git.openjdk.org/jdk/pull/18474#pullrequestreview-2001521250


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v4]

2024-04-15 Thread Maurizio Cimadamore
On Mon, 15 Apr 2024 14:02:56 GMT, Per Minborg  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.
>
> Per Minborg has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
>   
>   Co-authored-by: Maurizio Cimadamore 
> <54672762+mcimadam...@users.noreply.github.com>

Marked as reviewed by mcimadamore (Reviewer).

-

PR Review: https://git.openjdk.org/jdk/pull/18474#pullrequestreview-2001319293


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v4]

2024-04-15 Thread Per Minborg
> 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.

Per Minborg has updated the pull request incrementally with one additional 
commit since the last revision:

  Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
  
  Co-authored-by: Maurizio Cimadamore 
<54672762+mcimadam...@users.noreply.github.com>

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18474/files
  - new: https://git.openjdk.org/jdk/pull/18474/files/e173ff09..fa86d837

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18474=03
 - incr: https://webrevs.openjdk.org/?repo=jdk=18474=02-03

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/18474.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18474/head:pull/18474

PR: https://git.openjdk.org/jdk/pull/18474


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v3]

2024-04-15 Thread Maurizio Cimadamore
On Mon, 15 Apr 2024 13:48:09 GMT, Per Minborg  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.
>
> Per Minborg has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
>   
>   Co-authored-by: Maurizio Cimadamore 
> <54672762+mcimadam...@users.noreply.github.com>

src/java.base/share/classes/java/lang/foreign/SymbolLookup.java line 152:

> 150: 
> 151: /**
> 152:  * Returns the address of the symbol with the given name or throws 
> an Exception.

Suggestion:

 * Returns the address of the symbol with the given name or throws an 
exception.

-

PR Review Comment: https://git.openjdk.org/jdk/pull/18474#discussion_r1565837858


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v3]

2024-04-15 Thread Per Minborg
> 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.

Per Minborg has updated the pull request incrementally with one additional 
commit since the last revision:

  Update src/java.base/share/classes/java/lang/foreign/SymbolLookup.java
  
  Co-authored-by: Maurizio Cimadamore 
<54672762+mcimadam...@users.noreply.github.com>

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18474/files
  - new: https://git.openjdk.org/jdk/pull/18474/files/7de90243..e173ff09

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18474=02
 - incr: https://webrevs.openjdk.org/?repo=jdk=18474=01-02

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/18474.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18474/head:pull/18474

PR: https://git.openjdk.org/jdk/pull/18474


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v2]

2024-04-15 Thread Maurizio Cimadamore
On Mon, 15 Apr 2024 08:37:55 GMT, Per Minborg  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.
>
> Per Minborg has updated the pull request incrementally with two additional 
> commits since the last revision:
> 
>  - Fix typo
>  - Update after PR comments

src/java.base/share/classes/java/lang/foreign/SymbolLookup.java line 154:

> 152:  * Returns the address of the symbol with the given name or throws 
> an Exception.
> 153:  *
> 154:  * This is equivalent to the following code, but is more resource 
> efficient:

Suggestion:

 * This is equivalent to the following code, but is more efficient:

-

PR Review Comment: https://git.openjdk.org/jdk/pull/18474#discussion_r1565485693


Re: RFR: 8314592: Add shortcut to SymbolLookup::find [v2]

2024-04-15 Thread Per Minborg
> 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.

Per Minborg has updated the pull request incrementally with two additional 
commits since the last revision:

 - Fix typo
 - Update after PR comments

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18474/files
  - new: https://git.openjdk.org/jdk/pull/18474/files/159b9c44..7de90243

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18474=01
 - incr: https://webrevs.openjdk.org/?repo=jdk=18474=00-01

  Stats: 13 lines in 1 file changed: 3 ins; 2 del; 8 mod
  Patch: https://git.openjdk.org/jdk/pull/18474.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18474/head:pull/18474

PR: https://git.openjdk.org/jdk/pull/18474


Re: RFR: 8314592: Add shortcut to SymbolLookup::find

2024-04-11 Thread Maurizio Cimadamore
On Mon, 25 Mar 2024 14:56:23 GMT, Per Minborg  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: "

-

PR Review Comment: https://git.openjdk.org/jdk/pull/18474#discussion_r1560897671


Re: RFR: 8314592: Add shortcut to SymbolLookup::find

2024-04-11 Thread Maurizio Cimadamore
On Mon, 25 Mar 2024 14:56:23 GMT, Per Minborg  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 152:

> 150: 
> 151: /**
> 152:  * {@return the address of the symbol with the provided {@code name} 
> or throws an

I suggest using the same javadoc structure as the main `find` method. Note that 
there we have a summary, then a more detailed `@return` which talks about zero 
length memory segments. This should do the same.

src/java.base/share/classes/java/lang/foreign/SymbolLookup.java line 155:

> 153:  *  {@linkplain IllegalArgumentException} if no such address 
> can be found}
> 154:  *
> 155:  * This is a convenience method that provides better exception 
> messages compared

I would reframe this as: "this is equivalent to the following code, but with 
better exception message" (for consistency with other API points in FFM where 
we show what a method boils down to)

-

PR Review Comment: https://git.openjdk.org/jdk/pull/18474#discussion_r1560889723
PR Review Comment: https://git.openjdk.org/jdk/pull/18474#discussion_r1560893974


RFR: 8314592: Add shortcut to SymbolLookup::find

2024-04-11 Thread Per Minborg
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.

-

Commit messages:
 - Remove white space
 - Add SymbolLookup::findOrThrow

Changes: https://git.openjdk.org/jdk/pull/18474/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk=18474=00
  Issue: https://bugs.openjdk.org/browse/JDK-8314592
  Stats: 93 lines in 21 files changed: 30 ins; 0 del; 63 mod
  Patch: https://git.openjdk.org/jdk/pull/18474.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18474/head:pull/18474

PR: https://git.openjdk.org/jdk/pull/18474