Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDusi Sarath Chandra2016-01-08 12:22:53 +0000
committerSasikanth Bharadwaj2016-01-21 09:12:09 +0000
commit74c55d3545834cdffedbede2d1f08bc4b7ce7aa7 (patch)
tree8b0d4d7c746a42f88427f7f13c72785f138e4b3a
parent8d6a0633cf178debef55fd7128e1e0229f4b3cdd (diff)
downloadeclipse.jdt.core-I20160124-2000.tar.gz
eclipse.jdt.core-I20160124-2000.tar.xz
eclipse.jdt.core-I20160124-2000.zip
fix for bug 480989 Compiler violates JLS 16 for final fields in Java 7+I20160125-0800I20160125-0400I20160124-2000
Change-Id: I6e95bf9c4cf082a7b4676cb2244fd77de9999b2d Signed-off-by: Dusi Sarath Chandra <dusisarath@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java75
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java11
2 files changed, 83 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java
index fe3d00e929..be896d90b0 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2014 IBM Corporation and others.
+ * Copyright (c) 2005, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -241,6 +241,38 @@ public void test004() {
" ^\n" +
"The blank final field o may not have been initialized\n" +
"----------\n" +
+ (this.complianceLevel >= ClassFileConstants.JDK1_7 ?
+ "4. ERROR in X.java (at line 35)\n" +
+ " System.out.println(this.o); // legal\n" +
+ " ^\n" +
+ "The blank final field o may not have been initialized\n" +
+ "----------\n" +
+ "5. WARNING in X.java (at line 42)\n" +
+ " private final Object o;\n" +
+ " ^\n" +
+ "The value of the field X.Test5.o is not used\n" +
+ "----------\n" +
+ "6. ERROR in X.java (at line 44)\n" +
+ " Test5() {\n" +
+ " ^^^^^^^\n" +
+ "The blank final field o may not have been initialized\n" +
+ "----------\n" +
+ "7. ERROR in X.java (at line 46)\n" +
+ " other.o = new Object(); // illegal! other.o is not assignable\n" +
+ " ^\n" +
+ "The final field X.Test5.o cannot be assigned\n" +
+ "----------\n" +
+ "8. WARNING in X.java (at line 52)\n" +
+ " private final Object o;\n" +
+ " ^\n" +
+ "The value of the field X.Test6.o is not used\n" +
+ "----------\n" +
+ "9. ERROR in X.java (at line 59)\n" +
+ " other.o = new Object(); // illegal! other.o is not assignable\n" +
+ " ^\n" +
+ "The final field X.Test6.o cannot be assigned\n" +
+ "----------\n"
+ :
"4. WARNING in X.java (at line 42)\n" +
" private final Object o;\n" +
" ^\n" +
@@ -265,7 +297,7 @@ public void test004() {
" other.o = new Object(); // illegal! other.o is not assignable\n" +
" ^\n" +
"The final field X.Test6.o cannot be assigned\n" +
- "----------\n");
+ "----------\n"));
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190391
public void test005() {
@@ -2027,6 +2059,45 @@ public void test068() {
"Type mismatch: cannot convert from char to Integer\n" +
"----------\n");
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=480989
+public void testbug480989() {
+ String src =
+ "public abstract class Unassigned {\n" +
+ " public Unassigned() {}\n" +
+ " static class SubClass extends Unassigned {\n" +
+ " private final String test;\n" +
+ " public SubClass(String atest) { // rename\n" +
+ " System.out.println(this.test);\n" +
+ " this.test = atest;\n" +
+ " System.out.println(this.test);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new SubClass(\"Hello World!\");\n" +
+ " }\n" +
+ "}\n";
+ if (this.complianceLevel >= ClassFileConstants.JDK1_7) {
+ this.runNegativeTest(
+ new String[] {
+ "Unassigned.java",
+ src
+ },
+ "----------\n" +
+ "1. ERROR in Unassigned.java (at line 6)\n" +
+ " System.out.println(this.test);\n" +
+ " ^^^^\n" +
+ "The blank final field test may not have been initialized\n" +
+ "----------\n");
+ } else {
+ this.runConformTest(
+ new String[] {
+ "Unassigned.java",
+ src
+ },
+ "null\n" +
+ "Hello World!");
+ }
+}
public static Class testClass() {
return AssignmentTest.class;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
index da0db0ef3c..40e4674280 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -147,6 +147,15 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) {
manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/);
}
+ if (currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_7) {
+ FieldBinding fieldBinding = this.binding;
+ if (fieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
+ FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo);
+ if (!fieldInits.isDefinitelyAssigned(fieldBinding)) {
+ currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
+ }
+ }
+ }
return flowInfo;
}

Back to the top