-
Bug
-
Resolution: Fixed
-
P5
-
None
-
1.3
-
x86
-
windows_nt
-
Verified
The SigTest should check compile-time constants in source mode.
Compile-Time constants affects source compatibility.
If a field, which is a compile-time constant, is changed to become
a non-compile-time constant, them some sources will not compile against
the new version, because compile-time constants can be used in
"case <compile-time constant>:" expressions but regular fields can not.
For example the following class can be compiled:
class Other {
public static final int test = 1;
public static int getInt() {
return 1;
}
}
class Test {
public static final int test = 1;
public static void main(String[] argv) {
switch(Other.getInt()) {
case Other.test: System.out.println("OK"); break;
}
}
}
But changing of the line
public static final int test = 1;
by
public static final int test = getInt();
produces the following compile-time error.
Test.java:11: constant expression required
case Other.test: System.out.println("OK"); break;
^
1 error
The changing of the values does not break source compatibility if the
fields is still compile-time constant. But we have to check values because
they are part of the specification.
Compile-Time constants affects source compatibility.
If a field, which is a compile-time constant, is changed to become
a non-compile-time constant, them some sources will not compile against
the new version, because compile-time constants can be used in
"case <compile-time constant>:" expressions but regular fields can not.
For example the following class can be compiled:
class Other {
public static final int test = 1;
public static int getInt() {
return 1;
}
}
class Test {
public static final int test = 1;
public static void main(String[] argv) {
switch(Other.getInt()) {
case Other.test: System.out.println("OK"); break;
}
}
}
But changing of the line
public static final int test = 1;
by
public static final int test = getInt();
produces the following compile-time error.
Test.java:11: constant expression required
case Other.test: System.out.println("OK"); break;
^
1 error
The changing of the values does not break source compatibility if the
fields is still compile-time constant. But we have to check values because
they are part of the specification.
- relates to
-
JDK-4992007 (reflect) Need a way to distinguish compile-time constants
- Open