-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
beta
-
sparc
-
solaris_7
Name: laC46010 Date: 01/14/2000
Javac (JDK1.3.0R) does not take into account boolean constant
expressions which use boolean logical operators '|', '&' or '^'.
The test below uses the constant boolean expression whose value
is "true" as the conditional expression of 'if' statement and
tries to use the variable that has no definitely assigned value
in the 'else' branch. JLS (16.1.1) says, that
"V is definitely assigned after any constant expression
whose value is true when false."
Therefore every variable in the else branch is definitely assigned.
But javac incorrectly reports that variable might not have been
initialized. This error arises in all versions of JDK.
See reduced JCK test source and logs below:
--------------------------------------------------dasg00703.java
public class dasg00703 {
public static void main(String args[]) {
boolean b;
if (true | false) ;
else
if (b) ; // case '|'
if (true & true) ;
else
if (b) ; // case '&'
if (true ^ false) ;
else
if (b) ; // case '^'
}
}
----------------------------------------------------------------
Results of compilation:
$ java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-R)
Java HotSpot(TM) Client VM (build 1.3-R, interpreted mode)
$ javac -d . dasg00703.java
dasg00703.java:6: variable b might not have been initialized
if (b) ; // case '|'
^
dasg00703.java:9: variable b might not have been initialized
if (b) ; // case '&'
^
dasg00703.java:12: variable b might not have been initialized
if (b) ; // case '^'
^
3 errors
$
----------------------------------------------------------------
======================================================================