JDK-8029100 : (reflect) arrays of a lambda proxy class returns wrong name
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 8,14
  • Priority: P3
  • Status: Resolved
  • Resolution: Not an Issue
  • Submitted: 2013-11-25
  • Updated: 2020-11-04
  • Resolved: 2020-11-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 15
15Resolved
Related Reports
Relates :  
Description
Peter wites:

Speaking of names, the following test:

package pkg;
  
public class Test {
     public static void main(String[] args)
     {
         Runnable r = () -> {};
         Class<?> c = r.getClass();
         Class<?> ac = java.lang.reflect.Array.newInstance(c, 0).getClass();
         System.out.println("c: " + c.getName() + " / " + c.getSimpleName());
         System.out.println("ac: " + ac.getName() + " / " + ac.getSimpleName());
      }
}
 

Prints:

c: pkg.Test$$Lambda$1/798154996 / Test$$Lambda$1/798154996
ac: [Lpkg.Test$$Lambda$1; / Test$$Lambda$1/798154996[]
 
 
I think the array class name is missing the trailing '/798154996' just before ';'

Comments
Class::getName and Class::getSimpleName work properly for hidden classes in JDK 15 (see the regression test [1] verifying Class::getName and Class::getSimpleName is implemented with Class::getName). sun.misc.Unsafe::defineAnonymousClass is deprecated and replaced with hidden classes. So this issue will not be fixed. [1] https://github.com/openjdk/jdk/blob/master/test/jdk/java/lang/invoke/defineHiddenClass/BasicTest.java#L108 verifies
04-11-2020

[~hseigel] thanks Harold. My mistake I ran the test with JDK 14. It actually failed with JDK 14 but passed with JDK 15. I moved this back to core-libs. I will check if there is a test covering this.
04-11-2020

It appears to work okay in JDK 16. > $JAVA_TEST/bin/java pkg.Test c: pkg.Test$$Lambda$1/0x0000000800c00a18 / Test$$Lambda$1/0x0000000800c00a18 ac: [Lpkg.Test$$Lambda$1/0x0000000800c00a18; / Test$$Lambda$1/0x0000000800c00a18[] And, worked okay with JDK 15. >jdk-15.0.2/bin/java -showversion pkg.Test java version "15.0.2" 2021-01-19 Java(TM) SE Runtime Environment (build 15.0.2+4-15) Java HotSpot(TM) 64-Bit Server VM (build 15.0.2+4-15, mixed mode, sharing) c: pkg.Test$$Lambda$1/0x0000000800b98248 / Test$$Lambda$1/0x0000000800b98248 ac: [Lpkg.Test$$Lambda$1/0x0000000800b98248; / Test$$Lambda$1/0x0000000800b98248[]
04-11-2020

[~hseigel] I verified with JDK 15. Hidden classes have the same issue. I moved this issue to hotspot/runtime.
03-11-2020

The virtual method Klass::external_name supplies the /NN prefix. Perhaps arrayKlass::external_name needs an override.
24-01-2014

ILW: M, L, H -> P4 Deferring to 9
25-11-2013