On Thu, 5 Mar 2026 03:51:37 GMT, Chen Liang <[email protected]> wrote:
> The bootstrap methods in java.lang.runtime do not have explicit requirements > for the lookup; they largely ignored it until they suddenly start using the > lookups. > > Currently, the unprivileged lookup behavior is as follows: > 1. `ObjectMethods.bootstrap` for `equals` and `hashCode` may fail with > `IllegalAccessException` if the lookup is used to generate hidden classes; it > may be ignored if no hidden class is needed. > 2. `ObjectMethods.bootstrap` for `toString` fails with a `RuntimeException` > caused by a `StringConcatException`. > 3. `SwitchBootstraps` methods fail with `IllegalArgumentException` caused by > `IllegalAccessException`. > > In contrast, `LambdaMetafactory` and `StringConcatFactory` throw their own > types of exceptions. > > In this patch, I decided to make all these java.lang.runtime BSMs throw > `IllegalArgumentException` without a cause for any unprivileged lookup that > cannot support bytecode generation. Future BSMs should also reject > unprivileged lookup eagerly to allow implementations to have bytecode > generation freedom. The `IllegalArgumentException` is consistent with other > consistency checks done by these BSMs. > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). This pull request has now been integrated. Changeset: 5a19e49d Author: Chen Liang <[email protected]> URL: https://git.openjdk.org/jdk/commit/5a19e49dc48b9fb2cf480dab890922a2de59d2de Stats: 96 lines in 5 files changed: 42 ins; 29 del; 25 mod 8378796: java.lang.runtime bootstrap methods missing lookup validation Reviewed-by: jvernee ------------- PR: https://git.openjdk.org/jdk/pull/30067
