diff options
author | Manoj Palat | 2016-09-01 00:37:18 +0000 |
---|---|---|
committer | Manoj Palat | 2016-09-01 02:05:53 +0000 |
commit | f684b9a68e285ab0ad602f1b9f3fe0bcd956f2f6 (patch) | |
tree | 8eb424af14ba1d0c5c99707efbc1125f6cd5a9ac | |
parent | 76ad8c5fe3b4a269c986af0670bf9d833ece785d (diff) | |
download | eclipse.jdt.core-f684b9a68e285ab0ad602f1b9f3fe0bcd956f2f6.tar.gz eclipse.jdt.core-f684b9a68e285ab0ad602f1b9f3fe0bcd956f2f6.tar.xz eclipse.jdt.core-f684b9a68e285ab0ad602f1b9f3fe0bcd956f2f6.zip |
Fix for Bug 500083 [1.9][compiler] Bad error message/constant forY20160901-1000
non-final field as Try-resource
Change-Id: If5a78f47cd002e075c25d0a0dbd31ba802205822
6 files changed, 17 insertions, 5 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java index b43b58c042..91631a9d84 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java @@ -527,6 +527,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("FieldHidingField", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); expectedProblemAttributes.put("FieldHidingLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); expectedProblemAttributes.put("FieldMissingDeprecatedAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("FieldMustBeFinal", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("FieldTypeAmbiguous", DEPRECATED); expectedProblemAttributes.put("FieldTypeInheritedNameHidesEnclosingName", DEPRECATED); expectedProblemAttributes.put("FieldTypeInternalNameProvided", DEPRECATED); @@ -1376,6 +1377,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("FieldHidingField", new ProblemAttributes(JavaCore.COMPILER_PB_FIELD_HIDING)); expectedProblemAttributes.put("FieldHidingLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_FIELD_HIDING)); expectedProblemAttributes.put("FieldMissingDeprecatedAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION)); + expectedProblemAttributes.put("FieldMustBeFinal", SKIP); expectedProblemAttributes.put("FieldTypeAmbiguous", SKIP); expectedProblemAttributes.put("FieldTypeInheritedNameHidesEnclosingName", SKIP); expectedProblemAttributes.put("FieldTypeInternalNameProvided", SKIP); diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement9Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement9Test.java index dff31c9394..1d596954a0 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement9Test.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement9Test.java @@ -596,12 +596,12 @@ public void testBug488569_018() { "1. ERROR in X.java (at line 10)\n" + " try (this.y2; super.yz;y2) { \n" + " ^^\n" + - "Local variable y2 defined in an enclosing scope must be final or effectively final\n" + + "Field y2 must be final\n" + "----------\n" + "2. ERROR in X.java (at line 10)\n" + " try (this.y2; super.yz;y2) { \n" + " ^^\n" + - "Local variable yz defined in an enclosing scope must be final or effectively final\n" + + "Field yz must be final\n" + "----------\n" + "3. ERROR in X.java (at line 10)\n" + " try (this.y2; super.yz;y2) { \n" + diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java index 846051069a..510bc8eb2b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java @@ -1478,6 +1478,8 @@ void setSourceStart(int sourceStart); int InterfaceSuperInvocationNotBelow18 = Internal + Syntax + 667; /** @since 3.13*/ int InterfaceStaticMethodInvocationNotBelow18 = Internal + Syntax + 668; + /** @since 3.13 */ + int FieldMustBeFinal = Internal + 669; /** diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java index f2c6df159c..94b0d7933c 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java @@ -551,9 +551,7 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) { } else if (stmt instanceof FieldReference) { FieldReference fieldReference = (FieldReference) stmt; if (!fieldReference.binding.isFinal()) - this.scope.problemReporter().cannotReferToNonEffectivelyFinalOuterLocal(fieldReference.binding, fieldReference); - // effective finality maybe tricky to find here. - + this.scope.problemReporter().cannotReferToNonFinalField(fieldReference.binding, fieldReference); } stmt.generateCode(this.scope, codeStream); // Initialize resources ... } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java index d67b17c731..ada26b875b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java @@ -1341,6 +1341,15 @@ public void cannotReferToNonEffectivelyFinalOuterLocal(VariableBinding local, AS nodeSourceStart(local, location), nodeSourceEnd(local, location)); } +public void cannotReferToNonFinalField(VariableBinding local, ASTNode location) { + String[] arguments = new String[] { new String(local.readableName()) }; + this.handle( + IProblem.FieldMustBeFinal, + arguments, + arguments, + nodeSourceStart(local, location), + nodeSourceEnd(local, location)); +} public void cannotReturnInInitializer(ASTNode location) { this.handle( IProblem.CannotReturnInInitializer, diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties index c57f1bcd60..e6988af204 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties @@ -668,6 +668,7 @@ 666 = Syntax error, type annotations are illegal here 667 = Super method references to interface default methods are allowed only at source level 1.8 or above 668 = References to interface static methods are allowed only at source level 1.8 or above +669 = Field {0} must be final ### NULL ANALYSIS FOR OTHER EXPRESSIONS 670 = Null comparison always yields false: this expression cannot be null |