RFR: 8285401: Proxy class initializer should use 3-arg `Class.forName` to avoid unnecessary class initialization [v3]
liach
duke at openjdk.java.net
Tue May 24 13:12:58 UTC 2022
On Tue, 24 May 2022 05:36:30 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:
>> liach has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Move the try catch block as it doesn't throw checked exceptions
>
> src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java line 605:
>
>> 603: mv.visitLdcInsn(Type.getObjectType(dotToSlash(className)));
>> 604: mv.visitMethodInsn(INVOKEVIRTUAL, JL_CLASS,
>> 605: "getClassLoader", "()" + LJL_CLASSLOADER, false);
>
> Hello @liach, should this instead be using the (application supplied) `loader` returned by the call to `ProxyGenerator.getClassLoader()` or maybe the `loader` member in the `ProxyGenerator` itself?
This is equivalent to `jdk.proxy5.$Proxy5.class.getClassLoader()` in Java source code, so this is exactly the application-supplied loader, which also uses the same loader as the previous behavior of `forName` calls.
If you want to pass the loader from `ProxyGenerator` to the proxy, it requires complex tricks. Hidden classes won't work due to serialization incompatibility; accessor methods would be defined in `jdk.internal` and exported specifically to the proxy modules, but writing a class so each proxy gets its loader while what I wrote can already do is overkill.
> test/jdk/java/lang/reflect/Proxy/LazyInitializationTest.java line 56:
>
>> 54:
>> 55: value.m(new Parameter());
>> 56: Assert.assertTrue(initialized, "parameter type initialized after instantiation");
>
>> "parameter type initialized after instantiation"
>
> Since this is the text that gets displayed/reported when the assertion fails, should this instead be "parameter type not initialized"?
The rendered text for testng assert is `message expected: value actual: value`, so on a mismatch, it would print `parameter type initialized after instantiation expected: true actual: false`
-------------
PR: https://git.openjdk.java.net/jdk/pull/8800
More information about the core-libs-dev
mailing list