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 (-7 / +8 lines)
Lines 34-39 Link Here
34
	
34
	
35
	public ReferenceBinding[] handledExceptions;
35
	public ReferenceBinding[] handledExceptions;
36
	int[] isReached;
36
	int[] isReached;
37
	int[] clearUnusedDeclaredThrownExceptionWarning;
37
	int[] isNeeded;
38
	int[] isNeeded;
38
	UnconditionalFlowInfo[] initsOnExceptions;
39
	UnconditionalFlowInfo[] initsOnExceptions;
39
	ObjectCache indexes = new ObjectCache();
40
	ObjectCache indexes = new ObjectCache();
Lines 56-78 Link Here
56
	this.handledExceptions = handledExceptions;
57
	this.handledExceptions = handledExceptions;
57
	int count = handledExceptions.length, cacheSize = (count / ExceptionHandlingFlowContext.BitCacheSize) + 1;
58
	int count = handledExceptions.length, cacheSize = (count / ExceptionHandlingFlowContext.BitCacheSize) + 1;
58
	this.isReached = new int[cacheSize]; // none is reached by default
59
	this.isReached = new int[cacheSize]; // none is reached by default
60
	this.clearUnusedDeclaredThrownExceptionWarning = new int[cacheSize]; // none is reached by default
59
	this.isNeeded = new int[cacheSize]; // none is needed by default
61
	this.isNeeded = new int[cacheSize]; // none is needed by default
60
	this.initsOnExceptions = new UnconditionalFlowInfo[count];
62
	this.initsOnExceptions = new UnconditionalFlowInfo[count];
61
	boolean reachUnchecked = !scope.compilerOptions().
62
		reportUnusedDeclaredThrownExceptionIncludeUncheckedExceptions;
63
	for (int i = 0; i < count; i++) {
63
	for (int i = 0; i < count; i++) {
64
		this.indexes.put(handledExceptions[i], i); // key type  -> value index
64
		this.indexes.put(handledExceptions[i], i); // key type  -> value index
65
		int cacheIndex = i / ExceptionHandlingFlowContext.BitCacheSize, bitMask = 1 << (i % ExceptionHandlingFlowContext.BitCacheSize);
66
		if (handledExceptions[i].isUncheckedException(true)) {
65
		if (handledExceptions[i].isUncheckedException(true)) {
67
			if (reachUnchecked) {
66
			this.isReached[i / ExceptionHandlingFlowContext.BitCacheSize] |= 1 << (i % ExceptionHandlingFlowContext.BitCacheSize);
68
				this.isReached[cacheIndex] |= bitMask;
69
			}
70
			this.initsOnExceptions[i] = flowInfo.unconditionalCopy();
67
			this.initsOnExceptions[i] = flowInfo.unconditionalCopy();
71
		} else {
68
		} else {
72
			this.initsOnExceptions[i] = FlowInfo.DEAD_END;
69
			this.initsOnExceptions[i] = FlowInfo.DEAD_END;
73
		}
70
		}
74
	}
71
	}
75
	System.arraycopy(this.isReached, 0, this.isNeeded, 0, cacheSize);
72
	System.arraycopy(this.isReached, 0, this.isNeeded, 0, cacheSize);
73
	if (!scope.compilerOptions().reportUnusedDeclaredThrownExceptionIncludeUncheckedExceptions) {
74
		System.arraycopy(this.isReached, 0, this.clearUnusedDeclaredThrownExceptionWarning, 0, cacheSize);
75
	}
76
	this.initsOnReturn = FlowInfo.DEAD_END;	
76
	this.initsOnReturn = FlowInfo.DEAD_END;	
77
}
77
}
78
78
Lines 101-107 Link Here
101
		int index = this.indexes.get(this.handledExceptions[i]);
101
		int index = this.indexes.get(this.handledExceptions[i]);
102
		int cacheIndex = index / ExceptionHandlingFlowContext.BitCacheSize;
102
		int cacheIndex = index / ExceptionHandlingFlowContext.BitCacheSize;
103
		int bitMask = 1 << (index % ExceptionHandlingFlowContext.BitCacheSize);
103
		int bitMask = 1 << (index % ExceptionHandlingFlowContext.BitCacheSize);
104
		if ((this.isReached[cacheIndex] & bitMask) == 0) {
104
		if ((this.clearUnusedDeclaredThrownExceptionWarning[cacheIndex] & bitMask) == 0) {
105
			for (int j = 0; j < docCommentReferencesLength; j++) {
105
			for (int j = 0; j < docCommentReferencesLength; j++) {
106
				if (docCommentReferences[j] == this.handledExceptions[i]) {
106
				if (docCommentReferences[j] == this.handledExceptions[i]) {
107
					continue nextHandledException;
107
					continue nextHandledException;
Lines 214-219 Link Here
214
		this.isNeeded[cacheIndex] |= bitMask;
214
		this.isNeeded[cacheIndex] |= bitMask;
215
	}
215
	}
216
	this.isReached[cacheIndex] |= bitMask;
216
	this.isReached[cacheIndex] |= bitMask;
217
	this.clearUnusedDeclaredThrownExceptionWarning[cacheIndex] |= bitMask;
217
	
218
	
218
	this.initsOnExceptions[index] =
219
	this.initsOnExceptions[index] =
219
		(this.initsOnExceptions[index].tagBits & FlowInfo.UNREACHABLE) == 0 ?
220
		(this.initsOnExceptions[index].tagBits & FlowInfo.UNREACHABLE) == 0 ?
(-)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