View | Details | Raw Unified | Return to bug 359334 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (-1 lines)
Lines 11238-11244 Link Here
11238
}
11238
}
11239
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285088
11239
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285088
11240
public void test200() {
11240
public void test200() {
11241
	Map options = getCompilerOptions();
11242
	String errorMessage =
11241
	String errorMessage =
11243
				"----------\n" + 
11242
				"----------\n" + 
11244
				"1. ERROR in X.java (at line 3)\n" + 
11243
				"1. ERROR in X.java (at line 3)\n" + 
(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java (+40 lines)
Lines 10-15 Link Here
10
 *     Stephan Herrmann - Contributions for
10
 *     Stephan Herrmann - Contributions for
11
 *     							bug 358827 - [1.7] exception analysis for t-w-r spoils null analysis
11
 *     							bug 358827 - [1.7] exception analysis for t-w-r spoils null analysis
12
 *     							bug 349326 - [1.7] new warning for missing try-with-resources
12
 *     							bug 349326 - [1.7] new warning for missing try-with-resources
13
 *     							bug 359334 - Analysis for resource leak warnings does not consider exceptions as method exit points
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.core.tests.compiler.regression;
15
package org.eclipse.jdt.core.tests.compiler.regression;
15
16
Lines 4942-4947 Link Here
4942
		true,
4943
		true,
4943
		options);
4944
		options);
4944
}
4945
}
4946
// Bug 359334 - Analysis for resource leak warnings does not consider exceptions as method exit points
4947
public void test056throw1() {
4948
	Map options = getCompilerOptions();
4949
	options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR);
4950
	options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR);
4951
	options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.ERROR);
4952
	options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR);
4953
	this.runNegativeTest(
4954
		new String[] {
4955
			"X.java",
4956
			"import java.io.FileReader;\n" +
4957
			"public class X {\n" +
4958
			"    void foo2(boolean a, boolean b, boolean c) throws Exception {\n" +
4959
			"        FileReader reader = new FileReader(\"file\");\n" +
4960
			"        if(a)\n" +
4961
			"            throw new Exception();    //warning 1\n" +
4962
			"        else if (b)\n" +
4963
			"            reader.close();\n" +
4964
			"        else if(c)\n" +
4965
			"            throw new Exception();    //warning 2\n" +
4966
			"        reader.close();\n" +
4967
			"    }\n" +
4968
			"}\n"
4969
		},
4970
		"----------\n" + 
4971
		"1. ERROR in X.java (at line 6)\n" +
4972
		"	throw new Exception();    //warning 1\n" +
4973
		"	^^^^^^^^^^^^^^^^^^^^^^\n" +
4974
		"Resource leak: \'reader\' is not closed at this location\n" +
4975
		"----------\n" +
4976
		"2. ERROR in X.java (at line 10)\n" +
4977
		"	throw new Exception();    //warning 2\n" +
4978
		"	^^^^^^^^^^^^^^^^^^^^^^\n" +
4979
		"Resource leak: \'reader\' is not closed at this location\n" +
4980
		"----------\n",
4981
		null,
4982
		true,
4983
		options);	
4984
}
4945
public static Class testClass() {
4985
public static Class testClass() {
4946
	return TryWithResourcesStatementTest.class;
4986
	return TryWithResourcesStatementTest.class;
4947
}
4987
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ThrowStatement.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann - Contribution for bug 359334 - Analysis for resource leak warnings does not consider exceptions as method exit points
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
12
package org.eclipse.jdt.internal.compiler.ast;
12
13
Lines 35-40 Link Here
35
	this.exception.checkNPE(currentScope, flowContext, flowInfo);
36
	this.exception.checkNPE(currentScope, flowContext, flowInfo);
36
	// need to check that exception thrown is actually caught somewhere
37
	// need to check that exception thrown is actually caught somewhere
37
	flowContext.checkExceptionHandlers(this.exceptionType, this, flowInfo, currentScope);
38
	flowContext.checkExceptionHandlers(this.exceptionType, this, flowInfo, currentScope);
39
	currentScope.checkUnclosedCloseables(flowInfo, null/*ignore exception exits from flowContext*/, this);
38
	return FlowInfo.DEAD_END;
40
	return FlowInfo.DEAD_END;
39
}
41
}
40
42

Return to bug 359334