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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java (+2 lines)
Lines 179-184 Link Here
179
				problemReporter(currentMethod).finalMethodCannotBeOverridden(currentMethod, inheritedMethod);
179
				problemReporter(currentMethod).finalMethodCannotBeOverridden(currentMethod, inheritedMethod);
180
			if (!isAsVisible(currentMethod, inheritedMethod))
180
			if (!isAsVisible(currentMethod, inheritedMethod))
181
				problemReporter(currentMethod).visibilityConflict(currentMethod, inheritedMethod);
181
				problemReporter(currentMethod).visibilityConflict(currentMethod, inheritedMethod);
182
			if(inheritedMethod.isSynchronized() && !currentMethod.isSynchronized())
183
				problemReporter(currentMethod).missingSynchronizedOnInheritedMethod(currentMethod);
182
			if (options.reportDeprecationWhenOverridingDeprecatedMethod && inheritedMethod.isViewedAsDeprecated()) {
184
			if (options.reportDeprecationWhenOverridingDeprecatedMethod && inheritedMethod.isViewedAsDeprecated()) {
183
				if (!currentMethod.isViewedAsDeprecated() || options.reportDeprecationInsideDeprecatedCode) {
185
				if (!currentMethod.isViewedAsDeprecated() || options.reportDeprecationInsideDeprecatedCode) {
184
					// check against the other inherited methods to see if they hide this inheritedMethod
186
					// check against the other inherited methods to see if they hide this inheritedMethod
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (+1 lines)
Lines 259-264 Link Here
259
\      javadoc              invalid javadoc\n\
259
\      javadoc              invalid javadoc\n\
260
\      localHiding          local variable hiding another variable\n\
260
\      localHiding          local variable hiding another variable\n\
261
\      maskedCatchBlock   + hidden catch block\n\
261
\      maskedCatchBlock   + hidden catch block\n\
262
\      missingSynchronizedOnInheritedMethod	method missing synchronized of overridden method
262
\      nls                  string literal lacking non-nls tag //$NON-NLS-<n>$\n\
263
\      nls                  string literal lacking non-nls tag //$NON-NLS-<n>$\n\
263
\      noEffectAssign     + assignment without effect\n\
264
\      noEffectAssign     + assignment without effect\n\
264
\      null                 potential missing or redundant null check\n\
265
\      null                 potential missing or redundant null check\n\
(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (+4 lines)
Lines 3168-3173 Link Here
3168
		this.options.put(
3168
		this.options.put(
3169
				CompilerOptions.OPTION_ReportComparingIdentical,
3169
				CompilerOptions.OPTION_ReportComparingIdentical,
3170
				isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3170
				isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3171
	} else if (token.equals("missingSynchronizedOnInheritedMethod")) { //$NON-NLS-1$
3172
		this.options.put(
3173
				CompilerOptions.OPTION_ReportMissingSynchronizedOnInheritedMethod,
3174
				isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3171
	} else if (token.equals("intfNonInherited") || token.equals("interfaceNonInherited")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
3175
	} else if (token.equals("intfNonInherited") || token.equals("interfaceNonInherited")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
3172
		this.options.put(
3176
		this.options.put(
3173
			CompilerOptions.OPTION_ReportIncompatibleNonInheritedInterfaceMethod,
3177
			CompilerOptions.OPTION_ReportIncompatibleNonInheritedInterfaceMethod,
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (+1 lines)
Lines 348-353 Link Here
348
414 = Exception {0} is not compatible with throws clause in {1}, thus this interface cannot be implemented
348
414 = Exception {0} is not compatible with throws clause in {1}, thus this interface cannot be implemented
349
415 = The variable argument type {0} of the method {1} must be the last parameter
349
415 = The variable argument type {0} of the method {1} must be the last parameter
350
416 = The method {0} is overriding a method without making a super invocation
350
416 = The method {0} is overriding a method without making a super invocation
351
417 = The method {0}.{1} is overriding a method without being synchronized
351
352
352
420 = Code snippet support cannot find the class {0}
353
420 = Code snippet support cannot find the class {0}
353
421 = Code snippet support cannot find the method {0}.{1}({2}) 
354
421 = Code snippet support cannot find the method {0}.{1}({2}) 
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+13 lines)
Lines 318-323 Link Here
318
318
319
		case IProblem.ComparingIdentical:
319
		case IProblem.ComparingIdentical:
320
			return CompilerOptions.ComparingIdentical;
320
			return CompilerOptions.ComparingIdentical;
321
			
322
		case IProblem.MissingSynchronizedModifierInInheritedMethod:
323
			return CompilerOptions.MissingSynchronizedModifierInInheritedMethod;
321
	}
324
	}
322
	return 0;
325
	return 0;
323
}
326
}
Lines 410-415 Link Here
410
				case (int)(CompilerOptions.FallthroughCase >>> 32):
413
				case (int)(CompilerOptions.FallthroughCase >>> 32):
411
				case (int)(CompilerOptions.OverridingMethodWithoutSuperInvocation >>> 32):
414
				case (int)(CompilerOptions.OverridingMethodWithoutSuperInvocation >>> 32):
412
				case (int)(CompilerOptions.ComparingIdentical >>> 32):
415
				case (int)(CompilerOptions.ComparingIdentical >>> 32):
416
				case (int)(CompilerOptions.MissingSynchronizedModifierInInheritedMethod >> 32):
413
					return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM;
417
					return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM;
414
418
415
				case (int)(CompilerOptions.TypeHiding >>> 32):
419
				case (int)(CompilerOptions.TypeHiding >>> 32):
Lines 4910-4915 Link Here
4910
		typeDecl.sourceStart,
4914
		typeDecl.sourceStart,
4911
		typeDecl.sourceEnd);
4915
		typeDecl.sourceEnd);
4912
}
4916
}
4917
public void missingSynchronizedOnInheritedMethod(MethodBinding currentMethod) {
4918
	this.handle(
4919
			IProblem.MissingSynchronizedModifierInInheritedMethod,
4920
			new String[] {new String(currentMethod.declaringClass.readableName())},
4921
			new String[] {new String(currentMethod.declaringClass.readableName()),
4922
					new String(currentMethod.readableName())},
4923
			currentMethod.sourceStart(),
4924
			currentMethod.sourceEnd());
4925
}
4913
public void missingTypeInConstructor(ASTNode location, MethodBinding constructor) {
4926
public void missingTypeInConstructor(ASTNode location, MethodBinding constructor) {
4914
	List missingTypes = constructor.collectMissingTypes(null);
4927
	List missingTypes = constructor.collectMissingTypes(null);
4915
	TypeBinding missingType = (TypeBinding) missingTypes.get(0);
4928
	TypeBinding missingType = (TypeBinding) missingTypes.get(0);
(-)model/org/eclipse/jdt/core/JavaCore.java (-1 / +13 lines)
Lines 1468-1474 Link Here
1468
	 * @category CompilerOptionID
1468
	 * @category CompilerOptionID
1469
	 */
1469
	 */
1470
	public static final String COMPILER_PB_COMPARING_IDENTICAL = PLUGIN_ID + ".compiler.problem.comparingIdentical"; //$NON-NLS-1$
1470
	public static final String COMPILER_PB_COMPARING_IDENTICAL = PLUGIN_ID + ".compiler.problem.comparingIdentical"; //$NON-NLS-1$
1471
1471
	/**
1472
	 * Compiler option ID: Reporting Missing Synchronized Modifier On Inherited Method.
1473
	 * <p>When enabled, the compiler will issue an error or a warning if a method
1474
	 * overrides a synchronized method without having a synchronized modifier.
1475
	 * <dl>
1476
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod"</code></dd>
1477
	 * <dt>Possible values:</dt><dd><code>{ "error", "warning", "ignore" }</code></dd>
1478
	 * <dt>Default:</dt><dd><code>"warning"</code></dd>
1479
	 * </dl>
1480
	 * @since 3.5
1481
	 * @category CompilerOptionID
1482
	 */
1483
	public static final String COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD = PLUGIN_ID + ".compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$
1472
	/**
1484
	/**
1473
	 * Core option ID: Computing Project Build Order.
1485
	 * Core option ID: Computing Project Build Order.
1474
	 * <p>Indicate whether JavaCore should enforce the project build order to be based on
1486
	 * <p>Indicate whether JavaCore should enforce the project build order to be based on
(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (-1 / +10 lines)
Lines 120-125 Link Here
120
	public static final String OPTION_Process_Annotations = "org.eclipse.jdt.core.compiler.processAnnotations"; //$NON-NLS-1$
120
	public static final String OPTION_Process_Annotations = "org.eclipse.jdt.core.compiler.processAnnotations"; //$NON-NLS-1$
121
	public static final String OPTION_ReportRedundantSuperinterface =  "org.eclipse.jdt.core.compiler.problem.redundantSuperinterface"; //$NON-NLS-1$
121
	public static final String OPTION_ReportRedundantSuperinterface =  "org.eclipse.jdt.core.compiler.problem.redundantSuperinterface"; //$NON-NLS-1$
122
	public static final String OPTION_ReportComparingIdentical =  "org.eclipse.jdt.core.compiler.problem.comparingIdentical"; //$NON-NLS-1$
122
	public static final String OPTION_ReportComparingIdentical =  "org.eclipse.jdt.core.compiler.problem.comparingIdentical"; //$NON-NLS-1$
123
	public static final String OPTION_ReportMissingSynchronizedOnInheritedMethod =  "org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$
123
124
124
	// Backward compatibility
125
	// Backward compatibility
125
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
126
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
Lines 215-220 Link Here
215
	public static final long UnusedWarningToken = ASTNode.Bit55L;
216
	public static final long UnusedWarningToken = ASTNode.Bit55L;
216
	public static final long RedundantSuperinterface = ASTNode.Bit56L;
217
	public static final long RedundantSuperinterface = ASTNode.Bit56L;
217
	public static final long ComparingIdentical = ASTNode.Bit57L;
218
	public static final long ComparingIdentical = ASTNode.Bit57L;
219
	public static final long MissingSynchronizedModifierInInheritedMethod= ASTNode.Bit58L;
218
220
219
	// Map: String optionKey --> Long irritant>
221
	// Map: String optionKey --> Long irritant>
220
	private static Map OptionToIrritants;
222
	private static Map OptionToIrritants;
Lines 251-257 Link Here
251
		| UnusedTypeArguments
253
		| UnusedTypeArguments
252
		| NullReference
254
		| NullReference
253
		| UnusedWarningToken
255
		| UnusedWarningToken
254
		| ComparingIdentical;
256
		| ComparingIdentical
257
		| MissingSynchronizedModifierInInheritedMethod;
255
258
256
	// By default only lines and source attributes are generated.
259
	// By default only lines and source attributes are generated.
257
	public int produceDebugAttributes = ClassFileConstants.ATTR_SOURCE | ClassFileConstants.ATTR_LINES;
260
	public int produceDebugAttributes = ClassFileConstants.ATTR_SOURCE | ClassFileConstants.ATTR_LINES;
Lines 463-468 Link Here
463
		optionsMap.put(OPTION_Process_Annotations, this.processAnnotations ? ENABLED : DISABLED);
466
		optionsMap.put(OPTION_Process_Annotations, this.processAnnotations ? ENABLED : DISABLED);
464
		optionsMap.put(OPTION_ReportRedundantSuperinterface, getSeverityString(RedundantSuperinterface));
467
		optionsMap.put(OPTION_ReportRedundantSuperinterface, getSeverityString(RedundantSuperinterface));
465
		optionsMap.put(OPTION_ReportComparingIdentical, getSeverityString(ComparingIdentical));
468
		optionsMap.put(OPTION_ReportComparingIdentical, getSeverityString(ComparingIdentical));
469
		optionsMap.put(OPTION_ReportMissingSynchronizedOnInheritedMethod, getSeverityString(MissingSynchronizedModifierInInheritedMethod));
466
		return optionsMap;
470
		return optionsMap;
467
	}
471
	}
468
472
Lines 595-600 Link Here
595
					return OPTION_ReportRedundantSuperinterface;
599
					return OPTION_ReportRedundantSuperinterface;
596
				case (int)(ComparingIdentical >>> 32) :
600
				case (int)(ComparingIdentical >>> 32) :
597
					return OPTION_ReportComparingIdentical;
601
					return OPTION_ReportComparingIdentical;
602
				case (int)(MissingSynchronizedModifierInInheritedMethod >>> 32) :
603
					return OPTION_ReportMissingSynchronizedOnInheritedMethod;
598
			}
604
			}
599
		}
605
		}
600
		return null;
606
		return null;
Lines 884-889 Link Here
884
		if ((optionValue = optionsMap.get(OPTION_ReportUnusedTypeArgumentsForMethodInvocation)) != null) updateSeverity(UnusedTypeArguments, optionValue);
890
		if ((optionValue = optionsMap.get(OPTION_ReportUnusedTypeArgumentsForMethodInvocation)) != null) updateSeverity(UnusedTypeArguments, optionValue);
885
		if ((optionValue = optionsMap.get(OPTION_ReportRedundantSuperinterface)) != null) updateSeverity(RedundantSuperinterface, optionValue);
891
		if ((optionValue = optionsMap.get(OPTION_ReportRedundantSuperinterface)) != null) updateSeverity(RedundantSuperinterface, optionValue);
886
		if ((optionValue = optionsMap.get(OPTION_ReportComparingIdentical)) != null) updateSeverity(ComparingIdentical, optionValue);
892
		if ((optionValue = optionsMap.get(OPTION_ReportComparingIdentical)) != null) updateSeverity(ComparingIdentical, optionValue);
893
		if ((optionValue = optionsMap.get(OPTION_ReportMissingSynchronizedOnInheritedMethod)) != null) updateSeverity(MissingSynchronizedModifierInInheritedMethod, optionValue);
887
894
888
		// Javadoc options
895
		// Javadoc options
889
		if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) {
896
		if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) {
Lines 1081-1086 Link Here
1081
		buf.append("\n\t- unused type arguments for method/constructor invocation: ").append(getSeverityString(UnusedTypeArguments)); //$NON-NLS-1$
1088
		buf.append("\n\t- unused type arguments for method/constructor invocation: ").append(getSeverityString(UnusedTypeArguments)); //$NON-NLS-1$
1082
		buf.append("\n\t- redundant superinterface: ").append(getSeverityString(RedundantSuperinterface)); //$NON-NLS-1$
1089
		buf.append("\n\t- redundant superinterface: ").append(getSeverityString(RedundantSuperinterface)); //$NON-NLS-1$
1083
		buf.append("\n\t- comparing identical expr: ").append(getSeverityString(ComparingIdentical)); //$NON-NLS-1$
1090
		buf.append("\n\t- comparing identical expr: ").append(getSeverityString(ComparingIdentical)); //$NON-NLS-1$
1091
		buf.append("\n\t- missing synchronized on inherited method: ").append(getSeverityString(MissingSynchronizedModifierInInheritedMethod)); //$NON-NLS-1$
1084
		return buf.toString();
1092
		return buf.toString();
1085
	}
1093
	}
1086
1094
Lines 1321-1326 Link Here
1321
		"unqualified-field-access", //$NON-NLS-1$
1329
		"unqualified-field-access", //$NON-NLS-1$
1322
		"unused", //$NON-NLS-1$
1330
		"unused", //$NON-NLS-1$
1323
	};
1331
	};
1332
	
1324
	public static long warningTokenToIrritants(String warningToken) {
1333
	public static long warningTokenToIrritants(String warningToken) {
1325
		// keep in sync with warningTokens and warningTokenFromIrritant
1334
		// keep in sync with warningTokens and warningTokenFromIrritant
1326
		if (warningToken == null || warningToken.length() == 0) return 0;
1335
		if (warningToken == null || warningToken.length() == 0) return 0;
(-)compiler/org/eclipse/jdt/core/compiler/IProblem.java (+2 lines)
Lines 769-774 Link Here
769
	int IllegalVararg = MethodRelated + 415;
769
	int IllegalVararg = MethodRelated + 415;
770
	/** @since 3.3 */
770
	/** @since 3.3 */
771
	int OverridingMethodWithoutSuperInvocation = MethodRelated + 416;
771
	int OverridingMethodWithoutSuperInvocation = MethodRelated + 416;
772
	/** @since 3.5 */
773
	int MissingSynchronizedModifierInInheritedMethod= MethodRelated + 417;
772
774
773
	// code snippet support
775
	// code snippet support
774
	int CodeSnippetMissingClass = Internal + 420;
776
	int CodeSnippetMissingClass = Internal + 420;
(-)guide/jdt_api_options.htm (+14 lines)
Lines 805-810 Link Here
805
</tr>
805
</tr>
806
806
807
<tr>
807
<tr>
808
<td colspan=2><b>Reporting Missing synchronized modifier of inherited methods</b> (<b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#COMPILER_PB_MISSING_COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD">COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD</a></b>)</td>
809
</tr>
810
<tr valign="top">
811
<td rowspan=3>When enabled, the compiler will issue an error or a warning whenever a method overrides a synchronized method without having a synchronized modifier.</td>
812
<td><b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#ERROR">ERROR</a></b></td>
813
</tr>
814
<tr valign="top">
815
<td><b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#WARNING"><i>WARNING</i></a></b></td>
816
</tr>
817
<tr valign="top">
818
<td><b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#IGNORE">IGNORE</a></b></td>
819
</tr>
820
821
<tr>
808
<td colspan=2><b>Reporting Assignment with No Effect</b> (<b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#COMPILER_PB_NO_EFFECT_ASSIGNMENT">COMPILER_PB_NO_EFFECT_ASSIGNMENT</a></b>)</td>
822
<td colspan=2><b>Reporting Assignment with No Effect</b> (<b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#COMPILER_PB_NO_EFFECT_ASSIGNMENT">COMPILER_PB_NO_EFFECT_ASSIGNMENT</a></b>)</td>
809
</tr>
823
</tr>
810
<tr valign="top">
824
<tr valign="top">
(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (+17 lines)
Lines 8676-8679 Link Here
8676
		"----------\n"
8676
		"----------\n"
8677
	);
8677
	);
8678
}
8678
}
8679
8680
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239066
8681
public void test166() {
8682
	this.runNegativeTest(
8683
		new String[] {
8684
			"X.java",
8685
			"class X { synchronized void foo() {} }\n" +
8686
			"class Y extends X { @Override void foo() { } }"
8687
		},
8688
		"----------\n" +
8689
		"1. WARNING in X.java (at line 2)\n" +
8690
		"	class Y extends X { @Override void foo() { } }\n" +
8691
		"	                                   ^^^^^\n" +
8692
		"The method Y.foo() is overriding a method without being synchronized\n" +
8693
		"----------\n"
8694
	);
8695
}
8679
}
8696
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java (+2 lines)
Lines 847-852 Link Here
847
		expectedProblemAttributes.put("JavadocTypeArgumentsForRawGenericConstructor", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC));
847
		expectedProblemAttributes.put("JavadocTypeArgumentsForRawGenericConstructor", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC));
