Skip to content

8365878: jshell TOOLING's javap should use binary names #26864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ void jmod(String... args) { run("jmod", args); }
void jpackage(String... args) { run("jpackage", args); }

void javap(Class<?> type) throws Exception {
if (type.isPrimitive() || type.isHidden() || type.isArray()) throw new IllegalArgumentException("Type has no class file: " + type);
try {
var name = type.getCanonicalName();
if (name == null) throw new IllegalArgumentException("Type not supported: " + type);
var name = type.getName();
if (type == Class.forName(name, false, ClassLoader.getSystemClassLoader())) {
run("javap", "-c", "-v", "-s", name);
return;
Expand Down
31 changes: 29 additions & 2 deletions test/langtools/jdk/jshell/ToolingTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,7 @@

/*
* @test
* @bug 8306560
* @bug 8306560 8365878
* @summary Tests for snippets and methods defined in TOOLING.jsh
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
Expand Down Expand Up @@ -79,4 +79,31 @@ public void testDisassembleNewRecordClass() {
)
);
}

@Test
public void testDisassembleBuiltinInnerClass() {
test(
a -> assertCommand(a, "/open TOOLING",
""),
a -> assertCommandUserOutputContains(a, "javap(Base64.Decoder.class)",
"Classfile jrt:/java.base/java/util/Base64$Decoder.class",
"class java.util.Base64$Decoder",
"SourceFile: \"Base64.java\"")
);
}

@Test
public void testDisassembleAnonymousClass() {
test(
a -> assertCommand(a, "Object o() {return new ArrayList<>(){ };}", // must be in a method or it won't be anonymous
"| created method o()"),
a -> assertCommand(a, "/open TOOLING",
""),
a -> assertCommandUserOutputContains(a, "javap(o().getClass())",
"Classfile ", // Classfile /.../TOOLING-16063368030094702464.class
" extends java.util.ArrayList<java.lang.Object>", // class REPL.$JShell$22$1 extends java.util.ArrayList<java.lang.Object>
"SourceFile: \"$JShell$" // SourceFile: "$JShell$22.java"
)
);
}
}