RFR: 8365878: jshell TOOLING's javap should use binary names
altrisi
duke at openjdk.org
Thu Aug 21 15:19:33 UTC 2025
On Wed, 20 Aug 2025 16:14:34 GMT, Chen Liang <liach at openjdk.org> wrote:
>> This PR makes TOOLING.jsh's `javap` function support anonymous, local and built-in nested classes.
>>
>> Note that nested classes created in jshell would previously work, but not JDK ones as they'd miss the is built-in check (wrong name for `Class.forName`) and later throw an exception because of a null classloader.
>>
>> The rest of classes would fail the canonical name check, which wouldn't allow them to be disassembled.
>>
>> This change makes them work by changing the check from canonicalName != null to specific checks for unsupported types of classes, and doing Class.forName using the result of getName(), not the canonical name, for the built-in check.
>
> test/langtools/jdk/jshell/ToolingTest.java line 100:
>
>> 98: a -> assertCommand(a, "/open TOOLING",
>> 99: ""),
>> 100: a -> assertCommandUserOutputContains(a, "javap(Class.forName(\"sun.util.PreHashedMap$1\"))", // arbitrary built-in anonymous class
>
> I recommend the case to test against a generic class without a canonical name, such as `java.lang.invoke.DirectMethodHandle$Holder` generated by jlink; arbitrary javac artifacts is subject to renames because they have no linkage exposure, and these generic packages with antique code may be removed in a future maintenance and cause unexpected failures.
`java.lang.invoke.DirectMethodHandle$Holder` seems to have a canonical name, it's not anonymous:
jshell> Class.forName("java.lang.invoke.DirectMethodHandle$Holder").getCanonicalName()
$13 ==> "java.lang.invoke.DirectMethodHandle$Holder"
jshell> Class.forName("java.lang.invoke.DirectMethodHandle$Holder").isAnonymousClass()
$14 ==> false
Wasn't too sure on this test either way, considering I also added a test for user created anonymous classes, I think I'll just remove it instead. Any anonymous class can be refactored anytime and would have the same problem.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26864#discussion_r2288746130
More information about the compiler-dev
mailing list