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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java (-16 / +21 lines)
Lines 58-78 Link Here
58
	this.isReached = new int[cacheSize]; // none is reached by default
58
	this.isReached = new int[cacheSize]; // none is reached by default
59
	this.isNeeded = new int[cacheSize]; // none is needed by default
59
	this.isNeeded = new int[cacheSize]; // none is needed by default
60
	this.initsOnExceptions = new UnconditionalFlowInfo[count];
60
	this.initsOnExceptions = new UnconditionalFlowInfo[count];
61
	boolean reachUnchecked = !scope.compilerOptions().
61
	if (this.isMethodContext && scope.compilerOptions().reportUnusedDeclaredThrownExceptionIncludeUncheckedExceptions) {
62
		reportUnusedDeclaredThrownExceptionIncludeUncheckedExceptions;
62
		for (int i = 0; i < count; i++) {
63
	for (int i = 0; i < count; i++) {
63
			this.indexes.put(handledExceptions[i], i); // key type  -> value index
64
		this.indexes.put(handledExceptions[i], i); // key type  -> value index
64
			if (handledExceptions[i].isUncheckedException(true)) {
65
		int cacheIndex = i / ExceptionHandlingFlowContext.BitCacheSize, bitMask = 1 << (i % ExceptionHandlingFlowContext.BitCacheSize);
65
				this.initsOnExceptions[i] = flowInfo.unconditionalCopy();
66
		if (handledExceptions[i].isUncheckedException(true)) {
66
			} else {
67
			if (reachUnchecked) {
67
				this.initsOnExceptions[i] = FlowInfo.DEAD_END;
68
				this.isReached[cacheIndex] |= bitMask;
68
			}
69
		}
70
	} else {
71
		for (int i = 0; i < count; i++) {
72
			this.indexes.put(handledExceptions[i], i); // key type  -> value index
73
			if (handledExceptions[i].isUncheckedException(true)) {
74
				this.isReached[i / ExceptionHandlingFlowContext.BitCacheSize] |= 1 << (i % ExceptionHandlingFlowContext.BitCacheSize);
75
				this.initsOnExceptions[i] = flowInfo.unconditionalCopy();
76
			} else {
77
				this.initsOnExceptions[i] = FlowInfo.DEAD_END;
69
			}
78
			}
70
			this.initsOnExceptions[i] = flowInfo.unconditionalCopy();
71
		} else {
72
			this.initsOnExceptions[i] = FlowInfo.DEAD_END;
73
		}
79
		}
74
	}
80
	}
75
	System.arraycopy(this.isReached, 0, this.isNeeded, 0, cacheSize);
81
	if (!this.isMethodContext) {
82
		System.arraycopy(this.isReached, 0, this.isNeeded, 0, cacheSize);
83
	}
76
	this.initsOnReturn = FlowInfo.DEAD_END;	
84
	this.initsOnReturn = FlowInfo.DEAD_END;	
77
}
85
}
78
86
Lines 99-107 Link Here
99
	}
107
	}
100
	nextHandledException: for (int i = 0, count = this.handledExceptions.length; i < count; i++) {
108
	nextHandledException: for (int i = 0, count = this.handledExceptions.length; i < count; i++) {
101
		int index = this.indexes.get(this.handledExceptions[i]);
109
		int index = this.indexes.get(this.handledExceptions[i]);
102
		int cacheIndex = index / ExceptionHandlingFlowContext.BitCacheSize;
110
		if ((this.isReached[index / ExceptionHandlingFlowContext.BitCacheSize] & 1 << (index % ExceptionHandlingFlowContext.BitCacheSize)) == 0) {
103
		int bitMask = 1 << (index % ExceptionHandlingFlowContext.BitCacheSize);
104
		if ((this.isReached[cacheIndex] & bitMask) == 0) {
105
			for (int j = 0; j < docCommentReferencesLength; j++) {
111
			for (int j = 0; j < docCommentReferencesLength; j++) {
106
				if (docCommentReferences[j] == this.handledExceptions[i]) {
112
				if (docCommentReferences[j] == this.handledExceptions[i]) {
107
					continue nextHandledException;
113
					continue nextHandledException;
Lines 207-213 Link Here
207
		boolean wasAlreadyDefinitelyCaught) {
213
		boolean wasAlreadyDefinitelyCaught) {
208
		
214
		
209
	int index = this.indexes.get(exceptionType);
215
	int index = this.indexes.get(exceptionType);
210
	// if already flagged as being reached (unchecked exception handler)
211
	int cacheIndex = index / ExceptionHandlingFlowContext.BitCacheSize;
216
	int cacheIndex = index / ExceptionHandlingFlowContext.BitCacheSize;
212
	int bitMask = 1 << (index % ExceptionHandlingFlowContext.BitCacheSize);
217
	int bitMask = 1 << (index % ExceptionHandlingFlowContext.BitCacheSize);
213
	if (!wasAlreadyDefinitelyCaught) {
218
	if (!wasAlreadyDefinitelyCaught) {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java (+38 lines)
Lines 1328-1331 Link Here
1328
		null /* clientRequestor */,
1328
		null /* clientRequestor */,
1329
		true /* skipJavac */);
1329
		true /* skipJavac */);
1330
}
1330
}
1331
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=216897
1332
// reporting unnecessary declaration of thrown unchecked exceptions as warning
1333
public void test0037_declared_thrown_unchecked_exceptions() {
1334
	Map customOptions = new HashMap();
1335
	customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionIncludeUncheckedExceptions, 
1336
			CompilerOptions.ENABLED);
1337
	runTest(
1338
		new String[] {
1339
			"X.java",
1340
			"public class X {\n" + 
1341
			"  public static final class MyError extends Error {\n" + 
1342
			"    private static final long serialVersionUID = 1L;\n" + 
1343
			"  }\n" + 
1344
			"  public void foo() {\n" + 
1345
			"    try {\n" + 
1346
			"      bar();\n" + 
1347
			"    } catch (MyError e) {\n" + 
1348
			"    }\n" + 
1349
			"  }\n" + 
1350
			"  private void bar() {}\n" + 
1351
			"}"
1352
			},
1353
		null /* errorOptions */,
1354
		new String[] {
1355
			CompilerOptions.OPTION_ReportUnusedDeclaredThrownException
1356
			} /* warningOptions */,
1357
		null /* ignoreOptions */,
1358
		false /* expectingCompilerErrors */,
1359
		"" /* expectedCompilerLog */,
1360
		"" /* expectedOutputString */,
1361
		false /* forceExecution */,
1362
		null /* classLib */,
1363
		true /* shouldFlushOutputDirectory */, 
1364
		null /* vmArguments */, 
1365
		customOptions,
1366
		null /* clientRequestor */,
1367
		true /* skipJavac */);
1368
}
1331
}
1369
}

Return to bug 216897