[kaffe] error:Switch label must be constant [JLS 14.10]

Ito Kazumitsu ito.kazumitsu at hitachi-cable.co.jp
Mon Oct 27 17:09:02 PST 2003


The attached programs do not compile with KJC:

bash$ java at.dms.kjc.Main Trigger*.java
TriggerDef.java:10: error:Switch label must be constant [JLS 14.10]
TriggerDef.java:4: error:Method "indexToRight" must return a value [JLS 8.4.5]

This error occurs both with kjc-2.1B and with the modified kjc.jar
from Kaffe CVS.

Since every field declaration in the body of an interface is
implicitly public, static, and final [JLS 9.3],  the expression
used in this case as the switch label should be treated as a constant.

The following programs were copied from HSQLDB and simplified for testing.

bash$ cat Trigger.java 
public interface Trigger {

    int INSERT_AFTER      = 0;
    int DELETE_AFTER      = 1;
    int UPDATE_AFTER      = 2;
    int INSERT_BEFORE     = INSERT_AFTER + TriggerDef.NUM_TRIGGER_OPS;
    int DELETE_BEFORE     = DELETE_AFTER + TriggerDef.NUM_TRIGGER_OPS;
    int UPDATE_BEFORE     = UPDATE_AFTER + TriggerDef.NUM_TRIGGER_OPS;
    int INSERT_AFTER_ROW  = INSERT_AFTER + 2 * TriggerDef.NUM_TRIGGER_OPS;
    int DELETE_AFTER_ROW  = DELETE_AFTER + 2 * TriggerDef.NUM_TRIGGER_OPS;
    int UPDATE_AFTER_ROW  = UPDATE_AFTER + 2 * TriggerDef.NUM_TRIGGER_OPS;
    int INSERT_BEFORE_ROW = INSERT_BEFORE + 2 * TriggerDef.NUM_TRIGGER_OPS;
    int DELETE_BEFORE_ROW = DELETE_BEFORE + 2 * TriggerDef.NUM_TRIGGER_OPS;
    int UPDATE_BEFORE_ROW = UPDATE_BEFORE + 2 * TriggerDef.NUM_TRIGGER_OPS;

}
bash$ cat TriggerDef.java 
class TriggerDef {

    static final int NUM_TRIGGER_OPS = 3;    // ie ins,del,upd
    public static int indexToRight(int idx) {

        switch (idx) {

            case Trigger.DELETE_AFTER :
            case Trigger.DELETE_AFTER_ROW :
            case Trigger.DELETE_BEFORE :
            case Trigger.DELETE_BEFORE_ROW :
            case Trigger.INSERT_AFTER :
            case Trigger.INSERT_AFTER_ROW :
            case Trigger.INSERT_BEFORE :
            case Trigger.INSERT_BEFORE_ROW :
            case Trigger.UPDATE_AFTER :
            case Trigger.UPDATE_AFTER_ROW :
            case Trigger.UPDATE_BEFORE :
            case Trigger.UPDATE_BEFORE_ROW :
            default :
                return 0;
        }
    }
}




More information about the kaffe mailing list