Bug 533475 - ExceptionInIntializerError using ecj-4.7.3 in Java 9. Java
8 works fine, as does compiling with JDK
Change-Id: Icbaf6d26b690ba97056c45ea12760da0b1842d49
Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
index 751faf0..cc7fc5f 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2017 IBM Corporation and others.
+ * Copyright (c) 2005, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -3072,6 +3072,40 @@
};
this.runConformTest(sourceFiles, "1 11", options);
}
+public void testBug533475() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5)
+ return;
+ runConformTest(
+ new String[] {
+ "SwitchBug.java",
+ "public class SwitchBug {\n" +
+ " static class MyClass {\n" +
+ " private static final Object C = \"\";\n" +
+ "\n" +
+ " public enum State {\n" +
+ " ENABLED(C); // pass null constant\n" +
+ "\n" +
+ " State(Object value) {\n" +
+ " } // value can be ignored\n" +
+ " }\n" +
+ "\n" +
+ " /* unused method with switch statement IN SAME CLASS */\n" +
+ " private void unusedMethod() {\n" +
+ " switch (State.ENABLED) {\n" +
+ " case ENABLED:\n" +
+ " break;\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " \n" +
+ " public static void main(String[] args) {\n" +
+ " // access enum values from an other class\n" +
+ " MyClass.State.values();\n" +
+ " System.out.println(\"It runs.\");\n" +
+ " }\n" +
+ "}\n"
+ });
+}
public static Class testClass() {
return SwitchTest.class;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java
index c8bc57a..f2b5b6e 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
index cba674a..0c43198 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -3073,7 +3073,7 @@
}
}
aload_0();
- if (scope.compilerOptions().complianceLevel < ClassFileConstants.JDK9) {
+ if (scope.compilerOptions().complianceLevel < ClassFileConstants.JDK9 || !syntheticFieldBinding.isFinal()) {
// Modifying a final field outside of the <clinit> method is not allowed in 9
dup();
fieldAccess(Opcodes.OPC_putstatic, syntheticFieldBinding, null /* default declaringClass */);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
index 79ad44f..d2c525f 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -1310,7 +1310,7 @@
return;
Collection<FieldBinding> syntheticFields = this.synthetics[SourceTypeBinding.FIELD_EMUL].values();
for (FieldBinding field : syntheticFields) {
- if (CharOperation.prefixEquals(TypeConstants.SYNTHETIC_SWITCH_ENUM_TABLE, field.name)) {
+ if (CharOperation.prefixEquals(TypeConstants.SYNTHETIC_SWITCH_ENUM_TABLE, field.name) && field.isFinal()) {
MethodBinding[] accessors = (MethodBinding[]) this.synthetics[SourceTypeBinding.METHOD_EMUL].get(new String(field.name));
if (accessors == null || accessors[0] == null) // not a field for switch enum
continue;