### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java,v retrieving revision 1.24 diff -u -r1.24 AssignmentTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 10 Oct 2005 10:29:41 -0000 1.24 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 4 Jan 2006 14:15:43 -0000 @@ -1472,6 +1472,104 @@ }, "a=11b=1"); } +// warn upon parameter assignment +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773 +public void test040() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " b = false;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " b = false;\n" + + " ^\n" + + "The parameter b should not be assigned\n" + + "----------\n", + null, true, options); +} +// warn upon parameter assignment +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773 +// diagnose within fake reachable code +public void test041() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " if (false) {\n" + + " b = false;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " b = false;\n" + + " ^\n" + + "The parameter b should not be assigned\n" + + "----------\n", + null, true, options); +} +// warn upon parameter assignment +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773 +// diagnose within fake reachable code +public void test042() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " if (true) {\n" + + " return;\n" + + " }\n" + + " b = false;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " b = false;\n" + + " ^\n" + + "The parameter b should not be assigned\n" + + "----------\n", + null, true, options); +} +// warn upon parameter assignment +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773 +// we only show the 'assignment to final' error here +public void test043() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(final boolean b) {\n" + + " if (false) {\n" + + " b = false;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " b = false;\n" + + " ^\n" + + "The final local variable b cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n", + null, true, options); +} public static Class testClass() { return AssignmentTest.class; } Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v retrieving revision 1.28 diff -u -r1.28 BatchCompilerTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 6 Dec 2005 16:23:05 -0000 1.28 +++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 4 Jan 2006 14:15:44 -0000 @@ -2082,6 +2082,43 @@ false); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773 +// complain on assignment to parameters +public void test037() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(int i, final int j) {\n" + + " i = 0; // warning\n" + + " j = 0; // error\n" + + " }\n" + + "}\n"}, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 " + + " -cp \"" + OUTPUT_DIR + "\"" + + " -warn:+paramAssign" + + " -proceedOnError" + + " -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---" + + File.separator + "X.java\n" + + " (at line 3)\n" + + " i = 0; // warning\n" + + " ^\n" + + "The parameter i should not be assigned\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---" + File.separator + "X.java\n" + + " (at line 4)\n" + + " j = 0; // error\n" + + " ^\n" + + "The final local variable j cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "2 problems (1 error, 1 warning)", + true); +} + public static Class testClass() { return BatchCompilerTest.class; } #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/core/compiler/IProblem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java,v retrieving revision 1.162 diff -u -r1.162 IProblem.java --- compiler/org/eclipse/jdt/core/compiler/IProblem.java 2 Dec 2005 15:50:14 -0000 1.162 +++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 4 Jan 2006 14:15:46 -0000 @@ -72,6 +72,8 @@ * IBM Corporation - added the following constants * IllegalUsageOfQualifiedTypeReference * InvalidDigit + * IBM Corporation - added the following constants + * ParameterAssignment *******************************************************************************/ package org.eclipse.jdt.core.compiler; @@ -286,7 +288,9 @@ int TooManyArrayDimensions = Internal + 68; /** @since 2.1 */ int BytecodeExceeds64KLimitForConstructor = Internal + 69; - + /** @since 3.2 */ + int ParameterAssignment = Internal + 860; + // fields int UndefinedField = FieldRelated + 70; int NotVisibleField = FieldRelated + 71; Index: batch/org/eclipse/jdt/internal/compiler/batch/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties,v retrieving revision 1.484 diff -u -r1.484 messages.properties --- batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 14 Dec 2005 17:28:06 -0000 1.484 +++ batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 4 Jan 2006 14:15:46 -0000 @@ -153,6 +153,7 @@ \ noEffectAssign + assignment without effect\n\ \ null missing or redundant null check\n\ \ over-ann missing @Override annotation\n\ +\ paramAssign assignment to a parameter\n\ \ pkgDefaultMethod + attempt to override package-default method\n\ \ raw usage of raw type\n\ \ semicolon unnecessary semicolon, empty statement\n\ Index: batch/org/eclipse/jdt/internal/compiler/batch/Main.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java,v retrieving revision 1.220 diff -u -r1.220 Main.java --- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 25 Nov 2005 18:38:05 -0000 1.220 +++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 4 Jan 2006 14:15:46 -0000 @@ -1912,6 +1912,10 @@ this.options.put( CompilerOptions.OPTION_ReportUnusedLabel, isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); + } else if (token.equals("paramAssign")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportParameterAssignment, + isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); } else { throw new InvalidInputException(Main.bind("configure.invalidWarning", token)); //$NON-NLS-1$ } Index: compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties,v retrieving revision 1.191 diff -u -r1.191 messages.properties --- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 2 Dec 2005 15:50:14 -0000 1.191 +++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 4 Jan 2006 14:15:48 -0000 @@ -558,3 +558,5 @@ 857 = Incorrect number of type arguments for generic constructor <{3}>{0}({1}) of type {2}; it cannot be parameterized with arguments <{4}> 858 = The parameterized constructor <{3}>{0}({1}) of type {2} is not applicable for the arguments ({4}) 859 = The constructor {0}({1}) of raw type {2} is no longer generic; it cannot be parameterized with arguments <{3}> + +860 = The parameter {0} should not be assigned Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v retrieving revision 1.275 diff -u -r1.275 ProblemReporter.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 2 Dec 2005 15:50:14 -0000 1.275 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 4 Jan 2006 14:15:48 -0000 @@ -1469,6 +1469,9 @@ case IProblem.JavadocMissing: return CompilerOptions.MissingJavadocComments; + + case IProblem.ParameterAssignment: + return CompilerOptions.ParameterAssignment; } return 0; } @@ -4484,6 +4487,15 @@ compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceStart, compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd); } +public void parameterAssignment(LocalVariableBinding local, ASTNode location) { + String[] arguments = new String[] { new String(local.readableName())}; + this.handle( + IProblem.ParameterAssignment, + arguments, + arguments, + location.sourceStart, + location.sourceEnd); +} private String parameterBoundAsString(TypeVariableBinding typeVariable, boolean makeShort) { StringBuffer nameBuffer = new StringBuffer(10); if (typeVariable.firstBound == typeVariable.superclass) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java,v retrieving revision 1.82 diff -u -r1.82 SingleNameReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 5 Dec 2005 11:54:30 -0000 1.82 +++ compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 4 Jan 2006 14:15:47 -0000 @@ -119,6 +119,9 @@ currentScope.problemReporter().cannotAssignToFinalOuterLocal(localBinding, this); } } + else /* avoid double diagnostic */ if (localBinding.isArgument) { + currentScope.problemReporter().parameterAssignment(localBinding, this); + } flowInfo.markAsDefinitelyAssigned(localBinding); } manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo); Index: compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java,v retrieving revision 1.150 diff -u -r1.150 CompilerOptions.java --- compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 14 Nov 2005 18:47:41 -0000 1.150 +++ compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 4 Jan 2006 14:15:47 -0000 @@ -103,6 +103,7 @@ public static final String OPTION_ReportUnhandledWarningToken = "org.eclipse.jdt.core.compiler.problem.unhandledWarningToken"; //$NON-NLS-1$ public static final String OPTION_ReportUnusedLabel = "org.eclipse.jdt.core.compiler.problem.unusedLabel"; //$NON-NLS-1$ public static final String OPTION_FatalOptionalError = "org.eclipse.jdt.core.compiler.problem.fatalOptionalError"; //$NON-NLS-1$ + public static final String OPTION_ReportParameterAssignment = "org.eclipse.jdt.core.compiler.problem.parameterAssignment"; //$NON-NLS-1$ // Backward compatibility public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$ @@ -185,6 +186,7 @@ public static final long UnhandledWarningToken = ASTNode.Bit45L; public static final long RawTypeReference = ASTNode.Bit46L; public static final long UnusedLabel = ASTNode.Bit47L; + public static final long ParameterAssignment = ASTNode.Bit48L; // Default severity level for handlers public long errorThreshold = 0; @@ -393,6 +395,7 @@ optionsMap.put(OPTION_ReportNullReference, getSeverityString(NullReference)); optionsMap.put(OPTION_SuppressWarnings, this.suppressWarnings ? ENABLED : DISABLED); optionsMap.put(OPTION_ReportUnhandledWarningToken, getSeverityString(UnhandledWarningToken)); + optionsMap.put(OPTION_ReportParameterAssignment, getSeverityString(ParameterAssignment)); return optionsMap; } @@ -633,7 +636,8 @@ if ((optionValue = optionsMap.get(OPTION_ReportIncompleteEnumSwitch)) != null) updateSeverity(IncompleteEnumSwitch, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportUnhandledWarningToken)) != null) updateSeverity(UnhandledWarningToken, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportUnusedLabel)) != null) updateSeverity(UnusedLabel, optionValue); - + if ((optionValue = optionsMap.get(OPTION_ReportParameterAssignment)) != null) updateSeverity(ParameterAssignment, optionValue); + // Javadoc options if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) { if (ENABLED.equals(optionValue)) { @@ -798,6 +802,7 @@ buf.append("\n\t- unhandled warning token: ").append(getSeverityString(UnhandledWarningToken)); //$NON-NLS-1$ buf.append("\n\t- unused label: ").append(getSeverityString(UnusedLabel)); //$NON-NLS-1$ buf.append("\n\t- treat optional error as fatal: ").append(this.treatOptionalErrorAsFatal ? ENABLED : DISABLED); //$NON-NLS-1$ + buf.append("\n\t- parameter assignment: ").append(getSeverityString(ParameterAssignment)); //$NON-NLS-1$ return buf.toString(); } @@ -898,6 +903,7 @@ OPTION_ReportUnusedPrivateMember, OPTION_ReportVarargsArgumentNeedCast, OPTION_ReportUnhandledWarningToken, + OPTION_ReportParameterAssignment, }; return result; } @@ -949,6 +955,8 @@ return "unchecked"; //$NON-NLS-1$ case (int) UnusedLabel: return "unused"; //$NON-NLS-1$ + case (int) (ParameterAssignment >>> 32) : + return "paramAssign"; //$NON-NLS-1$ } } return null; @@ -985,6 +993,10 @@ if ("nls".equals(warningToken)) //$NON-NLS-1$ return NonExternalizedString; break; + case 'p' : + if ("paramAssign".equals(warningToken)) //$NON-NLS-1$ + return ParameterAssignment; + break; case 's' : if ("serial".equals(warningToken)) //$NON-NLS-1$ return MissingSerialVersion;