JDK-8013179 : assertion failure in javac when compiling with -source 1.6 -target 1.6
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-04-04
  • Updated: 2018-05-21
  • Resolved: 2013-07-31
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 8
8 b102Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
1.8.0 build 72

ADDITIONAL OS VERSION INFORMATION :
Linux kuling.bothner.com 3.6.11-1.fc17.x86_64 #1 SMP Mon Dec 17 22:16:35 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Compiling a simple program (see  " Step to Reproduce) that uses a MethodHandle causes javac to crash if passed the flags  -target 1.6 -source 1.6

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the following simple program with the flags -target 1.6 -source 1.6

$ cat Crasher.java
public class Crasher {
    static java.lang.invoke.MethodHandle getNamedMember;
    public static Object getMember(String name, Object rec) throws Throwable {
        return getNamedMember.invoke(rec, name);
    }
}    
$ javac -target 1.6 -source 1.6 Crasher.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A warning about the bootstrap class path.
ACTUAL -
javac crashes with an assertion.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
warning: [options] bootstrap class path not set in conjunction with -source 1.6
An exception has occurred in the compiler (1.8.0-ea). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  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.comp.TransTypes.visitApply(TransTypes.java:642)
at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1391)
at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:453)
at com.sun.tools.javac.comp.TransTypes.visitReturn(TransTypes.java:614)
at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1310)
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:160)
at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:835)
at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:453)
at com.sun.tools.javac.comp.TransTypes.visitMethodDef(TransTypes.java:487)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:723)
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.TransTypes.translateClass(TransTypes.java:934)
at com.sun.tools.javac.comp.TransTypes.visitClassDef(TransTypes.java:474)
at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:644)
at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:453)
at com.sun.tools.javac.comp.TransTypes.translateTopLevelClass(TransTypes.java:961)
at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1461)
at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1357)
at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:907)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:866)
at com.sun.tools.javac.main.Main.compile(Main.java:506)
at com.sun.tools.javac.main.Main.compile(Main.java:365)
at com.sun.tools.javac.main.Main.compile(Main.java:354)
at com.sun.tools.javac.main.Main.compile(Main.java:345)
at com.sun.tools.javac.Main.compile(Main.java:76)
at com.sun.tools.javac.Main.main(Main.java:61)


REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Modify -source 1.6 -target 1.6 to -source 1.7 -target 1.7.
Comments
Perhaps TransTypes could have a one-time check that MethodHandle as found on the bootclasspath has the expected signature. That method could post useful diagnostics about needing to see the bootclasspath correctly.
29-07-2013

I'm tempted to close it as won't fix. The problem here is that the type and number of arguments for the invoke method is different depending on the source/target. For 6 it was expecting a Object[]. I think that we can't add an error message for any possible combination of feature/source/target and expect it to be meaningful. That's why we have assertions, at the point that javac finds the error it's hard to determine that the error has been originated for a wrong combination of the mentioned factors.
29-07-2013

After looking at it more closely, this is more tricky than I initially thought, someone with more expertise with the type system needs to be consulted. Vicente has volunteered to shepherd this one.
18-06-2013