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 15:37:09 GMT, altrisi <duke 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.

Created https://bugs.openjdk.org/browse/JDK-8365878 for you.

src/jdk.jshell/share/classes/jdk/jshell/tool/resources/TOOLING.jsh line 12:

> 10: void javap(Class<?> type) throws Exception {
> 11:     try {
> 12:         if (type.isPrimitive() || type.isHidden() || type.isArray()) throw new IllegalArgumentException("Type not supported: " + type);

The message should say the given class has no class file. And this check should be hoisted out of the try-catch.

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.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/26864#issuecomment-3207681627
PR Review Comment: https://git.openjdk.org/jdk/pull/26864#discussion_r2288782092
PR Review Comment: https://git.openjdk.org/jdk/pull/26864#discussion_r2288654271


More information about the compiler-dev mailing list