-
Bug
-
Resolution: Fixed
-
P3
-
24
-
b25
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
I got it on windows, but I expect it to be on all OS-s.
A DESCRIPTION OF THE PROBLEM :
If you define an hidden class that has a serializable lambda reference it will fail with:
Caused by: java.lang.ClassFormatError: Illegal class name "autotest/Test.0x00000134c3004000" in class file autotest/Test_0x00000134c3004000$$Lambda
at java.base/java.lang.ClassLoader.defineClass0(Native Method)
at java.base/java.lang.System$2.defineClass(System.java:2489)
at java.base/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2471)
at java.base/java.lang.invoke.InnerClassLambdaMetafactory.generateInnerClass(InnerClassLambdaMetafactory.java:356)
Probably should have genereted the generateSerializationHostileMethods branch from the InnerClassLambdaMetafactory for the inner lambda class?
It did not fail on JDK 23, but I must say that if I tryed to use the serialization aspect of the lambda it did fail.
REGRESSION : Last worked in version 23.0.1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I made a small program that fails with un ugly error, should probably not fail or throw more meaning full error.
You can reproduce it if you define a hidden class that uses a serializable lambda.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Does not fail on class define, probably should fail when serialize is used?
ACTUAL -
Fails on class define on JDK 24 (not 23)
---------- BEGIN SOURCE ----------
package autotest;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.nio.file.Files;
public class Test {
public String foo;
public Test() {
Func<String> sup = Test::get;
foo = sup.get();
System.out.println("foo " + foo);
// if you uncomment it will also fail on JDK 23
// try {
// ByteArrayOutputStream stream = new ByteArrayOutputStream();
// ObjectOutputStream objectOutputStream = new ObjectOutputStream(stream);
// objectOutputStream.writeObject(sup);
// objectOutputStream.flush();
// objectOutputStream.close();
// System.out.println("stream " + stream.size());
// }
// catch (Throwable e) {
// System.out.println("fail " + e.getMessage());
// e.printStackTrace();
// }
}
private static String get() {
return "foo";
}
public static void main(String[] args) throws Exception {
new Test().test();
}
public void test() throws Exception {
System.out.println("start");
byte[] bytes = Test.class.getClassLoader().getResourceAsStream("autotest/Test.class").readAllBytes();
System.out.println("bytes " + bytes);
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodHandles.Lookup newLookp = lookup.defineHiddenClass(bytes, false);
System.out.println("target " + newLookp + " " + newLookp.lookupClass());
System.out.println("targe2 " + Test.class.descriptorString());
System.out.println("targe3 " + newLookp.lookupClass().descriptorString());
System.out.println("targe4 " + newLookp.lookupClass().getDeclaredConstructor().newInstance());
System.out.println("done");
}
public static interface Func<T> extends java.io.Serializable {
T get();
}
}
---------- END SOURCE ----------
FREQUENCY : always
I got it on windows, but I expect it to be on all OS-s.
A DESCRIPTION OF THE PROBLEM :
If you define an hidden class that has a serializable lambda reference it will fail with:
Caused by: java.lang.ClassFormatError: Illegal class name "autotest/Test.0x00000134c3004000" in class file autotest/Test_0x00000134c3004000$$Lambda
at java.base/java.lang.ClassLoader.defineClass0(Native Method)
at java.base/java.lang.System$2.defineClass(System.java:2489)
at java.base/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2471)
at java.base/java.lang.invoke.InnerClassLambdaMetafactory.generateInnerClass(InnerClassLambdaMetafactory.java:356)
Probably should have genereted the generateSerializationHostileMethods branch from the InnerClassLambdaMetafactory for the inner lambda class?
It did not fail on JDK 23, but I must say that if I tryed to use the serialization aspect of the lambda it did fail.
REGRESSION : Last worked in version 23.0.1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I made a small program that fails with un ugly error, should probably not fail or throw more meaning full error.
You can reproduce it if you define a hidden class that uses a serializable lambda.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Does not fail on class define, probably should fail when serialize is used?
ACTUAL -
Fails on class define on JDK 24 (not 23)
---------- BEGIN SOURCE ----------
package autotest;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.nio.file.Files;
public class Test {
public String foo;
public Test() {
Func<String> sup = Test::get;
foo = sup.get();
System.out.println("foo " + foo);
// if you uncomment it will also fail on JDK 23
// try {
// ByteArrayOutputStream stream = new ByteArrayOutputStream();
// ObjectOutputStream objectOutputStream = new ObjectOutputStream(stream);
// objectOutputStream.writeObject(sup);
// objectOutputStream.flush();
// objectOutputStream.close();
// System.out.println("stream " + stream.size());
// }
// catch (Throwable e) {
// System.out.println("fail " + e.getMessage());
// e.printStackTrace();
// }
}
private static String get() {
return "foo";
}
public static void main(String[] args) throws Exception {
new Test().test();
}
public void test() throws Exception {
System.out.println("start");
byte[] bytes = Test.class.getClassLoader().getResourceAsStream("autotest/Test.class").readAllBytes();
System.out.println("bytes " + bytes);
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodHandles.Lookup newLookp = lookup.defineHiddenClass(bytes, false);
System.out.println("target " + newLookp + " " + newLookp.lookupClass());
System.out.println("targe2 " + Test.class.descriptorString());
System.out.println("targe3 " + newLookp.lookupClass().descriptorString());
System.out.println("targe4 " + newLookp.lookupClass().getDeclaredConstructor().newInstance());
System.out.println("done");
}
public static interface Func<T> extends java.io.Serializable {
T get();
}
}
---------- END SOURCE ----------
FREQUENCY : always
- links to
-
Commit(master) openjdk/jdk/681a57f9
-
Review(master) openjdk/jdk/21912