-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.2
-
x86
-
windows_2000
Name: rmT116609 Date: 02/12/2004
FULL PRODUCT VERSION :
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
First, I am not sure if this is a compiler bug or not. It may be a case where the JLS needs to be updated. If so, please forward this report to the proper person/group.
The following code correctly produces a compiler error:
try {
int x = 3;
} catch(InterruptedException e) {}
Here is the error:
Tester.java:7: exception java.lang.InterruptedException is never thrown in body of corresponding try statement
} catch(InterruptedException e) {}
^
1 error
This error makes perfect sense. Now, allow me to change the code slightly:
try {
int x = 3;
} catch(Exception e) {}
This causes no compiler error. Even if you comment out the "int x = 3;" it *STILL* causes no compiler error.
I think it should produce the same error as the previous example.
Now, please allow me to quote section 14.20 from the JLS. This section discusses unreachable catch blocks:
A catch block C is reachable iff both of the following are true:
1. Some expression or throw statement in the try block is
reachable and can throw an exception whose type is
assignable to the parameter of the catch clause C.
(An expression is considered reachable iff the innermost
statement containing it is reachable.)
2. There is no earlier catch block A in the try statement such
that the type of C's parameter is the same as or a subclass
of the type of A's parameter.
In my example code, the catch block is unreachable (as per the spec description) but there is no compiler error. Specifically, there is *NO* expression or throw statement in the try block that can throw an exception assignable to the parameter of the catch clause -- that parameter being of type Exception in my example.
Please note that if I comment out the "int x = 3;" in the try block, I still get no compiler error.
So, as I said, either it is a compiler bug or the JLS needs to be updated to allow for this.
I hope this description is clear. Please feel free to contact me if you need to.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
** See Description **
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect a compiler error
ACTUAL -
No compiler error
REPRODUCIBILITY :
This bug can be reproduced always.
(Incident Review ID: 238540)
======================================================================
FULL PRODUCT VERSION :
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
First, I am not sure if this is a compiler bug or not. It may be a case where the JLS needs to be updated. If so, please forward this report to the proper person/group.
The following code correctly produces a compiler error:
try {
int x = 3;
} catch(InterruptedException e) {}
Here is the error:
Tester.java:7: exception java.lang.InterruptedException is never thrown in body of corresponding try statement
} catch(InterruptedException e) {}
^
1 error
This error makes perfect sense. Now, allow me to change the code slightly:
try {
int x = 3;
} catch(Exception e) {}
This causes no compiler error. Even if you comment out the "int x = 3;" it *STILL* causes no compiler error.
I think it should produce the same error as the previous example.
Now, please allow me to quote section 14.20 from the JLS. This section discusses unreachable catch blocks:
A catch block C is reachable iff both of the following are true:
1. Some expression or throw statement in the try block is
reachable and can throw an exception whose type is
assignable to the parameter of the catch clause C.
(An expression is considered reachable iff the innermost
statement containing it is reachable.)
2. There is no earlier catch block A in the try statement such
that the type of C's parameter is the same as or a subclass
of the type of A's parameter.
In my example code, the catch block is unreachable (as per the spec description) but there is no compiler error. Specifically, there is *NO* expression or throw statement in the try block that can throw an exception assignable to the parameter of the catch clause -- that parameter being of type Exception in my example.
Please note that if I comment out the "int x = 3;" in the try block, I still get no compiler error.
So, as I said, either it is a compiler bug or the JLS needs to be updated to allow for this.
I hope this description is clear. Please feel free to contact me if you need to.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
** See Description **
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect a compiler error
ACTUAL -
No compiler error
REPRODUCIBILITY :
This bug can be reproduced always.
(Incident Review ID: 238540)
======================================================================
- duplicates
-
JDK-4948126 14.21: Try statements, unreachable statements, and unchecked exceptions
-
- Closed
-