-
Bug
-
Resolution: Fixed
-
P3
-
9
-
b153
-
generic
-
generic
-
Verified
FULL PRODUCT VERSION :
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+148-jigsaw-nightly-h5846-20161213)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+148-jigsaw-nightly-h5846-20161213, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Wersja 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Javac throws AssertionError when compiling method reference with generic code and varargs as in test case below.
It works fine when lambda expression is used, or without generic type/varargs.
REGRESSION. Last worked in version 8u112
ADDITIONAL REGRESSION INFORMATION:
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+148-jigsaw-nightly-h5846-20161213)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+148-jigsaw-nightly-h5846-20161213, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile given class using JDK9 compiler
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should compile.
ACTUAL -
It does not.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (9-ea). 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.
java.lang.AssertionError
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.setVarargsIfNeeded(LambdaToMethod.java:795)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.access$1900(LambdaToMethod.java:81)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$MemberReferenceToLambda.expressionInvoke(LambdaToMethod.java:971)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$MemberReferenceToLambda.lambda(LambdaToMethod.java:845)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitReference(LambdaToMethod.java:1502)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMemberReference.accept(JCTree.java:2184)
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:1555)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:950)
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:1275)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1014)
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:1408)
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:1317)
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:1241)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.access$300(LambdaToMethod.java:1193)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.visitClassDef(LambdaToMethod.java:239)
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:204)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:197)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translateTopLevelClass(LambdaToMethod.java:224)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1555)
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:976)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:307)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:160)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:55)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:41)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Bug<T> {
public T invoke(Object... args) {
return null;
}
public static <T extends String> void test() { // works with <T> alone.
Bug<T> bug = new Bug<>();
java.util.function.Function<String, T> b = bug::invoke; // compile error, but works with (args) -> bug.invoke(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use this instead:
java.util.function.Function<String, T> b = (args) -> bug.invoke(args);
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+148-jigsaw-nightly-h5846-20161213)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+148-jigsaw-nightly-h5846-20161213, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Wersja 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Javac throws AssertionError when compiling method reference with generic code and varargs as in test case below.
It works fine when lambda expression is used, or without generic type/varargs.
REGRESSION. Last worked in version 8u112
ADDITIONAL REGRESSION INFORMATION:
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+148-jigsaw-nightly-h5846-20161213)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+148-jigsaw-nightly-h5846-20161213, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile given class using JDK9 compiler
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should compile.
ACTUAL -
It does not.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (9-ea). 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.
java.lang.AssertionError
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.setVarargsIfNeeded(LambdaToMethod.java:795)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.access$1900(LambdaToMethod.java:81)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$MemberReferenceToLambda.expressionInvoke(LambdaToMethod.java:971)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$MemberReferenceToLambda.lambda(LambdaToMethod.java:845)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitReference(LambdaToMethod.java:1502)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMemberReference.accept(JCTree.java:2184)
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:1555)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:950)
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:1275)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1014)
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:1408)
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:1317)
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:1241)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.access$300(LambdaToMethod.java:1193)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.visitClassDef(LambdaToMethod.java:239)
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:204)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:197)
at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translateTopLevelClass(LambdaToMethod.java:224)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1555)
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:976)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:307)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:160)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:55)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:41)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Bug<T> {
public T invoke(Object... args) {
return null;
}
public static <T extends String> void test() { // works with <T> alone.
Bug<T> bug = new Bug<>();
java.util.function.Function<String, T> b = bug::invoke; // compile error, but works with (args) -> bug.invoke(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use this instead:
java.util.function.Function<String, T> b = (args) -> bug.invoke(args);
- duplicates
-
JDK-8176202 AssertionError in LambdaToMethod.setVarargsIfNeeded
-
- Closed
-