Enable Java8 for GWT on JDK7 (cont'd)

This patch stubs missing SerializedLambda which is missing
in JDK7 but referenced from Java8 byte code for lambdas
(such as produced by our own JdtCompiler), preventing GWT
compilation with JDK7.

This is a followup to commit 3586e7bc10777c7d479889a5f20927cbf2aceb97
which stubbed LambdaMetafactory already.

Change-Id: Ie035afd6f031a596172c149739507bc1223d95f7
diff --git a/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java b/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
index 4125092..ada3271 100644
--- a/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
@@ -497,6 +497,65 @@
           + "GQ==");
     }
 
+    /*
+      Generated from:
+
+      public class SerializedLambda {
+        public SerializedLambda(Class<?> capturingClass,
+                        String functionalInterfaceClass,
+                        String functionalInterfaceMethodName,
+                        String functionalInterfaceMethodSignature,
+                        int implMethodKind,
+                        String implClass,
+                        String implMethodName,
+                        String implMethodSignature,
+                        String instantiatedMethodType,
+                        Object[] capturedArgs) {
+        }
+
+        public String getCapturingClass() { return null; }
+        public String getFunctionalInterfaceClass() { return null; }
+        public String getFunctionalInterfaceMethodName() { return null; }
+        public String getFunctionalInterfaceMethodSignature() { return null; }
+        public String getImplClass() { return null; }
+        public String getImplMethodName() { return null; }
+        public String getImplMethodSignature() { return null; }
+        public int getImplMethodKind() { return 0; }
+        public final String getInstantiatedMethodType() { return null; }
+        public int getCapturedArgCount() { return 0; }
+        public Object getCapturedArg(int i) { return null; }
+        public String toString() { return super.toString(); }
+      }
+     */
+    private byte[] getSerializedLambdaBytes() {
+      return BaseEncoding.base64().decode(
+          "yv66vgAAADMAIQoABAAcCgAEAB0HAB4HAB8BAAY8aW5pdD4BAKYoTGphdmEvbGFuZy9DbGFzcztM"
+          + "amF2YS9sYW5nL1N0cmluZztMamF2YS9sYW5nL1N0cmluZztMamF2YS9sYW5nL1N0cmluZztJTGph"
+          + "dmEvbGFuZy9TdHJpbmc7TGphdmEvbGFuZy9TdHJpbmc7TGphdmEvbGFuZy9TdHJpbmc7TGphdmEv"
+          + "bGFuZy9TdHJpbmc7W0xqYXZhL2xhbmcvT2JqZWN0OylWAQAEQ29kZQEAD0xpbmVOdW1iZXJUYWJs"
+          + "ZQEACVNpZ25hdHVyZQEAqShMamF2YS9sYW5nL0NsYXNzPCo+O0xqYXZhL2xhbmcvU3RyaW5nO0xq"
+          + "YXZhL2xhbmcvU3RyaW5nO0xqYXZhL2xhbmcvU3RyaW5nO0lMamF2YS9sYW5nL1N0cmluZztMamF2"
+          + "YS9sYW5nL1N0cmluZztMamF2YS9sYW5nL1N0cmluZztMamF2YS9sYW5nL1N0cmluZztbTGphdmEv"
+          + "bGFuZy9PYmplY3Q7KVYBABFnZXRDYXB0dXJpbmdDbGFzcwEAFCgpTGphdmEvbGFuZy9TdHJpbmc7"
+          + "AQAbZ2V0RnVuY3Rpb25hbEludGVyZmFjZUNsYXNzAQAgZ2V0RnVuY3Rpb25hbEludGVyZmFjZU1l"
+          + "dGhvZE5hbWUBACVnZXRGdW5jdGlvbmFsSW50ZXJmYWNlTWV0aG9kU2lnbmF0dXJlAQAMZ2V0SW1w"
+          + "bENsYXNzAQARZ2V0SW1wbE1ldGhvZE5hbWUBABZnZXRJbXBsTWV0aG9kU2lnbmF0dXJlAQARZ2V0"
+          + "SW1wbE1ldGhvZEtpbmQBAAMoKUkBABlnZXRJbnN0YW50aWF0ZWRNZXRob2RUeXBlAQATZ2V0Q2Fw"
+          + "dHVyZWRBcmdDb3VudAEADmdldENhcHR1cmVkQXJnAQAVKEkpTGphdmEvbGFuZy9PYmplY3Q7AQAI"
+          + "dG9TdHJpbmcBAApTb3VyY2VGaWxlAQAVU2VyaWFsaXplZExhbWJkYS5qYXZhDAAFACAMABkADAEA"
+          + "IWphdmEvbGFuZy9pbnZva2UvU2VyaWFsaXplZExhbWJkYQEAEGphdmEvbGFuZy9PYmplY3QBAAMo"
+          + "KVYAIQADAAQAAAAAAA0AAQAFAAYAAgAHAAAAIQABAAsAAAAFKrcAAbEAAAABAAgAAAAKAAIAAAAN"
+          + "AAQADgAJAAAAAgAKAAEACwAMAAEABwAAABoAAQABAAAAAgGwAAAAAQAIAAAABgABAAAAEAABAA0A"
+          + "DAABAAcAAAAaAAEAAQAAAAIBsAAAAAEACAAAAAYAAQAAABEAAQAOAAwAAQAHAAAAGgABAAEAAAAC"
+          + "AbAAAAABAAgAAAAGAAEAAAASAAEADwAMAAEABwAAABoAAQABAAAAAgGwAAAAAQAIAAAABgABAAAA"
+          + "EwABABAADAABAAcAAAAaAAEAAQAAAAIBsAAAAAEACAAAAAYAAQAAABQAAQARAAwAAQAHAAAAGgAB"
+          + "AAEAAAACAbAAAAABAAgAAAAGAAEAAAAVAAEAEgAMAAEABwAAABoAAQABAAAAAgGwAAAAAQAIAAAA"
+          + "BgABAAAAFgABABMAFAABAAcAAAAaAAEAAQAAAAIDrAAAAAEACAAAAAYAAQAAABcAEQAVAAwAAQAH"
+          + "AAAAGgABAAEAAAACAbAAAAABAAgAAAAGAAEAAAAYAAEAFgAUAAEABwAAABoAAQABAAAAAgOsAAAA"
+          + "AQAIAAAABgABAAAAGQABABcAGAABAAcAAAAaAAEAAgAAAAIBsAAAAAEACAAAAAYAAQAAABoAAQAZ"
+          + "AAwAAQAHAAAAHQABAAEAAAAFKrcAArAAAAABAAgAAAAGAAEAAAAbAAEAGgAAAAIAGw==");
+    }
+
     private NameEnvironmentAnswer findTypeInCache(String internalName) {
       if (!internalTypes.containsKey(internalName)) {
         return null;
@@ -551,10 +610,10 @@
           // returns null indicating a failure.
         }
       }