848
		expectedProblemAttributes.put("ExternalProblemNotFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
848
		expectedProblemAttributes.put("ExternalProblemNotFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
849
		expectedProblemAttributes.put("ExternalProblemFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
849
		expectedProblemAttributes.put("ExternalProblemFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
850
		expectedProblemAttributes.put("MissingSynchronizedModifierInInheritedMethod", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
850
		StringBuffer failures = new StringBuffer();
851
		StringBuffer failures = new StringBuffer();
851
		Field[] fields = (iProblemClass = IProblem.class).getFields();
852
		Field[] fields = (iProblemClass = IProblem.class).getFields();
852
		boolean watchInternalCategory = false, printHeader = true;
853
		boolean watchInternalCategory = false, printHeader = true;
Lines 1994-1999 Link Here
1994
		expectedProblemAttributes.put("ExternalProblemNotFixable", SKIP);
1995
		expectedProblemAttributes.put("ExternalProblemNotFixable", SKIP);
1995
		expectedProblemAttributes.put("ExternalProblemFixable", SKIP);
1996
		expectedProblemAttributes.put("ExternalProblemFixable", SKIP);
1996
		expectedProblemAttributes.put("ComparingIdentical", new ProblemAttributes(JavaCore.COMPILER_PB_COMPARING_IDENTICAL));
1997
		expectedProblemAttributes.put("ComparingIdentical", new ProblemAttributes(JavaCore.COMPILER_PB_COMPARING_IDENTICAL));
1998
		expectedProblemAttributes.put("MissingSynchronizedModifierInInheritedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD));
1997
		Map constantNamesIndex = new HashMap();
1999
		Map constantNamesIndex = new HashMap();
1998
		Field[] fields = JavaCore.class.getFields();
2000
		Field[] fields = JavaCore.class.getFields();
1999
		for (int i = 0, length = fields.length; i < length; i++) {
2001
		for (int i = 0, length = fields.length; i < length; i++) {

Return to bug 239066