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

javac StackOverflow in final field initialization with lambda and string concat

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8, 8u65
    • tools
    • 8
    • x86_64
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_40"
      Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
      Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      Linux cvatap1d 2.6.18-348.29.1.el5 #1 SMP Thu Dec 18 07:43:27 EST 2014 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      the following 5 lines of code cause a StackOverflowError in javac:

      import java.util.Arrays;

      public class Foo {
      final Object o = Arrays.stream(new String[]{}).map(x -> x)+"\n";
      }


      ADDITIONAL REGRESSION INFORMATION:
      same error using the following versions:

      java version "1.8.0"
      Java(TM) SE Runtime Environment (build 1.8.0-b132)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

      java version "1.8.0_05"
      Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

      java version "1.8.0_20"
      Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
      Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a file called Foo.java

      2. Paste these 5 lines of code into Foo.java:

      import java.util.Arrays;

      public class Foo {
      final Object o = Arrays.stream(new String[]{}).map(x -> x)+"\n";
      }

      3. run: javac Foo.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expecting successful compilation and generation of Foo.class file.
      ACTUAL -
      javac fails with StackOverflowError

      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.visitLambda(Attr.java:2266)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2404)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2404)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2404)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2404)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2404)
      ...

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class Foo {
      final Object o = Arrays.stream(new String[]{}).map(x -> x)+"\n";
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      removing any of the following:

      1. final
      2. map(x -> x)
      3. +"\n";

            jlahoda Jan Lahoda
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: