This kind of construct has been seen in several Modena testcases and
I consider it a bug in those testcases, and in general. I wished that
javac would detect it and print out an error or some kind of warning.
class b {
public static int f() {
try {
return 5; /* <---- 5 is NEVER returned! */
}
finally {
return 6;
}
}
}
Without a return expression there appears to be no harm, or mis-understanding
as to what is happening, but with a return expression the behavior is
very very mis-leading... Consider it being even worse:
class b {
public static int f() {
try {
try {
return 5; /* <---- 5 is NEVER returned! */
}
finally {
return 6;
}
}
finally {
return 7;
}
}
}
Now it never returns 5 or 6, yet those statements appear to be executed.
Perhaps a
warning: return expression lost due to abrupt transfer of finally clause
???
-kto
kelly.ohair@Eng 1997-10-24
- duplicates
-
JDK-4128179 # Add a lint-like facility to javac
-
- Closed
-