JDK-8227678 : Javac compilation issues when compiling static expressions that use Lambda
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2019-07-12
  • Updated: 2019-07-15
  • Resolved: 2019-07-15
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10 build using JDK 8u211

A DESCRIPTION OF THE PROBLEM :
Compiling the supplied source file in Java 8 produces the following output, before consuming system resources and giving up.
C:\CompileTest>"C:\Program Files\Java\jdk1.8.0_211\bin\javac" com\compile\CompileTest.java

The system is out of resources.
Consult the following stack trace for details.
java.lang.StackOverflowError
        at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2296)
        at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
        at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)
        at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
		....
        at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
        at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the supplied file:
"C:\Program Files\Java\jdk1.8.0_211\bin\javac" com\compile\CompileTest.java:

package com.compile;

import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CompileTest {
    public static String[] ROLES_DATA = {"ROLE"};

    public static String[][] USERS_DATA = {
            {"FIELDS", "DATA"}
    };

    private static final String SCHEMA_INSERT_DATA = Stream.of(ROLES_DATA).map(v -> "INSERT INTO ROLES VALUES(" + v + ");\n")
            .collect(Collectors.joining())
            + Stream.of(USERS_DATA).map(v -> "INSERT INTO USERS (" + v[0] + ") VALUES(" + v[1] + ");\n")
            .collect(Collectors.joining());
}

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Produces class file without error.
ACTUAL -
Infinite loop, runs out of memory

---------- BEGIN SOURCE ----------
package com.compile;

import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CompileTest {
    public static String[] ROLES_DATA = {"ROLE"};

    public static String[][] USERS_DATA = {
            {"FIELDS", "DATA"}
    };

    private static final String SCHEMA_INSERT_DATA = Stream.of(ROLES_DATA).map(v -> "INSERT INTO ROLES VALUES(" + v + ");\n")
            .collect(Collectors.joining())
            + Stream.of(USERS_DATA).map(v -> "INSERT INTO USERS (" + v[0] + ") VALUES(" + v[1] + ");\n")
            .collect(Collectors.joining());
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Don't use static initialisation with Lambdas.
Compile with JDK 11, but source code 8

FREQUENCY : always



Comments
This issue is duplicate of JDK-8077605, which is already fixed in JDK9 and above. 8u212 - Fail 9 GA - PAss 11 - Pass 14 - Pass Please upgrade your JDK version to avoid this issue.
15-07-2019