-      // LambdaMetafactory is byte-code side artifact of JDT compile and actually not referenced by
-      // our AST. However, this class is only available in JDK8+ so JdtCompiler fails to validate
-      // the classes that are referencing it. We tackle that by providing a stub version if it is
-      // not found in the class path.
+      // LambdaMetafactory and SerializedLambda byte-code side-artifacts of JDT compile and actually
+      // not referenced by our AST. However, these classes are only available in JDK8+ so
+      // JdtCompiler fails to validate the classes that are referencing it. We tackle that by
+      // providing a stub version if it is not found in the class path.
       if (internalName.equals("java/lang/invoke/LambdaMetafactory")) {
         try {
           ClassFileReader cfr = new ClassFileReader(getLambdaMetafactoryBytes(),
@@ -563,6 +622,14 @@
         } catch (ClassFormatException e) {
           e.printStackTrace();
         }
+      } else if (internalName.equals("java/lang/invoke/SerializedLambda")) {
+        try {
+          ClassFileReader cfr = new ClassFileReader(getSerializedLambdaBytes(),
+              "synthetic:java/lang/invoke/SerializedLambda".toCharArray(), true);
+          return new NameEnvironmentAnswer(cfr, null);
+        } catch (ClassFormatException e) {
+          e.printStackTrace();
+        }
       }
       return null;
     }