Community
Participate
Working Groups
Code based, v_810. The 'this.exception.computeConversion(scope, this.exceptionType, this.exceptionType);' statement in ThrowStatement#resolve can be commented out without tilting any JDT Core test case. This implies that either the statement is unneeded, or the test suite should be augmented. I have not investigated which of these is the right option (got alerted by the fact that a peculiar step-through was obviously doing nothing at all, but this does not prove that the statement is useless).
Looking at the code it is very tempting to say, the mentioned line will never do any useful stuff, but: public class C { static <T> T id(T in) { return in; } public static void main(String[] args) throws Throwable { throw id(new Exception()); } } this compiles with and without the line in question, however, executing the class in one case yields: Exception in thread "main" java.lang.Exception at C.main(C.java:4) in the other case you get: Exception in thread "main" java.lang.VerifyError: (class: C, method: main signature: ([Ljava/lang/String;)V) Can only throw Throwable objects (You may guess which is which ;-)
Here's a snippet that tests the line in question: // https://bugs.eclipse.org/bugs/show_bug.cgi?id=202393 // improve coverage of tests. public void test0701_legalByteCode() { if (this.complianceLevel < ClassFileConstants.JDK1_5) return; this.runConformTest( new String[] { "Bug202393.java", "public class Bug202393 {\n" + " static <T> T id(T in) { return in; }\n" + " public static void main(String[] args) {\n" + " try {" + " bad();" + " } catch (Throwable t) {\n" + " System.out.print(\"CAUGHT\");\n" + " }\n" + " }\n" + " static void bad() throws Throwable {\n" + " throw id(new Exception());\n" + " }\n" + "}\n"}, "CAUGHT" ); } I placed it in org.eclipse.jdt.core.tests.compiler.regression.RuntimeTests and it indeed fails if the line in ThrowStatement is deleted. Is there a better place to test for legal byte code? A better way to handle the <1.5 case?
Thanks Stephan, indeed the line is needed to perform conversions such as generic ones.
Released the new test as GenericTypeTest#test1446, into 3.5M6. Fixed
Verified for 3.5M6 using I20090310-0100