JDK-8074381 : java.lang.AssertionError during compiling
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8-pool,9
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-02-24
  • Updated: 2018-08-07
  • Resolved: 2015-03-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b56Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Error occurred during compilation of a class

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the file in the section
Source code for an executable test case

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The classes were compiled and project built or the syntax errors announced.
An exception has occurred in the compiler instead.
ACTUAL -
An exception has occurred in the compiler (1.8.0_31). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bu
greport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.AssertionError
        at com.sun.tools.javac.util.Assert.error(Assert.java:126)
...

ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (1.8.0_31). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bu
greport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.AssertionError
        at com.sun.tools.javac.util.Assert.error(Assert.java:126)
        at com.sun.tools.javac.util.Assert.check(Assert.java:45)
        at com.sun.tools.javac.code.Types.functionalInterfaceBridges(Types.java:656)
        at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$TranslationContext.<init>(LambdaToMethod.java:1703)
        at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$LambdaTranslationContext.<init>(LambdaToMethod.java:1779)
        at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.makeLambdaContext(LambdaToMethod.java:1652)
        at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitLambda(LambdaToMethod.java:1259)
        at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
        at com.sun.tools.javac.tree.TreeTranslator.visitApply(TreeTranslator.java:275)
        at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
        at com.sun.tools.javac.tree.TreeTranslator.visitVarDef(TreeTranslator.java:153)
        at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitVarDef(LambdaToMethod.java:1444)
        at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
        at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:162)
        at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitBlock(LambdaToMethod.java:1169)
        at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
        at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:145)
        at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitMethodDef(LambdaToMethod.java:1279)
        at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
        at com.sun.tools.javac.tree.TreeTranslator.visitClassDef(TreeTranslator.java:134)
        at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitClassDef(LambdaToMethod.java:1206)
        at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
        at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.analyzeAndPreprocessClass(LambdaToMethod.java:1159)
        at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.access$300(LambdaToMethod.java:1116)
        at com.sun.tools.javac.comp.LambdaToMethod.visitClassDef(LambdaToMethod.java:230)
        at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
        at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:195)
        at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:188)
        at com.sun.tools.javac.comp.LambdaToMethod.translateTopLevelClass(LambdaToMethod.java:215)
        at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1493)
        at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1356)
        at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.main.Main.compile(Main.java:381)
        at com.sun.tools.javac.main.Main.compile(Main.java:370)
        at com.sun.tools.javac.main.Main.compile(Main.java:361)
        at com.sun.tools.javac.Main.compile(Main.java:56)
        at com.sun.tools.javac.Main.main(Main.java:42)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package rup;

import java.util.List;
import java.util.function.Predicate;


public final class Lib
{
    @SuppressWarnings("unchecked")
    public static List<Class<?>> findClasses(Class<?> rootClass)
    {
        List<Class<?>> classes = findClasses(rootClass, c -> true);
        return classes;
    }


    @SuppressWarnings("unchecked")
    public static List<Class<?>> findClasses(Class<?> rootClass,
                                             IClassFilter classFilter)
    {
        return null;
    }

}

interface IClassFilter<T> extends Predicate<Class<? extends T>>
{
    public boolean test (Class<? extends T> cls);
}

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


Comments
The comment above is misleading; in reality what's really happening here is that this code should never be allowed in the first place - javac applies a check in which it verifies that, for any functional expression, you could write an equivalent anonymous class which ticks all the boxes; this is done to implement the checks described in 15.27.3: "For each non-static member method m of U, if the function type of U has a subsignature of the signature of m, then a notional method whose method type is the function type of U is deemed to override m, and any compile-time error or unchecked warning specified in ��8.4.8.3 may occur. " Now, turns out that the above code would actually fail if replaced with an inner class: Main.java:15: error: <anonymous Test$1> is not abstract and does not override abstract method m(Object) in Sup Sub s2 = new Sub() { ^ 1 error The same error is not reported when checking the lambda simply because the synthetic class created by javac features a spurious ACC_ABSTRACT flag - so javac doesn't really think that ALL abstract methods in the functional interface should be implemented - hence the mismatch.
04-03-2015

Types.makeFunctionalInterfaceClass seems a bit buggy - it creates a synthetic class symbol with a raw supertype, which is wrong. The notion of functional interface and functional descriptor only applies to interface _declaration_ not types. It is only in the last step, when computing the functional type of an interface that the type information is used and erasure (if needed) is applied. Hence, this routine should probably behave more like makeNotionalInterface - which would create the following synthetic interface: interface $Notional<X> extends Sub<X> { } Here we need to create the following synthetic interface: interface $Synthetic<X> extends $Notional<X> { boolean m(String s); } tricky bits: if one of the targets is an instantiation of a generic functional interface, the type parameters should be used to instantiate the notional supertype.
04-03-2015

Simpler test case: interface Sup<X> { boolean m(X x); } interface Sub<X> extends Sup<String> { boolean m(String s); } class Test { void test() { Sub s = c -> true; } }
04-03-2015

Checked this for JDK 8u31, 8u40 ea b23, 8u60 b04, and 9 ea b50 and could reproduce the issue. >javac Lib.java An exception has occurred in the compiler (1.8.0_31). Please file a bug at the J ava Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnosti c in your report. Thank you. java.lang.AssertionError at com.sun.tools.javac.util.Assert.error(Assert.java:126) at com.sun.tools.javac.util.Assert.check(Assert.java:45) at com.sun.tools.javac.code.Types.functionalInterfaceBridges(Types.java: 656) at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$Tr anslationContext.<init>(LambdaToMethod.java:1703) .............................................................................................
26-02-2015