-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1, 1.1.4
-
generic, sparc
-
solaris_2.5.1
Name: laC46010 Date: 03/16/98
javac (JDK1.0.2 and later) treats expressions a.b.c and a.c (
where 'a' names an instance of class T,
b - non-final reference to T,
c - final non-static field of class T)
as a constant expressions which contradicts the JLS (15.27).
The JLS (15.27) says :
"A compile-time constant expression is an expression denoting a value
of primitive type or a String that is composed using only the
following:
Literals of primitive type and literals of type String
Casts to primitive types and casts to type String
The unary operators +, -, ~, and ! (but not ++ or --)
The multiplicative operators *, /, and %
The additive operators + and -
The shift operators <<, >>, and >>>
The relational operators <, <=, >, and >= (but not instanceof)
The equality operators == and !=
The bitwise and logical operators &, ^, and |
The conditional-and operator && and the conditional-or operator ||
The ternary conditional operator ? :
Simple names that refer to final variables whose initializers are
constant expressions
Qualified names of the form TypeName . Identifier that refer to
final variables whose initializers are constant expressions
Compile-time constant expressions are used in case labels in switch
statements..."
The mentioned two expressions can't be constructed using any of these.
See full examples below:
------------------------- expr49626.java --------------------------
import java.io.PrintStream;
class A_fa32121 {
public final int a = 0;
public A_fa32121 next = null;
public A_fa32121 getNext() { return next; }
}
public class expr49626 {
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
public static int run(String argv[], PrintStream out) {
A_fa32121 a_fa32121 = new A_fa32121();
int var = 0;
switch (var) {
case a_fa32121.a :
break;
default : ;
}
return 0/*STATUS_PASSED*/;
}
}
-----------------------------------------------------------------------------
> /export/ld14/java/dest/jdk1.2b3L/solaris/bin/javac -d . expr49626.java
>
------------------------- expr49628.java --------------------------
import java.io.PrintStream;
class A_fa32123 {
public final int a = 0;
public A_fa32123 next = null;
public A_fa32123 getNext() { return next; }
}
public class expr49628 {
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
public static int run(String argv[], PrintStream out) {
A_fa32123 a_fa32123 = new A_fa32123();
int var = 0;
switch (var) {
case a_fa32123.next.a :
break;
default : ;
}
return 0/*STATUS_PASSED*/;
}
}
-----------------------------------------------------------------------------
> /export/ld14/java/dest/jdk1.2b3L/solaris/bin/javac -d . expr49628.java
>
======================================================================
From bug 4093405:
this.value is being allowed as a case label as well. The underlying
cause is the same.
todd.turnidge@Eng 1998-04-09
- duplicates
-
JDK-4093405 "this.value" allowed as case label.
- Closed
-
JDK-4266342 javac allows improper qualified name in switch case label
- Resolved