### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java,v retrieving revision 1.79 diff -u -r1.79 LocalDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 8 Feb 2011 05:59:17 -0000 1.79 +++ compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 8 Mar 2011 16:40:34 -0000 @@ -38,7 +38,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { // record variable initialization if any - if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { + if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { this.bits |= ASTNode.IsLocalDeclarationReachable; // only set if actually reached } if (this.binding != null && this.type.resolvedType instanceof TypeVariableBinding) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java,v retrieving revision 1.118 diff -u -r1.118 TryStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java 5 Mar 2011 17:18:43 -0000 1.118 +++ compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java 8 Mar 2011 16:40:34 -0000 @@ -159,7 +159,7 @@ catchInfo); this.catchExitInitStateIndexes[i] = currentScope.methodScope().recordInitializationStates(catchInfo); this.catchExits[i] = - (catchInfo.tagBits & FlowInfo.UNREACHABLE) != 0; + (catchInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0; tryInfo = tryInfo.mergedWith(catchInfo.unconditionalInits()); } } @@ -268,7 +268,7 @@ catchInfo); this.catchExitInitStateIndexes[i] = currentScope.methodScope().recordInitializationStates(catchInfo); this.catchExits[i] = - (catchInfo.tagBits & FlowInfo.UNREACHABLE) != 0; + (catchInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0; tryInfo = tryInfo.mergedWith(catchInfo.unconditionalInits()); } } Index: compiler/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java,v retrieving revision 1.45 diff -u -r1.45 ExceptionHandlingFlowContext.java --- compiler/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java 7 Mar 2009 00:59:06 -0000 1.45 +++ compiler/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java 8 Mar 2011 16:40:34 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -227,8 +227,8 @@ } public void recordReturnFrom(UnconditionalFlowInfo flowInfo) { - if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { - if ((this.initsOnReturn.tagBits & FlowInfo.UNREACHABLE) == 0) { + if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { + if ((this.initsOnReturn.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { this.initsOnReturn = this.initsOnReturn.mergedWith(flowInfo); } else { Index: compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java,v retrieving revision 1.69 diff -u -r1.69 FlowContext.java --- compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 4 Mar 2011 12:41:21 -0000 1.69 +++ compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 8 Mar 2011 16:40:34 -0000 @@ -530,7 +530,7 @@ } public void recordSettingFinal(VariableBinding variable, Reference finalReference, FlowInfo flowInfo) { - if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { + if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { // for initialization inside looping statement that effectively loops FlowContext context = this; while (context != null) { Index: compiler/org/eclipse/jdt/internal/compiler/flow/InsideSubRoutineFlowContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/InsideSubRoutineFlowContext.java,v retrieving revision 1.21 diff -u -r1.21 InsideSubRoutineFlowContext.java --- compiler/org/eclipse/jdt/internal/compiler/flow/InsideSubRoutineFlowContext.java 7 Mar 2009 01:08:10 -0000 1.21 +++ compiler/org/eclipse/jdt/internal/compiler/flow/InsideSubRoutineFlowContext.java 8 Mar 2011 16:40:34 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -43,7 +43,7 @@ } public void recordReturnFrom(UnconditionalFlowInfo flowInfo) { - if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { + if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { if (this.initsOnReturn == FlowInfo.DEAD_END) { this.initsOnReturn = (UnconditionalFlowInfo) flowInfo.copy(); } else { Index: compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java,v retrieving revision 1.55 diff -u -r1.55 LoopingFlowContext.java --- compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 5 Mar 2011 17:18:43 -0000 1.55 +++ compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 8 Mar 2011 16:40:34 -0000 @@ -385,8 +385,8 @@ } public void recordContinueFrom(FlowContext innerFlowContext, FlowInfo flowInfo) { - if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { - if ((this.initsOnContinue.tagBits & FlowInfo.UNREACHABLE) == 0) { + if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { + if ((this.initsOnContinue.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { this.initsOnContinue = this.initsOnContinue. mergedWith(flowInfo.unconditionalInitsWithoutSideEffect()); } Index: compiler/org/eclipse/jdt/internal/compiler/flow/SwitchFlowContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/SwitchFlowContext.java,v retrieving revision 1.32 diff -u -r1.32 SwitchFlowContext.java --- compiler/org/eclipse/jdt/internal/compiler/flow/SwitchFlowContext.java 7 Mar 2009 01:08:10 -0000 1.32 +++ compiler/org/eclipse/jdt/internal/compiler/flow/SwitchFlowContext.java 8 Mar 2011 16:40:34 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -42,7 +42,7 @@ } public void recordBreakFrom(FlowInfo flowInfo) { - if ((this.initsOnBreak.tagBits & FlowInfo.UNREACHABLE) == 0) { + if ((this.initsOnBreak.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { this.initsOnBreak = this.initsOnBreak.mergedWith(flowInfo.unconditionalInits()); } else { Index: compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java,v retrieving revision 1.78 diff -u -r1.78 MethodScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java 1 Nov 2010 14:15:47 -0000 1.78 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java 8 Mar 2011 16:40:34 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -409,7 +409,7 @@ } public final int recordInitializationStates(FlowInfo flowInfo) { - if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) != 0) return -1; + if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0) return -1; UnconditionalFlowInfo unconditionalFlowInfo = flowInfo.unconditionalInitsWithoutSideEffect(); long[] extraInits = unconditionalFlowInfo.extra == null ? null : unconditionalFlowInfo.extra[0]; #P org.eclipse.jdt.core.tests Index: Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/ConformTest.java =================================================================== RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/ConformTest.java,v retrieving revision 1.157 diff -u -r1.157 ConformTest.java --- Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/ConformTest.java 5 Mar 2011 17:18:29 -0000 1.157 +++ Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/ConformTest.java 8 Mar 2011 16:40:40 -0000 @@ -6688,15 +6688,13 @@ " [pc: 0, pc: 96] local: delete index: 1 type: boolean\n" + " [pc: 5, pc: 96] local: s index: 2 type: java.lang.String\n" + " [pc: 13, pc: 96] local: buffer index: 3 type: java.lang.StringBuffer\n" + - " [pc: 24, pc: 59] local: datas index: 4 type: java.lang.String[]\n" + - " [pc: 62, pc: 79] local: datas index: 4 type: java.lang.String[]\n" + - " [pc: 34, pc: 59] local: data index: 5 type: java.lang.Object[]\n" + - " [pc: 62, pc: 79] local: data index: 5 type: java.lang.Object[]\n" + - " [pc: 51, pc: 59] local: e index: 6 type: java.lang.Exception\n" + + " [pc: 24, pc: 79] local: datas index: 4 type: java.lang.String[]\n" + + " [pc: 34, pc: 79] local: data index: 5 type: java.lang.Object[]\n" + + " [pc: 51, pc: 62] local: e index: 6 type: java.lang.Exception\n" + " Stack map table: number of frames 8\n" + " [pc: 49, full, stack: {java.lang.Exception}, locals: {X, int, java.lang.String, java.lang.StringBuffer, java.lang.String[], java.lang.Object[]}]\n" + - " [pc: 59, chop 2 local(s)]\n" + - " [pc: 62, append: {java.lang.String[], java.lang.Object[]}]\n" + + " [pc: 59, append: {java.lang.Exception}]\n" + + " [pc: 62, chop 1 local(s)]\n" + " [pc: 76, same]\n" + " [pc: 79, full, stack: {java.lang.Exception}, locals: {X, int, java.lang.String, java.lang.StringBuffer}]\n" + " [pc: 86, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + @@ -7569,6 +7567,44 @@ } } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339139 +// To check that code gen is ok +public void testBug339139() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public abstract class X {\n" + + " private static Object[] bar() {\n" + + " return null;\n" + + " }\n" + + " protected final Object foo() {\n" + + " Object[] tab = null;\n" + + " if(tab != null) {\n" + + " Object[] v = bar(); \n" + + " int length = tab.length;\n" + + " loop : for (int i = 0, max = v.length; i < max; i++) {\n" + + " Object o = v[i];\n" + + " if (o == null) continue loop;\n" + + " if(0 == length) {\n" + + " loop2 : for (int j = 0; j < length; j++) {\n" + + " Object o2 = null;\n" + + " for (int k = 0; k < length; k++) {\n" + + " if (o2 == tab[k]) {\n" + + " continue loop2;\n" + + " }\n" + + " }\n" + + " continue loop;\n" + + " }\n" + + " return o;\n" + + " }\n" + + " }\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}\n", + }); // custom requestor +} + public static Class testClass() { return ConformTest.class; } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java,v retrieving revision 1.31 diff -u -r1.31 ProgrammingProblemsTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java 16 Feb 2011 08:09:15 -0000 1.31 +++ src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java 8 Mar 2011 16:40:47 -0000 @@ -2309,4 +2309,42 @@ true/*shouldFlushOutputDirectory*/, customOptions); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339139 +// Issue local variable not used warning inside deadcode +public void test0059() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object a = null;\n" + + " if (a != null){\n" + + " int j = 3;\n" + + " j++;\n" + // value is not used + " }\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (a != null){\n" + + " int j = 3;\n" + + " j++;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " int j = 3;\n" + + " ^\n" + + "The value of the local variable j is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} } \ No newline at end of file