### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core 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.218 diff -u -r1.218 Main.java --- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 18 Oct 2005 19:18:29 -0000 1.218 +++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 22 Nov 2005 12:55:01 -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: 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.472 diff -u -r1.472 messages.properties --- batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 15 Nov 2005 13:54:22 -0000 1.472 +++ batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 22 Nov 2005 12:55:01 -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: 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.161 diff -u -r1.161 IProblem.java --- compiler/org/eclipse/jdt/core/compiler/IProblem.java 21 Oct 2005 07:19:17 -0000 1.161 +++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 22 Nov 2005 12:55:01 -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,14 @@ int TooManyArrayDimensions = Internal + 68; /** @since 2.1 */ int BytecodeExceeds64KLimitForConstructor = Internal + 69; - + /** @since 3.2 */ + int ParameterAssignment = Internal + 860; + // REVIEW argument would be more homogeneous with existing code, but JLS + // puts a clear emphasis on parameter -- see p.211 for + // parameter/argument disc. + // examples of existing code: RedefinedArgument, ArgumentIsNeverUsed, + // ArgumentHidingField... + // fields int UndefinedField = FieldRelated + 70; int NotVisibleField = FieldRelated + 71; 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.78 diff -u -r1.78 SingleNameReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 10 Oct 2005 10:29:38 -0000 1.78 +++ compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 22 Nov 2005 12:55:02 -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 22 Nov 2005 12:55:02 -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; 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.273 diff -u -r1.273 ProblemReporter.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 21 Oct 2005 07:19:17 -0000 1.273 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 22 Nov 2005 12:55:03 -0000 @@ -1461,6 +1461,9 @@ case IProblem.JavadocMissing: return CompilerOptions.MissingJavadocComments; + + case IProblem.ParameterAssignment: + return CompilerOptions.ParameterAssignment; } return 0; } @@ -4476,6 +4479,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/problem/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties,v retrieving revision 1.190 diff -u -r1.190 messages.properties --- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 21 Oct 2005 07:19:17 -0000 1.190 +++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 22 Nov 2005 12:55:03 -0000 @@ -557,3 +557,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 #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 22 Nov 2005 12:55:08 -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.26 diff -u -r1.26 BatchCompilerTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 4 Nov 2005 15:06:07 -0000 1.26 +++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 22 Nov 2005 12:55:08 -0000 @@ -2035,6 +2035,41 @@ System.setProperty("user.dir", javaUserDir); } } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773 +public void test036() { + 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; }