-
Bug
-
Resolution: Fixed
-
P2
-
20
-
b33
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8301029 | 21 | Jan Lahoda | P2 | Resolved | Fixed | b07 |
JDK-8301539 | 20.0.2 | Jan Lahoda | P2 | Resolved | Fixed | b01 |
JDK-8301526 | 20.0.1 | Jan Lahoda | P2 | Resolved | Fixed | b04 |
In the following example, serializing a lambda and reading it back in succeeds on JDK 19 and fails on JDK 20.
I think the culprit isJDK-8059632.
```
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.function.Predicate;
@SuppressWarnings("unchecked")
public class T {
enum E {
ONE,
TWO,
THREE
}
public static void main(String[] args) throws Exception {
E e = E.ONE;
Predicate<E> p = (Serializable & Predicate<E>) e::equals;
try (OutputStream os = Files.newOutputStream(Paths.get("o"));
ObjectOutputStream oos = new ObjectOutputStream(os)) {
oos.writeObject(p);
}
try (InputStream is = Files.newInputStream(Paths.get("o"));
ObjectInputStream ois = new ObjectInputStream(is)) {
p = (Predicate<E>) ois.readObject();
}
Arrays.stream(E.values()).filter(p).forEachOrdered(System.err::println);
}
}
```
$ java -fullversion
openjdk full version "19.0.2+7-44"
$ javac T.java
$ java T
$ java T
ONE
$ java -fullversion
openjdk full version "20-ea+31-2311"
$ javac T.java
$ java T
Exception in thread "main" java.io.InvalidObjectException: ReflectiveOperationException during deserialization
at java.base/java.lang.invoke.SerializedLambda.readResolve(SerializedLambda.java:280)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at java.base/java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1190)
at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2289)
at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1760)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:538)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:496)
at T.main(T.java:29)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at java.base/java.lang.invoke.SerializedLambda.readResolve(SerializedLambda.java:278)
... 8 more
Caused by: java.lang.IllegalArgumentException: Invalid lambda deserialization
at T.$deserializeLambda$(T.java:11)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 10 more
I think the culprit is
```
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.function.Predicate;
@SuppressWarnings("unchecked")
public class T {
enum E {
ONE,
TWO,
THREE
}
public static void main(String[] args) throws Exception {
E e = E.ONE;
Predicate<E> p = (Serializable & Predicate<E>) e::equals;
try (OutputStream os = Files.newOutputStream(Paths.get("o"));
ObjectOutputStream oos = new ObjectOutputStream(os)) {
oos.writeObject(p);
}
try (InputStream is = Files.newInputStream(Paths.get("o"));
ObjectInputStream ois = new ObjectInputStream(is)) {
p = (Predicate<E>) ois.readObject();
}
Arrays.stream(E.values()).filter(p).forEachOrdered(System.err::println);
}
}
```
$ java -fullversion
openjdk full version "19.0.2+7-44"
$ javac T.java
$ java T
$ java T
ONE
$ java -fullversion
openjdk full version "20-ea+31-2311"
$ javac T.java
$ java T
Exception in thread "main" java.io.InvalidObjectException: ReflectiveOperationException during deserialization
at java.base/java.lang.invoke.SerializedLambda.readResolve(SerializedLambda.java:280)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at java.base/java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1190)
at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2289)
at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1760)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:538)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:496)
at T.main(T.java:29)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at java.base/java.lang.invoke.SerializedLambda.readResolve(SerializedLambda.java:278)
... 8 more
Caused by: java.lang.IllegalArgumentException: Invalid lambda deserialization
at T.$deserializeLambda$(T.java:11)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 10 more
- backported by
-
JDK-8301029 Lambda deserialization regression involving Enum method reference
- Resolved
-
JDK-8301526 Lambda deserialization regression involving Enum method reference
- Resolved
-
JDK-8301539 Lambda deserialization regression involving Enum method reference
- Resolved
- csr for
-
JDK-8300787 Lambda deserialization regression involving Enum method reference
- Closed
- relates to
-
JDK-8059632 Method reference compilation uses incorrect qualifying type
- Resolved
-
JDK-8282080 Lambda deserialization fails for Object method references on interfaces
- Closed
(1 relates to, 2 links to)