JDK-7178324 : Crash when compiling for(i : x) try(AutoCloseable x = ...) {}
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-06-20
  • Updated: 2013-06-26
  • Resolved: 2012-08-10
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 7 JDK 8
7u40Fixed 8 b52Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :


ADDITIONAL OS VERSION INFORMATION :
Windows 7, x64

A DESCRIPTION OF THE PROBLEM :
Here's the code that causes the crash:



Should be all you need to fix the issue.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just compile the above, doesn't seem to be context dependent.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should compile without crashing, or at least report better error information.
ACTUAL -
javac crashed!  Never seen that before.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Here you go, stack trace:

An exception has occurred in the compiler (1.7.0_02). 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.NullPointerException
	at com.sun.tools.javac.tree.TreeInfo.endPos(TreeInfo.java:248)
	at com.sun.tools.javac.comp.Lower.visitIterableForeachLoop(Lower.java:3277)
	at com.sun.tools.javac.comp.Lower.visitForeachLoop(Lower.java:3133)
	at com.sun.tools.javac.tree.JCTree$JCEnhancedForLoop.accept(JCTree.java:907)
	at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
	at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)
	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.comp.Lower.visitBlock(Lower.java:3311)
	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:781)
	at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
	at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)
	at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:144)
	at com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2619)
	at com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2538)
	at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:669)
	at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
	at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)
	at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2283)
	at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:591)
	at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
	at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)
	at com.sun.tools.javac.comp.Lower.translate(Lower.java:2180)
	at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3651)
	at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1393)
	at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1271)
	at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:870)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:829)
	at com.sun.tools.javac.main.Main.compile(Main.java:419)
	at com.sun.tools.javac.main.Main.compile(Main.java:333)
	at com.sun.tools.javac.main.Main.compile(Main.java:324)
	at com.sun.tools.javac.Main.compile(Main.java:94)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:554)
	at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:161)
	at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:605)
	at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class TestMe {
public static void main() {
final List<File> attachedJars = new ArrayList<>();
for(File attachedJar : attachedJars)
	try (
		final FileInputStream is = new FileInputStream(attachedJar)
	) {
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Take the above code and do this instead:

class TestMe {
public static void main() {
final List<File> attachedJars = new ArrayList<>();
for(File attachedJar : attachedJars) {
	try (
		final FileInputStream is = new FileInputStream(attachedJar)
	) {
	}
}
}

Comments
test: http://hg.openjdk.java.net/jdk8/tl/langtools/file/250f0acf880c/test/tools/javac/TryWithResources/T7178324.java
18-12-2012

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-comp/langtools/rev/f071cd32d297
14-08-2012

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-main/langtools/rev/f071cd32d297
11-08-2012

EVALUATION Yes this is a bug. Fix known - testing the fix.
26-06-2012