RFR: 8365878: jshell TOOLING's javap should use binary names
Chen Liang
liach at openjdk.org
Thu Aug 21 15:19:33 UTC 2025
On Wed, 20 Aug 2025 16:43:32 GMT, altrisi <duke at openjdk.org> wrote:
>> 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.
Essentially the problem is the name from `getCanonicalName` is wrong. javap accepts both dot and slash notations, so `getName` is sufficient. Also the `type.getClassLoader().getResourceAsStream(name)` is wrong if the type is loaded by the bootstrap class loader.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26864#discussion_r2288781037
More information about the compiler-dev
mailing list