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

Initializing static fields causes unbounded recursion in javac

    XMLWordPrintable

Details

    • b63
    • x86_64
    • linux
    • Verified

    Backports

      Description

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

        javac -version
        javac 1.8.0_40


        ADDITIONAL OS VERSION INFORMATION :
        Linux 3.16.7-ckt5-sk+ #1 SMP Tue Feb 17 22:00:49 EST 2015 x86_64 x86_64 x86_64 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        When performing a particular set of specific operations when initializing a `static final` field, javac overflows the stack.

        It appears as if the combination of String append and performing a map operation on a stream cause this behavior.

        Behavior noticed by user on reddit forum (not me, although I have reproduced it): https://www.reddit.com/r/learnprogramming/comments/32bfle/can_you_explain_this_strange_java8_error/

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Attempt to compile provided source code.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Successful compilation
        ACTUAL -
        The system is out of resources.
        Consult the following stack trace for details.
        java.lang.StackOverflowError
            at com.sun.tools.javac.code.Scope.dupUnshared(Scope.java:144)
            at com.sun.tools.javac.comp.Attr.lambdaEnv(Attr.java:2609)
            at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2275)
            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)
            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)
            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)
            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)
            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)

        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.code.Scope.dupUnshared(Scope.java:144)
            at com.sun.tools.javac.comp.Attr.lambdaEnv(Attr.java:2609)
            at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2275)
            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)
            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)
            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)
            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)
            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)

        REPRODUCIBILITY :
        This bug can be reproduced always.

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

        public class uncompilable
        {
            static final List<String> stringList = Arrays.asList("doesnt", "matter");

            static final String finalJoinedMappedAppendedString = "" + fakeJoin(stringList.stream().map(str -> str).collect(Collectors.toList()));

            private static String fakeJoin(List<String> doesntMatter) {
                return "anything";
            }

            public static void main(String[] args) { }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        From forum post:

        "Oh and additionally, if you put the stream/map/collect calls into a random static function and call that instead, it all works fine. It just dislikes being directly attached to the static final field."

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved: