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

javac stack overflow when compiling lambda

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u101
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      x86
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_101"
      Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Darwin pcofthenight 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      Using a lambda expression in this context...

          private static final String[] LANGUAGE_CODES = { "en", "pl" };
          private static final String LANGUAGES_JSON = "{\"data\":{\"languages\":[" + Arrays.stream(LANGUAGE_CODES)
              .map(c -> "{\"language\":\"" + c + "\"}").collect(Collectors.joining(",")) + "]}}";

      ... causes a stack overflow that looks like...

      java.lang.StackOverflowError
              at com.sun.tools.javac.comp.Attr.lambdaEnv(Attr.java:2638)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2304)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:575)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2434)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Put this in a java file, then run "javac JavaCrash.java":

      import java.util.Arrays;
      import java.util.stream.Collectors;

      public class JavaCrash
      {
          private static final String[] LANGUAGE_CODES = { "en", "pl" };
          private static final String LANGUAGES_JSON = "{\"data\":{\"languages\":[" + Arrays.stream(LANGUAGE_CODES)
              .map(c -> "{\"language\":\"" + c + "\"}").collect(Collectors.joining(",")) + "]}}";

          public static void main(String[] args)
          {
              System.out.println(LANGUAGES_JSON);
          }
      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It compiles and works correctly.
      ACTUAL -
      The system is out of resources.
      Consult the following stack trace for details.
      java.lang.StackOverflowError
              at com.sun.tools.javac.comp.Attr.lambdaEnv(Attr.java:2638)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2304)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:575)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2434)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:575)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2434)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
      .......


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      The system is out of resources.
      Consult the following stack trace for details.
      java.lang.StackOverflowError
              at com.sun.tools.javac.comp.Attr.lambdaEnv(Attr.java:2638)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2304)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:575)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2434)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:575)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2434)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
      .......


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Arrays;
      import java.util.stream.Collectors;

      public class JavaCrash
      {
          private static final String[] LANGUAGE_CODES = { "en", "pl" };
          private static final String LANGUAGES_JSON = "{\"data\":{\"languages\":[" + Arrays.stream(LANGUAGE_CODES)
              .map(c -> "{\"language\":\"" + c + "\"}").collect(Collectors.joining(",")) + "]}}";

          public static void main(String[] args)
          {
              System.out.println(LANGUAGES_JSON);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Just use a static initializer and for loop instead of a stream.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                fmatte Fairoz Matte
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: