-
Type:
Bug
-
Resolution: Won't Fix
-
Priority:
P5
-
None
-
Affects Version/s: 6
-
Component/s: tools
-
x86
-
linux
FULL PRODUCT VERSION :
$ java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
$ javac -version
javac 1.6.0
ADDITIONAL OS VERSION INFORMATION :
Linux softfab08 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux
Ubuntu Linux "edgy" on x86 (Pentium 4).
Package used is "sun-java6-jdk", version 6-00-2ubuntu2, from the Ubuntu "multiverse" repository.
A DESCRIPTION OF THE PROBLEM :
See the included test case. It fails to compile, because the compiler thinks the local final variable "x" might be assigned twice. However, if you look at the code, you will see this is not possible.
The original file with this problem was a lot larger, I simplified it to the included test case. All remaining elements are essential: the while loop, the try-catch and the inner class with at least two final fields that are initialized in the constructor.
I also tested this with javac 1.5.0 and that version had the same problem.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the included test case source.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the test case to compile without errors.
ACTUAL -
Compilation fails with an error message saying that the final local variable might already be assigned.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
$ javac TestCase.java
TestCase.java:12: variable x might already have been assigned
x = null;
^
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class C {
public boolean flag;
public void doIt() {
// Sun JDK (tested 1.5.0 and 1.6.0) fails to compile this with the
// "final" modifier.
final Object x;
while (flag) {
try {} catch (Exception e) {}
}
x = null;
}
private class UnusedButNecessary {
private final Object a;
private final Object b;
public UnusedButNecessary() {
a = null;
b = null;
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Removing the "final" modifier makes the test case compile.
$ java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
$ javac -version
javac 1.6.0
ADDITIONAL OS VERSION INFORMATION :
Linux softfab08 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux
Ubuntu Linux "edgy" on x86 (Pentium 4).
Package used is "sun-java6-jdk", version 6-00-2ubuntu2, from the Ubuntu "multiverse" repository.
A DESCRIPTION OF THE PROBLEM :
See the included test case. It fails to compile, because the compiler thinks the local final variable "x" might be assigned twice. However, if you look at the code, you will see this is not possible.
The original file with this problem was a lot larger, I simplified it to the included test case. All remaining elements are essential: the while loop, the try-catch and the inner class with at least two final fields that are initialized in the constructor.
I also tested this with javac 1.5.0 and that version had the same problem.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the included test case source.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the test case to compile without errors.
ACTUAL -
Compilation fails with an error message saying that the final local variable might already be assigned.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
$ javac TestCase.java
TestCase.java:12: variable x might already have been assigned
x = null;
^
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class C {
public boolean flag;
public void doIt() {
// Sun JDK (tested 1.5.0 and 1.6.0) fails to compile this with the
// "final" modifier.
final Object x;
while (flag) {
try {} catch (Exception e) {}
}
x = null;
}
private class UnusedButNecessary {
private final Object a;
private final Object b;
public UnusedButNecessary() {
a = null;
b = null;
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Removing the "final" modifier makes the test case compile.