Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8027681

Lambda serialization fails once reflection proxy generation kicks in

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P1
    • Resolution: Fixed
    • 8
    • 8
    • core-libs

    Backports

      Description

         Now that lambda proxies are anonymous, when we cross the threshold where reflection proxies are generated to invoke writeReplace, linkage of the reflection proxy fails with CFNE, causing serialization to fail:

        LambdaObject: org.openjdk.tests.java.util.stream.IntReduceTest$$Lambda$1004/961982062@69dd3352 [ 20 ]
           [testng] Throwable: java.lang.NoClassDefFoundError: org/openjdk/tests/java/util/stream/IntReduceTest$$Lambda$1004/961982062java.lang.NoClassDefFoundError: org/openjdk/tests/java/util/stream/IntReduceTest$$Lambda$1004/961982062
           [testng] at sun.reflect.GeneratedMethodAccessor273.invoke(Unknown Source)
           [testng] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           [testng] at java.lang.reflect.Method.invoke(Method.java:483)
           [testng] at java.io.ObjectStreamClass.invokeWriteReplace(ObjectStreamClass.java:1075)
           [testng] at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1136)
           [testng] at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
           [testng] at com.oracle.lambda.TestLambdaSerialization.serializeAndDeserialize0(TestLambdaSerialization.java:128)

        Test patch to detect failures:

        diff -r f6bc96afc5d4 test/java/util/stream/test/org/openjdk/tests/java/lang/invoke/SerializedLambdaTest.java
        --- a/test/java/util/stream/test/org/openjdk/tests/java/lang/invoke/SerializedLambdaTest.java
        +++ b/test/java/util/stream/test/org/openjdk/tests/java/lang/invoke/SerializedLambdaTest.java
        @@ -45,15 +45,19 @@
          */
         @Test
         public class SerializedLambdaTest {
        + public static final int REPS = 50;
        +
             @SuppressWarnings("unchecked")
             private<T> void assertSerial(T p, Consumer<T> asserter) throws IOException, ClassNotFoundException {
                 asserter.accept(p);
         
        - byte[] bytes = serialize(p);
        + for (int i=0; i<REPS; i++) {
        + byte[] bytes = new byte[0];
        + bytes = serialize(p);
                 assertTrue(bytes.length > 0);
        -
                 asserter.accept((T) deserialize(bytes));
             }
        + }
         
             private void assertNotSerial(Predicate<String> p, Consumer<Predicate<String>> asserter)


        Attachments

          Issue Links

            Activity

              People

                rfield Robert Field
                briangoetz Brian Goetz
                Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: