Community
Participate
Working Groups
Compile the following two files: Color.java: ---------------------- package pack; enum Color {WHITE, BLACK} ---------------------- Test.java: package pack; import static pack.Color.*; public class Test { public static void main(String[] args) { Color c = BLACK; switch(c) { case BLACK: System.out.println("Black"); break; case WHITE: System.out.println("White"); break; } } } ----------------------------------------- Execute pack.Test and it will print out: Black as expected. Now reorder the two constants inside Color.java and recompile ONLY Color.java. Now execute pack.Test and it will print out: White This violates 13.4.26 of JLS V3 The problem is that the generated switch depends on the ordinal value from the enum. javac creates a translation table from compile time ordinal-> run time ordinal and switches based on the translated value.
Created attachment 21522 [details] Apply on HEAD
Created attachment 21523 [details] Apply on HEAD of org.eclipse.jdt.core.tests.compiler Corresponding regression tests. I will add more.
I just found a bug in my patch when I have two switchs for the same enum type. I create the synthetic field twice. I am investigating.
Created attachment 21527 [details] Apply on HEAD
Created attachment 21528 [details] Apply on HEAD Remove HashMap from SwitchStatement to replace it with a SyntheticMethodBinding field. A switch statement can only have one synthetic method. So there is no need for a hash map.
Created attachment 21529 [details] Apply on HEAD of org.eclipse.jdt.core.tests.compiler More tests.
Fixed and released in HEAD. Regression tests in org.eclipse.jdt.core.tests.compiler.regression.EnumTest.test105-111. Changes in: org.eclipse.jdt.internal.compiler.ClassFile org.eclipse.jdt.internal.compiler.ast.SwitchStatement org.eclipse.jdt.internal.compiler.codegen.CodeStream org.eclipse.jdt.internal.compiler.codegen.ConstantPool org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding org.eclipse.jdt.internal.compiler.lookup.TypeConstants
Verified for 3.1 RC1 with build I20050527-0010.