Summary: | JDT compiler fails to compile legitimate Java code. | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Deyan Bektchiev <dejan> | ||||||
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> | ||||||
Status: | VERIFIED FIXED | QA Contact: | |||||||
Severity: | major | ||||||||
Priority: | P3 | CC: | teryaev | ||||||
Version: | 3.0 | ||||||||
Target Milestone: | 2.1.2 | ||||||||
Hardware: | PC | ||||||||
OS: | Windows NT | ||||||||
Whiteboard: | |||||||||
Attachments: |
|
Description
Deyan Bektchiev
2003-07-24 18:40:44 EDT
Indeed, we should not complain. test case reduced a little bit: public class Sample { public void method() { if (false) { try { try { throw new InterruptedException(); } finally { System.out.println(); } } catch(InterruptedException e) { } } } } Created attachment 5575 [details]
regression test
regression test added Created attachment 5576 [details]
regression test update
added a test for if (true) {} else { ...code... } situation
proposed patch: Index: IfStatement.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compi ler/ast/IfStatement.java,v retrieving revision 1.35 diff -u -r1.35 IfStatement.java --- IfStatement.java 26 Jun 2003 15:59:51 -0000 1.35 +++ IfStatement.java 29 Jul 2003 07:51:19 -0000 @@ -83,7 +83,7 @@ // Save info for code gen thenInitStateIndex = currentScope.methodScope ().recordInitializationStates(thenFlowInfo); - if (!thenStatement.complainIfUnreachable(thenFlowInfo, currentScope, false)) { + if (!isConditionOptimizedFalse && ! thenStatement.complainIfUnreachable(thenFlowInfo, currentScope, false)) { thenFlowInfo = thenStatement.analyseCode(currentScope, flowContext, thenFlowInfo); } @@ -100,7 +100,7 @@ // Save info for code gen elseInitStateIndex = currentScope.methodScope ().recordInitializationStates(elseFlowInfo); - if (!elseStatement.complainIfUnreachable(elseFlowInfo, currentScope, false)) { + if (!isConditionOptimizedTrue && ! elseStatement.complainIfUnreachable(elseFlowInfo, currentScope, false)) { elseFlowInfo = elseStatement.analyseCode(currentScope, flowContext, elseFlowInfo); } This fix would not work as it would entirely skip the flow analysis inside offending fake reachable portions of the ASTs. The real fix is quite more complex and lives elsewhere. Unreachable code should still be processed during the analysis, slightly differently. e.g. if (false) { return; return; // should still complain about being unreachable } The real fix is actually in checks for unreachable flow infos, which should be replaced from "...info.isReachable()" into "...info == FlowInfo.DEAD_END". Down the road we should get rid of DEAD_ENDs since these are loosing track of the initialization information from thereon. Fixed, regression tests added. Backported to 2.1 stream for further integration. Regression test added. Released for 2.1.2 (backported better version, see bug 42692). Regression tests are InitializationTest#test161/test162. These were not backported to 2.1.2 stream. Added now. 2.1.2 stream was missing portion of the fix on TryStatement. Backport complete now. Verified with build 2.1.2 RC2 Verified as well. |