Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 338881 - [1.7][compiler] Try with resources does not work because of an IAE
Summary: [1.7][compiler] Try with resources does not work because of an IAE
Status: VERIFIED DUPLICATE of bug 338402
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-03 23:02 EST by Deepak Azad CLA
Modified: 2011-08-05 02:54 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Deepak Azad CLA 2011-03-03 23:02:49 EST
--------------------------------------------------------------------------
package p;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

class TryWithResources {
	void foo() {
		File file = new File("C:\\somefile");
		try(FileReader fileReader = new FileReader(file);) {
			char[] in = new char[50];
			fileReader.read(in);
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			
		}
	}
	public static void main(String[] args) {
		new TryWithResources().foo();
	}
}
-------------------------------------------------------------------------

The exception 
java.lang.IllegalArgumentException: info cannot be null
	at org.eclipse.jdt.internal.compiler.codegen.StackMapFrame.addStackItem(StackMapFrame.java:81)
	at org.eclipse.jdt.internal.compiler.ClassFile.traverse(ClassFile.java:4535)
	at org.eclipse.jdt.internal.compiler.ClassFile.generateStackMapTableAttribute(ClassFile.java:3367)
	at org.eclipse.jdt.internal.compiler.ClassFile.completeCodeAttribute(ClassFile.java:1191)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:257)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:182)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:543)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:612)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:361)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1187)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:681)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1183)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:809)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider$1.run(ASTProvider.java:544)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.createAST(ASTProvider.java:537)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:480)
	at org.eclipse.jdt.ui.SharedASTProvider.getAST(SharedASTProvider.java:126)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:169)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$3.run(SelectionListenerWithASTManager.java:154)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Comment 1 Srikanth Sankaran CLA 2011-03-06 23:37:42 EST
Please see https://bugs.eclipse.org/bugs/show_bug.cgi?id=338402 for
the master bug. This feature implementation is work in progress, no
support exists for code generation yet (deep where is the current
failure).
Comment 2 Srikanth Sankaran CLA 2011-03-09 00:44:21 EST
This problem is fixed by the patch posted at 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=338402#c11 which has
been released into the BETA_JAVA7 branch.

I have added a slightly modified version of the test from comment#0
into org.eclipse.jdt.core.tests.compiler.regression.TryWithResourcesStatementTest.test029()
(see bug 338402 comment 12 for printStackTrace related problems)

*** This bug has been marked as a duplicate of bug 338402 ***
Comment 3 Olivier Thomann CLA 2011-06-28 09:26:12 EDT
Verified.