java/8298: Incomplete enforcement of constant expressions in switch/case
mcmartin@stanford.edu
mcmartin@stanford.edu
Mon Oct 21 00:56:00 GMT 2002
>Number: 8298
>Category: java
>Synopsis: Incomplete enforcement of constant expressions in switch/case
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: accepts-illegal
>Submitter-Id: net
>Arrival-Date: Mon Oct 21 00:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: mcmartin@stanford.edu
>Release: gcj 3.2
>Organization:
>Environment:
>Description:
The GCJ front-end should reject this, as the cases y.a and y.b don't match the definition of ConstantExpression in section 15.28 of the JLS (as required for cases in a switch in section 14.10 of the JLS):
public class test {
static final int a = 1;
static final int b = 2;
public static void main(String[] args) {
int x = 2;
test y = new test();
switch(x) {
case y.a:
System.out.println("Equal to a");
break;
case y.b:
System.out.println("Equal to b");
break;
default:
System.out.println("Something random");
break;
}
}
}
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Java-prs
mailing list