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

Covariant lambda parameter causes compiler to crash

    XMLWordPrintable

Details

    • x86_64
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      A covariant lambda parameter without a type annotation will cause the 11.0.1 compiler to crash with the message "An exception has occurred in the compiler (11.0.1). Please file a bug against the Java compiler..."

      The actual exception concerns a mismatched i18n message string.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The issue as presented uses Vavr (from vavr.io) version 0.9.2 (vavr-0.9.2.jar from Maven Central). I don't think the bug requires Vavr, however.

      Simply compile the attached source code with
      $ javac -cp vavr-0.9.2.jar:. CompilerMessageBug.java


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      javac should emit a useful error message about the lambda argument type (TemplateProcessor, in this case) being required for the lambda parameter "p".
      ACTUAL -
      javac emits the following exception and terminates compilation:

      An exception has occurred in the compiler (11.0.1). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
      com.sun.tools.javac.code.Types$SignatureGenerator$InvalidSignatureException
      at jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:5107)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.typeSig(LambdaToMethod.java:2436)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$LambdaTranslationContext.serializedLambdaDisambiguation(LambdaToMethod.java:2049)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$LambdaTranslationContext.serializedLambdaName(LambdaToMethod.java:2082)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$LambdaTranslationContext.complete(LambdaToMethod.java:2282)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.analyzeLambda(LambdaToMethod.java:1477)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitLambda(LambdaToMethod.java:1454)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1807)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitApply(TreeTranslator.java:280)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitApply(LambdaToMethod.java:1337)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitLambda(TreeTranslator.java:294)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.analyzeLambda(LambdaToMethod.java:1476)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitLambda(LambdaToMethod.java:1454)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1807)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitApply(TreeTranslator.java:280)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitApply(LambdaToMethod.java:1337)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitSelect(TreeTranslator.java:357)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitSelect(LambdaToMethod.java:1613)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2110)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitApply(TreeTranslator.java:279)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitApply(LambdaToMethod.java:1337)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitTypeCast(TreeTranslator.java:340)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCTypeCast.accept(JCTree.java:2018)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitVarDef(TreeTranslator.java:158)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitVarDef(LambdaToMethod.java:1640)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:956)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:167)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitBlock(LambdaToMethod.java:1360)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1020)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:150)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitMethodDef(LambdaToMethod.java:1493)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitClassDef(TreeTranslator.java:139)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitClassDef(LambdaToMethod.java:1402)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.analyzeAndPreprocessClass(LambdaToMethod.java:1326)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.visitClassDef(LambdaToMethod.java:296)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:261)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:254)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translateTopLevelClass(LambdaToMethod.java:281)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1560)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1432)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
      at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
      at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)


      ---------- BEGIN SOURCE ----------
      import java.util.stream.Stream;
      import java.util.function.Function;
      import java.util.Optional;
      import io.vavr.control.Try;
      import java.io.InputStream;

      public class CompilerMessageBug {

        private interface TemplateProcessor {
          InputStream process() throws Exception;
        }

        private interface TemplateProcessorFactory<TP extends TemplateProcessor> extends Function<Object, TP> {}

        private TemplateProcessorFactory<? extends TemplateProcessor> templateProcessorFactory = null;

        public void processTemplate() {
          InputStream is =
            Try.of(
                () -> templateProcessorFactory.apply(null)
            ).flatMap(
              // this line causes the OpenJDK 11 compiler to fail with an exception
              p -> Try.of(() -> p.process())
              // the following line does not:
              // (TemplateProcessor p) -> Try.of(() -> p.process())
            ).getOrElseThrow(ex -> new RuntimeException(ex));
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      The "workaround" is to add the argument type to the lambda parameter. (I say "workaround" since my guess is that due to bug fixes or features introduced with the type inference system between v10 and v11 has resulted in requiring the argument type.)


      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              pmangal Priyanka Mangal (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: