### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: buildnotes_jdt-core.html =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v retrieving revision 1.6763 diff -u -r1.6763 buildnotes_jdt-core.html --- buildnotes_jdt-core.html 24 Nov 2008 10:21:59 -0000 1.6763 +++ buildnotes_jdt-core.html 24 Nov 2008 12:58:57 -0000 @@ -47,9 +47,27 @@
Project org.eclipse.jdt.core v_926 (cvs).

What's new in this drop

+

Problem Reports Fixed

-254825 +48399 +[compiler] Enhance unreachable code detection +
254825 [javadoc] compile error when referencing outer param from inner class javadoc
252555 [javadoc] NPE on duplicate package-info Index: compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java,v retrieving revision 1.98 diff -u -r1.98 ConstructorDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java 2 Oct 2008 00:46:27 -0000 1.98 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java 24 Nov 2008 12:58:59 -0000 @@ -125,13 +125,11 @@ // propagate to statements if (this.statements != null) { - boolean didAlreadyComplain = false; + int complaintLevel = (nonStaticFieldInfoReachMode & FlowInfo.UNREACHABLE) == 0 ? Statement.NOT_COMPLAINED : Statement.COMPLAINED_FAKE_REACHABLE; for (int i = 0, count = this.statements.length; i < count; i++) { Statement stat = this.statements[i]; - if (!stat.complainIfUnreachable(flowInfo, this.scope, didAlreadyComplain)) { + if ((complaintLevel = stat.complainIfUnreachable(flowInfo, this.scope, complaintLevel)) < Statement.COMPLAINED_UNREACHABLE) { flowInfo = stat.analyseCode(this.scope, constructorContext, flowInfo); - } else { - didAlreadyComplain = true; } } } Index: compiler/org/eclipse/jdt/internal/compiler/ast/Block.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Block.java,v retrieving revision 1.39 diff -u -r1.39 Block.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Block.java 27 Jun 2008 16:03:54 -0000 1.39 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Block.java 24 Nov 2008 12:58:59 -0000 @@ -22,121 +22,105 @@ // the number of explicit declaration , used to create scope public BlockScope scope; - public Block(int explicitDeclarations) { - this.explicitDeclarations = explicitDeclarations; - } - - public FlowInfo analyseCode( - BlockScope currentScope, - FlowContext flowContext, - FlowInfo flowInfo) { - - // empty block - if (this.statements == null) return flowInfo; - boolean didAlreadyComplain = false; - for (int i = 0, max = this.statements.length; i < max; i++) { - Statement stat = this.statements[i]; - if (!stat.complainIfUnreachable(flowInfo, this.scope, didAlreadyComplain)) { - flowInfo = stat.analyseCode(this.scope, flowContext, flowInfo); - } else { - didAlreadyComplain = true; - } - } - return flowInfo; - } - /** - * Code generation for a block - */ - public void generateCode(BlockScope currentScope, CodeStream codeStream) { +public Block(int explicitDeclarations) { + this.explicitDeclarations = explicitDeclarations; +} - if ((this.bits & IsReachable) == 0) { - return; - } - int pc = codeStream.position; - if (this.statements != null) { - for (int i = 0, max = this.statements.length; i < max; i++) { - this.statements[i].generateCode(this.scope, codeStream); - } - } // for local variable debug attributes - if (this.scope != currentScope) { // was really associated with its own scope - codeStream.exitUserScope(this.scope); +public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { + // empty block + if (this.statements == null) return flowInfo; + int complaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED; + for (int i = 0, max = this.statements.length; i < max; i++) { + Statement stat = this.statements[i]; + if ((complaintLevel = stat.complainIfUnreachable(flowInfo, this.scope, complaintLevel)) < Statement.COMPLAINED_UNREACHABLE) { + flowInfo = stat.analyseCode(this.scope, flowContext, flowInfo); } - codeStream.recordPositionsFrom(pc, this.sourceStart); } - - public boolean isEmptyBlock() { - - return this.statements == null; + return flowInfo; +} +/** + * Code generation for a block + */ +public void generateCode(BlockScope currentScope, CodeStream codeStream) { + if ((this.bits & IsReachable) == 0) { + return; } - - public StringBuffer printBody(int indent, StringBuffer output) { - - if (this.statements == null) return output; - for (int i = 0; i < this.statements.length; i++) { - this.statements[i].printStatement(indent + 1, output); - output.append('\n'); + int pc = codeStream.position; + if (this.statements != null) { + for (int i = 0, max = this.statements.length; i < max; i++) { + this.statements[i].generateCode(this.scope, codeStream); } - return output; + } // for local variable debug attributes + if (this.scope != currentScope) { // was really associated with its own scope + codeStream.exitUserScope(this.scope); } + codeStream.recordPositionsFrom(pc, this.sourceStart); +} - public StringBuffer printStatement(int indent, StringBuffer output) { +public boolean isEmptyBlock() { + return this.statements == null; +} - printIndent(indent, output); - output.append("{\n"); //$NON-NLS-1$ - printBody(indent, output); - return printIndent(indent, output).append('}'); +public StringBuffer printBody(int indent, StringBuffer output) { + if (this.statements == null) return output; + for (int i = 0; i < this.statements.length; i++) { + this.statements[i].printStatement(indent + 1, output); + output.append('\n'); } + return output; +} - public void resolve(BlockScope upperScope) { +public StringBuffer printStatement(int indent, StringBuffer output) { + printIndent(indent, output); + output.append("{\n"); //$NON-NLS-1$ + printBody(indent, output); + return printIndent(indent, output).append('}'); +} - if ((this.bits & UndocumentedEmptyBlock) != 0) { - upperScope.problemReporter().undocumentedEmptyBlock(this.sourceStart, this.sourceEnd); - } - if (this.statements != null) { - this.scope = - this.explicitDeclarations == 0 - ? upperScope - : new BlockScope(upperScope, this.explicitDeclarations); - for (int i = 0, length = this.statements.length; i < length; i++) { - this.statements[i].resolve(this.scope); - } +public void resolve(BlockScope upperScope) { + if ((this.bits & UndocumentedEmptyBlock) != 0) { + upperScope.problemReporter().undocumentedEmptyBlock(this.sourceStart, this.sourceEnd); + } + if (this.statements != null) { + this.scope = + this.explicitDeclarations == 0 + ? upperScope + : new BlockScope(upperScope, this.explicitDeclarations); + for (int i = 0, length = this.statements.length; i < length; i++) { + this.statements[i].resolve(this.scope); } } +} - public void resolveUsing(BlockScope givenScope) { - - if ((this.bits & UndocumentedEmptyBlock) != 0) { - givenScope.problemReporter().undocumentedEmptyBlock(this.sourceStart, this.sourceEnd); - } - // this optimized resolve(...) is sent only on none empty blocks - this.scope = givenScope; - if (this.statements != null) { - for (int i = 0, length = this.statements.length; i < length; i++) { - this.statements[i].resolve(this.scope); - } +public void resolveUsing(BlockScope givenScope) { + if ((this.bits & UndocumentedEmptyBlock) != 0) { + givenScope.problemReporter().undocumentedEmptyBlock(this.sourceStart, this.sourceEnd); + } + // this optimized resolve(...) is sent only on none empty blocks + this.scope = givenScope; + if (this.statements != null) { + for (int i = 0, length = this.statements.length; i < length; i++) { + this.statements[i].resolve(this.scope); } } +} - public void traverse( - ASTVisitor visitor, - BlockScope blockScope) { - - if (visitor.visit(this, blockScope)) { - if (this.statements != null) { - for (int i = 0, length = this.statements.length; i < length; i++) - this.statements[i].traverse(visitor, this.scope); - } +public void traverse(ASTVisitor visitor, BlockScope blockScope) { + if (visitor.visit(this, blockScope)) { + if (this.statements != null) { + for (int i = 0, length = this.statements.length; i < length; i++) + this.statements[i].traverse(visitor, this.scope); } - visitor.endVisit(this, blockScope); - } - - /** - * Dispatch the call on its last statement. - */ - public void branchChainTo(BranchLabel label) { - if (this.statements != null) { - this.statements[this.statements.length - 1].branchChainTo(label); - } } + visitor.endVisit(this, blockScope); +} +/** + * Dispatch the call on its last statement. + */ +public void branchChainTo(BranchLabel label) { + if (this.statements != null) { + this.statements[this.statements.length - 1].branchChainTo(label); + } +} } Index: compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java,v retrieving revision 1.56 diff -u -r1.56 AssertStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java 25 Sep 2008 23:10:29 -0000 1.56 +++ compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java 24 Nov 2008 12:58:59 -0000 @@ -67,7 +67,9 @@ // only gets evaluated when escaping - results are not taken into account FlowInfo exceptionInfo = this.exceptionArgument.analyseCode(currentScope, flowContext, assertInfo.copy()); - if (!isOptimizedTrueAssertion){ + if (isOptimizedTrueAssertion){ + currentScope.problemReporter().fakeReachable(this.exceptionArgument); + } else { flowContext.checkExceptionHandlers( currentScope.getJavaLangAssertionError(), this, Index: compiler/org/eclipse/jdt/internal/compiler/ast/EmptyStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/EmptyStatement.java,v retrieving revision 1.22 diff -u -r1.22 EmptyStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/EmptyStatement.java 27 Jun 2008 16:03:56 -0000 1.22 +++ compiler/org/eclipse/jdt/internal/compiler/ast/EmptyStatement.java 24 Nov 2008 12:58:59 -0000 @@ -29,13 +29,13 @@ } // Report an error if necessary - public boolean complainIfUnreachable(FlowInfo flowInfo, BlockScope scope, boolean didAlreadyComplain) { + public int complainIfUnreachable(FlowInfo flowInfo, BlockScope scope, int complaintLevel) { // before 1.4, empty statements are tolerated anywhere if (scope.compilerOptions().complianceLevel < ClassFileConstants.JDK1_4) { - return false; + return complaintLevel; } - return super.complainIfUnreachable(flowInfo, scope, didAlreadyComplain); + return super.complainIfUnreachable(flowInfo, scope, complaintLevel); } public void generateCode(BlockScope currentScope, CodeStream codeStream){ Index: compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java,v retrieving revision 1.60 diff -u -r1.60 IfStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java 27 Jun 2008 16:03:55 -0000 1.60 +++ compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java 24 Nov 2008 12:58:59 -0000 @@ -53,14 +53,10 @@ this.sourceEnd = sourceEnd; } - public FlowInfo analyseCode( - BlockScope currentScope, - FlowContext flowContext, - FlowInfo flowInfo) { - + public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { // process the condition - FlowInfo conditionFlowInfo = - this.condition.analyseCode(currentScope, flowContext, flowInfo); + FlowInfo conditionFlowInfo = this.condition.analyseCode(currentScope, flowContext, flowInfo); + int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED; Constant cst = this.condition.optimizedBooleanConstant(); boolean isConditionOptimizedTrue = cst != Constant.NotAConstant && cst.booleanValue() == true; @@ -77,11 +73,9 @@ } if (this.thenStatement != null) { // Save info for code gen - this.thenInitStateIndex = - currentScope.methodScope().recordInitializationStates(thenFlowInfo); - if (!this.thenStatement.complainIfUnreachable(thenFlowInfo, currentScope, false)) { - thenFlowInfo = - this.thenStatement.analyseCode(currentScope, flowContext, thenFlowInfo); + this.thenInitStateIndex = currentScope.methodScope().recordInitializationStates(thenFlowInfo); + if (this.thenStatement.complainIfUnreachable(thenFlowInfo, currentScope, initialComplaintLevel) < Statement.COMPLAINED_UNREACHABLE) { + thenFlowInfo = this.thenStatement.analyseCode(currentScope, flowContext, thenFlowInfo); } } // code gen: optimizing the jump around the ELSE part @@ -98,11 +92,9 @@ currentScope.problemReporter().unnecessaryElse(this.elseStatement); } // Save info for code gen - this.elseInitStateIndex = - currentScope.methodScope().recordInitializationStates(elseFlowInfo); - if (!this.elseStatement.complainIfUnreachable(elseFlowInfo, currentScope, false)) { - elseFlowInfo = - this.elseStatement.analyseCode(currentScope, flowContext, elseFlowInfo); + this.elseInitStateIndex = currentScope.methodScope().recordInitializationStates(elseFlowInfo); + if (this.elseStatement.complainIfUnreachable(elseFlowInfo, currentScope, initialComplaintLevel) < Statement.COMPLAINED_UNREACHABLE) { + elseFlowInfo = this.elseStatement.analyseCode(currentScope, flowContext, elseFlowInfo); } } Index: compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java,v retrieving revision 1.90 diff -u -r1.90 ConditionalExpression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 25 Sep 2008 23:10:29 -0000 1.90 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 24 Nov 2008 12:58:59 -0000 @@ -52,7 +52,10 @@ // process the if-true part FlowInfo trueFlowInfo = flowInfo.initsWhenTrue().copy(); if (isConditionOptimizedFalse) { - trueFlowInfo.setReachMode(FlowInfo.UNREACHABLE); + if ((trueFlowInfo.reachMode() & FlowInfo.UNREACHABLE) == 0) { + currentScope.problemReporter().fakeReachable(this.valueIfTrue); + trueFlowInfo.setReachMode(FlowInfo.UNREACHABLE); + } } this.trueInitStateIndex = currentScope.methodScope().recordInitializationStates(trueFlowInfo); trueFlowInfo = this.valueIfTrue.analyseCode(currentScope, flowContext, trueFlowInfo); @@ -60,7 +63,10 @@ // process the if-false part FlowInfo falseFlowInfo = flowInfo.initsWhenFalse().copy(); if (isConditionOptimizedTrue) { - falseFlowInfo.setReachMode(FlowInfo.UNREACHABLE); + if ((falseFlowInfo.reachMode() & FlowInfo.UNREACHABLE) == 0) { + currentScope.problemReporter().fakeReachable(this.valueIfFalse); + falseFlowInfo.setReachMode(FlowInfo.UNREACHABLE); + } } this.falseInitStateIndex = currentScope.methodScope().recordInitializationStates(falseFlowInfo); falseFlowInfo = this.valueIfFalse.analyseCode(currentScope, flowContext, falseFlowInfo); @@ -85,11 +91,18 @@ UnconditionalFlowInfo falseInfoWhenTrue = falseFlowInfo.initsWhenTrue().unconditionalCopy(); UnconditionalFlowInfo trueInfoWhenFalse = trueFlowInfo.initsWhenFalse().unconditionalInits(); UnconditionalFlowInfo falseInfoWhenFalse = falseFlowInfo.initsWhenFalse().unconditionalInits(); - if (isValueIfTrueOptimizedFalse) trueInfoWhenTrue.setReachMode(FlowInfo.UNREACHABLE); - if (isValueIfFalseOptimizedFalse) falseInfoWhenTrue.setReachMode(FlowInfo.UNREACHABLE); - if (isValueIfTrueOptimizedTrue) trueInfoWhenFalse.setReachMode(FlowInfo.UNREACHABLE); - if (isValueIfFalseOptimizedTrue) falseInfoWhenFalse.setReachMode(FlowInfo.UNREACHABLE); - + if (isValueIfTrueOptimizedFalse) { + trueInfoWhenTrue.setReachMode(FlowInfo.UNREACHABLE); + } + if (isValueIfFalseOptimizedFalse) { + falseInfoWhenTrue.setReachMode(FlowInfo.UNREACHABLE); + } + if (isValueIfTrueOptimizedTrue) { + trueInfoWhenFalse.setReachMode(FlowInfo.UNREACHABLE); + } + if (isValueIfFalseOptimizedTrue) { + falseInfoWhenFalse.setReachMode(FlowInfo.UNREACHABLE); + } mergedInfo = FlowInfo.conditional( trueInfoWhenTrue.mergedWith(falseInfoWhenTrue), Index: compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java,v retrieving revision 1.67 diff -u -r1.67 MethodDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java 12 Sep 2008 13:31:45 -0000 1.67 +++ compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java 24 Nov 2008 12:59:00 -0000 @@ -39,11 +39,7 @@ super(compilationResult); } - public void analyseCode( - ClassScope classScope, - InitializationFlowContext initializationContext, - FlowInfo flowInfo) { - + public void analyseCode(ClassScope classScope, InitializationFlowContext initializationContext, FlowInfo flowInfo) { // starting of the code analysis for methods if (this.ignoreFurtherInvestigation) return; @@ -83,13 +79,11 @@ } // propagate to statements if (this.statements != null) { - boolean didAlreadyComplain = false; + int complaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) == 0 ? Statement.NOT_COMPLAINED : Statement.COMPLAINED_FAKE_REACHABLE; for (int i = 0, count = this.statements.length; i < count; i++) { Statement stat = this.statements[i]; - if (!stat.complainIfUnreachable(flowInfo, this.scope, didAlreadyComplain)) { + if ((complaintLevel = stat.complainIfUnreachable(flowInfo, this.scope, complaintLevel)) < Statement.COMPLAINED_UNREACHABLE) { flowInfo = stat.analyseCode(this.scope, methodContext, flowInfo); - } else { - didAlreadyComplain = true; } } } Index: compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java,v retrieving revision 1.64 diff -u -r1.64 ForStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java 27 Jun 2008 16:03:56 -0000 1.64 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java 24 Nov 2008 12:58:59 -0000 @@ -58,13 +58,10 @@ } } - public FlowInfo analyseCode( - BlockScope currentScope, - FlowContext flowContext, - FlowInfo flowInfo) { - + public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { this.breakLabel = new BranchLabel(); this.continueLabel = new BranchLabel(); + int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED; // process the initializations if (this.initializations != null) { @@ -82,7 +79,7 @@ cst = this.condition == null ? null : this.condition.optimizedBooleanConstant(); boolean isConditionOptimizedTrue = cst == null || (cst != Constant.NotAConstant && cst.booleanValue() == true); boolean isConditionOptimizedFalse = cst != null && (cst != Constant.NotAConstant && cst.booleanValue() == false); - + // process the condition LoopingFlowContext condLoopContext = null; FlowInfo condInfo = flowInfo.nullInfoLessUnconditionalCopy(); @@ -137,9 +134,8 @@ actionInfo.setReachMode(FlowInfo.UNREACHABLE); } } - if (!this.action.complainIfUnreachable(actionInfo, this.scope, false)) { - actionInfo = this.action.analyseCode(this.scope, loopingContext, actionInfo). - unconditionalInits(); + if (this.action.complainIfUnreachable(actionInfo, this.scope, initialComplaintLevel) < Statement.COMPLAINED_UNREACHABLE) { + actionInfo = this.action.analyseCode(this.scope, loopingContext, actionInfo).unconditionalInits(); } // code generation can be optimized when no need to continue in the loop @@ -179,9 +175,13 @@ } exitBranch.addPotentialInitializationsFrom(actionInfo). addInitializationsFrom(condInfo.initsWhenFalse()); - } - else { + } else { exitBranch.addInitializationsFrom(condInfo.initsWhenFalse()); + if (this.increments != null) { + if (initialComplaintLevel == Statement.NOT_COMPLAINED) { + currentScope.problemReporter().fakeReachable(this.increments[0]); + } + } } // nulls checks if (condLoopContext != null) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java,v retrieving revision 1.61 diff -u -r1.61 WhileStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java 27 Jun 2008 16:03:54 -0000 1.61 +++ compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java 24 Nov 2008 12:59:00 -0000 @@ -36,13 +36,11 @@ this.sourceEnd = e; } - public FlowInfo analyseCode( - BlockScope currentScope, - FlowContext flowContext, - FlowInfo flowInfo) { + public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { this.breakLabel = new BranchLabel(); this.continueLabel = new BranchLabel(); + int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED; Constant cst = this.condition.constant; boolean isConditionTrue = cst != Constant.NotAConstant && cst.booleanValue() == true; @@ -52,10 +50,10 @@ boolean isConditionOptimizedTrue = cst != Constant.NotAConstant && cst.booleanValue() == true; boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false; - this.preCondInitStateIndex = - currentScope.methodScope().recordInitializationStates(flowInfo); + this.preCondInitStateIndex = currentScope.methodScope().recordInitializationStates(flowInfo); LoopingFlowContext condLoopContext; FlowInfo condInfo = flowInfo.nullInfoLessUnconditionalCopy(); + // we need to collect the contribution to nulls of the coming paths through the // loop, be they falling through normally or branched to break, continue labels // or catch blocks @@ -111,7 +109,7 @@ currentScope.methodScope().recordInitializationStates( condInfo.initsWhenTrue()); - if (!this.action.complainIfUnreachable(actionInfo, currentScope, false)) { + if (this.action.complainIfUnreachable(actionInfo, currentScope, initialComplaintLevel) < Statement.COMPLAINED_UNREACHABLE) { actionInfo = this.action.analyseCode(currentScope, loopingContext, actionInfo); } Index: compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java,v retrieving revision 1.40 diff -u -r1.40 AND_AND_Expression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java 27 Jun 2008 16:03:56 -0000 1.40 +++ compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java 24 Nov 2008 12:58:59 -0000 @@ -54,7 +54,10 @@ int previousMode = rightInfo.reachMode(); if (isLeftOptimizedFalse) { - rightInfo.setReachMode(FlowInfo.UNREACHABLE); + if ((rightInfo.reachMode() & FlowInfo.UNREACHABLE) == 0) { + currentScope.problemReporter().fakeReachable(this.right); + rightInfo.setReachMode(FlowInfo.UNREACHABLE); + } } rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo); FlowInfo mergedInfo = FlowInfo.conditional( Index: compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java,v retrieving revision 1.74 diff -u -r1.74 SwitchStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java 17 Sep 2008 09:08:38 -0000 1.74 +++ compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java 24 Nov 2008 12:59:00 -0000 @@ -44,11 +44,7 @@ int preSwitchInitStateIndex = -1; int mergedInitStateIndex = -1; - public FlowInfo analyseCode( - BlockScope currentScope, - FlowContext flowContext, - FlowInfo flowInfo) { - + public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { try { flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo); SwitchFlowContext switchContext = @@ -58,11 +54,11 @@ // to the entry point) FlowInfo caseInits = FlowInfo.DEAD_END; // in case of statements before the first case - this.preSwitchInitStateIndex = - currentScope.methodScope().recordInitializationStates(flowInfo); + this.preSwitchInitStateIndex = currentScope.methodScope().recordInitializationStates(flowInfo); int caseIndex = 0; if (this.statements != null) { - boolean didAlreadyComplain = false; + int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED; + int complaintLevel = initialComplaintLevel; int fallThroughState = CASE; for (int i = 0, max = this.statements.length; i < max; i++) { Statement statement = this.statements[i]; @@ -74,7 +70,7 @@ this.scope.problemReporter().possibleFallThroughCase(this.scope.enclosingCase); } caseInits = caseInits.mergedWith(flowInfo.unconditionalInits()); - didAlreadyComplain = false; // reset complaint + complaintLevel = initialComplaintLevel; // reset complaint fallThroughState = CASE; } else if (statement == this.defaultCase) { // statement is the default case this.scope.enclosingCase = this.defaultCase; // record entering in a switch case block @@ -83,18 +79,16 @@ this.scope.problemReporter().possibleFallThroughCase(this.scope.enclosingCase); } caseInits = caseInits.mergedWith(flowInfo.unconditionalInits()); - didAlreadyComplain = false; // reset complaint + complaintLevel = initialComplaintLevel; // reset complaint fallThroughState = CASE; } else { fallThroughState = FALLTHROUGH; // reset below if needed } - if (!statement.complainIfUnreachable(caseInits, this.scope, didAlreadyComplain)) { + if ((complaintLevel = statement.complainIfUnreachable(caseInits, this.scope, complaintLevel)) < Statement.COMPLAINED_UNREACHABLE) { caseInits = statement.analyseCode(this.scope, switchContext, caseInits); if (caseInits == FlowInfo.DEAD_END) { fallThroughState = ESCAPING; } - } else { - didAlreadyComplain = true; } } } @@ -107,10 +101,8 @@ // if no default case, then record it may jump over the block directly to the end if (this.defaultCase == null) { // only retain the potential initializations - flowInfo.addPotentialInitializationsFrom( - caseInits.mergedWith(switchContext.initsOnBreak)); - this.mergedInitStateIndex = - currentScope.methodScope().recordInitializationStates(flowInfo); + flowInfo.addPotentialInitializationsFrom(caseInits.mergedWith(switchContext.initsOnBreak)); + this.mergedInitStateIndex = currentScope.methodScope().recordInitializationStates(flowInfo); return flowInfo; } Index: compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java,v retrieving revision 1.42 diff -u -r1.42 Statement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java 27 Jun 2008 16:03:56 -0000 1.42 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java 24 Nov 2008 12:59:00 -0000 @@ -17,128 +17,136 @@ public abstract class Statement extends ASTNode { - public abstract FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo); +public abstract FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo); - /** - * INTERNAL USE ONLY. - * This is used to redirect inter-statements jumps. - */ - public void branchChainTo(BranchLabel label) { - // do nothing by default - } - - // Report an error if necessary - public boolean complainIfUnreachable(FlowInfo flowInfo, BlockScope scope, boolean didAlreadyComplain) { + public static final int NOT_COMPLAINED = 0; + public static final int COMPLAINED_FAKE_REACHABLE = 1; + public static final int COMPLAINED_UNREACHABLE = 2; + +/** + * INTERNAL USE ONLY. + * This is used to redirect inter-statements jumps. + */ +public void branchChainTo(BranchLabel label) { + // do nothing by default +} - if ((flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0) { - this.bits &= ~ASTNode.IsReachable; - boolean reported = flowInfo == FlowInfo.DEAD_END; - if (!didAlreadyComplain && reported) { +// Report an error if necessary (if even more unreachable than previously reported +// complaintLevel = 0 if was reachable up until now, 1 if fake reachable (deadcode), 2 if fatal unreachable (error) +public int complainIfUnreachable(FlowInfo flowInfo, BlockScope scope, int previousComplaintLevel) { + if ((flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0) { + this.bits &= ~ASTNode.IsReachable; + if (flowInfo == FlowInfo.DEAD_END) { + if (previousComplaintLevel < COMPLAINED_UNREACHABLE) { scope.problemReporter().unreachableCode(this); } - return reported; // keep going for fake reachable + return COMPLAINED_UNREACHABLE; + } else { + if (previousComplaintLevel < COMPLAINED_FAKE_REACHABLE) { + scope.problemReporter().fakeReachable(this); + } + return COMPLAINED_FAKE_REACHABLE; } - return false; } + return previousComplaintLevel; +} - /** - * Generate invocation arguments, considering varargs methods - */ - public void generateArguments(MethodBinding binding, Expression[] arguments, BlockScope currentScope, CodeStream codeStream) { - - if (binding.isVarargs()) { - // 5 possibilities exist for a call to the vararg method foo(int i, int ... value) : - // foo(1), foo(1, null), foo(1, 2), foo(1, 2, 3, 4) & foo(1, new int[] {1, 2}) - TypeBinding[] params = binding.parameters; - int paramLength = params.length; - int varArgIndex = paramLength - 1; - for (int i = 0; i < varArgIndex; i++) { +/** + * Generate invocation arguments, considering varargs methods + */ +public void generateArguments(MethodBinding binding, Expression[] arguments, BlockScope currentScope, CodeStream codeStream) { + if (binding.isVarargs()) { + // 5 possibilities exist for a call to the vararg method foo(int i, int ... value) : + // foo(1), foo(1, null), foo(1, 2), foo(1, 2, 3, 4) & foo(1, new int[] {1, 2}) + TypeBinding[] params = binding.parameters; + int paramLength = params.length; + int varArgIndex = paramLength - 1; + for (int i = 0; i < varArgIndex; i++) { + arguments[i].generateCode(currentScope, codeStream, true); + } + + ArrayBinding varArgsType = (ArrayBinding) params[varArgIndex]; // parameterType has to be an array type + ArrayBinding codeGenVarArgsType = (ArrayBinding) binding.parameters[varArgIndex].erasure(); + int elementsTypeID = varArgsType.elementsType().id; + int argLength = arguments == null ? 0 : arguments.length; + + if (argLength > paramLength) { + // right number but not directly compatible or too many arguments - wrap extra into array + // called with (argLength - lastIndex) elements : foo(1, 2) or foo(1, 2, 3, 4) + // need to gen elements into an array, then gen each remaining element into created array + codeStream.generateInlinedValue(argLength - varArgIndex); + codeStream.newArray(codeGenVarArgsType); // create a mono-dimensional array + for (int i = varArgIndex; i < argLength; i++) { + codeStream.dup(); + codeStream.generateInlinedValue(i - varArgIndex); arguments[i].generateCode(currentScope, codeStream, true); + codeStream.arrayAtPut(elementsTypeID, false); } - - ArrayBinding varArgsType = (ArrayBinding) params[varArgIndex]; // parameterType has to be an array type - ArrayBinding codeGenVarArgsType = (ArrayBinding) binding.parameters[varArgIndex].erasure(); - int elementsTypeID = varArgsType.elementsType().id; - int argLength = arguments == null ? 0 : arguments.length; - - if (argLength > paramLength) { + } else if (argLength == paramLength) { + // right number of arguments - could be inexact - pass argument as is + TypeBinding lastType = arguments[varArgIndex].resolvedType; + if (lastType == TypeBinding.NULL + || (varArgsType.dimensions() == lastType.dimensions() + && lastType.isCompatibleWith(varArgsType))) { + // foo(1, new int[]{2, 3}) or foo(1, null) --> last arg is passed as-is + arguments[varArgIndex].generateCode(currentScope, codeStream, true); + } else { // right number but not directly compatible or too many arguments - wrap extra into array - // called with (argLength - lastIndex) elements : foo(1, 2) or foo(1, 2, 3, 4) // need to gen elements into an array, then gen each remaining element into created array - codeStream.generateInlinedValue(argLength - varArgIndex); + codeStream.generateInlinedValue(1); codeStream.newArray(codeGenVarArgsType); // create a mono-dimensional array - for (int i = varArgIndex; i < argLength; i++) { - codeStream.dup(); - codeStream.generateInlinedValue(i - varArgIndex); - arguments[i].generateCode(currentScope, codeStream, true); - codeStream.arrayAtPut(elementsTypeID, false); - } - } else if (argLength == paramLength) { - // right number of arguments - could be inexact - pass argument as is - TypeBinding lastType = arguments[varArgIndex].resolvedType; - if (lastType == TypeBinding.NULL - || (varArgsType.dimensions() == lastType.dimensions() - && lastType.isCompatibleWith(varArgsType))) { - // foo(1, new int[]{2, 3}) or foo(1, null) --> last arg is passed as-is - arguments[varArgIndex].generateCode(currentScope, codeStream, true); - } else { - // right number but not directly compatible or too many arguments - wrap extra into array - // need to gen elements into an array, then gen each remaining element into created array - codeStream.generateInlinedValue(1); - codeStream.newArray(codeGenVarArgsType); // create a mono-dimensional array - codeStream.dup(); - codeStream.generateInlinedValue(0); - arguments[varArgIndex].generateCode(currentScope, codeStream, true); - codeStream.arrayAtPut(elementsTypeID, false); - } - } else { // not enough arguments - pass extra empty array - // scenario: foo(1) --> foo(1, new int[0]) - // generate code for an empty array of parameterType + codeStream.dup(); codeStream.generateInlinedValue(0); - codeStream.newArray(codeGenVarArgsType); // create a mono-dimensional array + arguments[varArgIndex].generateCode(currentScope, codeStream, true); + codeStream.arrayAtPut(elementsTypeID, false); } - } else if (arguments != null) { // standard generation for method arguments - for (int i = 0, max = arguments.length; i < max; i++) - arguments[i].generateCode(currentScope, codeStream, true); + } else { // not enough arguments - pass extra empty array + // scenario: foo(1) --> foo(1, new int[0]) + // generate code for an empty array of parameterType + codeStream.generateInlinedValue(0); + codeStream.newArray(codeGenVarArgsType); // create a mono-dimensional array } + } else if (arguments != null) { // standard generation for method arguments + for (int i = 0, max = arguments.length; i < max; i++) + arguments[i].generateCode(currentScope, codeStream, true); } +} - public abstract void generateCode(BlockScope currentScope, CodeStream codeStream); - - public boolean isEmptyBlock() { - return false; - } +public abstract void generateCode(BlockScope currentScope, CodeStream codeStream); - public boolean isValidJavaStatement() { - //the use of this method should be avoid in most cases - //and is here mostly for documentation purpose..... - //while the parser is responsable for creating - //welled formed expression statement, which results - //in the fact that java-non-semantic-expression-used-as-statement - //should not be parsable...thus not being built. - //It sounds like the java grammar as help the compiler job in removing - //-by construction- some statement that would have no effect.... - //(for example all expression that may do side-effects are valid statement - // -this is an appromative idea.....-) +public boolean isEmptyBlock() { + return false; +} - return true; - } +public boolean isValidJavaStatement() { + //the use of this method should be avoid in most cases + //and is here mostly for documentation purpose..... + //while the parser is responsable for creating + //welled formed expression statement, which results + //in the fact that java-non-semantic-expression-used-as-statement + //should not be parsable...thus not being built. + //It sounds like the java grammar as help the compiler job in removing + //-by construction- some statement that would have no effect.... + //(for example all expression that may do side-effects are valid statement + // -this is an appromative idea.....-) - public StringBuffer print(int indent, StringBuffer output) { - return printStatement(indent, output); - } - public abstract StringBuffer printStatement(int indent, StringBuffer output); + return true; +} - public abstract void resolve(BlockScope scope); +public StringBuffer print(int indent, StringBuffer output) { + return printStatement(indent, output); +} - /** - * Returns case constant associated to this statement (NotAConstant if none) - */ - public Constant resolveCase(BlockScope scope, TypeBinding testType, SwitchStatement switchStatement) { - // statement within a switch that are not case are treated as normal statement.... +public abstract StringBuffer printStatement(int indent, StringBuffer output); - resolve(scope); - return Constant.NotAConstant; - } +public abstract void resolve(BlockScope scope); +/** + * Returns case constant associated to this statement (NotAConstant if none) + */ +public Constant resolveCase(BlockScope scope, TypeBinding testType, SwitchStatement switchStatement) { + // statement within a switch that are not case are treated as normal statement.... + resolve(scope); + return Constant.NotAConstant; +} } Index: compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java,v retrieving revision 1.53 diff -u -r1.53 ForeachStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java 19 Sep 2008 19:45:19 -0000 1.53 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java 24 Nov 2008 12:58:59 -0000 @@ -72,17 +72,15 @@ this.kind = -1; } - public FlowInfo analyseCode( - BlockScope currentScope, - FlowContext flowContext, - FlowInfo flowInfo) { + public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { // initialize break and continue labels this.breakLabel = new BranchLabel(); this.continueLabel = new BranchLabel(); + int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED; // process the element variable and collection this.collection.checkNPE(currentScope, flowContext, flowInfo); - flowInfo = this.elementVariable.analyseCode(this.scope, flowContext, flowInfo); + flowInfo = this.elementVariable.analyseCode(this.scope, flowContext, flowInfo); FlowInfo condInfo = this.collection.analyseCode(this.scope, flowContext, flowInfo.copy()); // element variable will be assigned when iterating @@ -101,10 +99,8 @@ if (!(this.action == null || (this.action.isEmptyBlock() && currentScope.compilerOptions().complianceLevel <= ClassFileConstants.JDK1_3))) { - if (!this.action.complainIfUnreachable(actionInfo, this.scope, false)) { - actionInfo = this.action. - analyseCode(this.scope, loopingContext, actionInfo). - unconditionalCopy(); + if (this.action.complainIfUnreachable(actionInfo, this.scope, initialComplaintLevel) < Statement.COMPLAINED_UNREACHABLE) { + actionInfo = this.action.analyseCode(this.scope, loopingContext, actionInfo).unconditionalCopy(); } // code generation can be optimized when no need to continue in the loop Index: compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java,v retrieving revision 1.39 diff -u -r1.39 OR_OR_Expression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java 27 Jun 2008 16:03:55 -0000 1.39 +++ compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java 24 Nov 2008 12:59:00 -0000 @@ -56,7 +56,10 @@ int previousMode = rightInfo.reachMode(); if (isLeftOptimizedTrue){ - rightInfo.setReachMode(FlowInfo.UNREACHABLE); + if ((rightInfo.reachMode() & FlowInfo.UNREACHABLE) == 0) { + currentScope.problemReporter().fakeReachable(this.right); + rightInfo.setReachMode(FlowInfo.UNREACHABLE); + } } rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo); FlowInfo mergedInfo = FlowInfo.conditional( Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v retrieving revision 1.383 diff -u -r1.383 ProblemReporter.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 21 Nov 2008 20:03:08 -0000 1.383 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 24 Nov 2008 12:59:02 -0000 @@ -42,10 +42,13 @@ CONSTRUCTOR_ACCESS = 0x8, METHOD_ACCESS = 0xC; +public ProblemReporter(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory) { + super(policy, options, problemFactory); +} + private static int getElaborationId (int leadProblemId, byte elaborationVariant) { return leadProblemId << 8 | elaborationVariant; // leadProblemId comes into the higher order bytes } - public static int getIrritant(int problemID) { switch(problemID){ @@ -326,6 +329,9 @@ case IProblem.ShouldImplementHashcode: return CompilerOptions.ShouldImplementHashcode; + + case IProblem.DeadCode: + return CompilerOptions.DeadCode; } return 0; } @@ -375,6 +381,7 @@ case CompilerOptions.ComparingIdentical : case CompilerOptions.MissingSynchronizedModifierInInheritedMethod : case CompilerOptions.ShouldImplementHashcode : + case CompilerOptions.DeadCode : return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM; case CompilerOptions.OverriddenPackageDefaultMethod : @@ -394,7 +401,7 @@ case CompilerOptions.UnhandledWarningToken : case CompilerOptions.UnusedWarningToken : case CompilerOptions.UnusedLabel : - case CompilerOptions.RedundantSuperinterface : + case CompilerOptions.RedundantSuperinterface : return CategorizedProblem.CAT_UNNECESSARY_CODE; case CompilerOptions.UsingDeprecatedAPI : @@ -442,9 +449,6 @@ } return CategorizedProblem.CAT_INTERNAL; } -public ProblemReporter(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory) { - super(policy, options, problemFactory); -} public void abortDueToInternalError(String errorMessage) { this.abortDueToInternalError(errorMessage, null); } @@ -1306,6 +1310,7 @@ nodeSourceStart(field, location), nodeSourceEnd(field, location)); } + public void deprecatedMethod(MethodBinding method, ASTNode location) { boolean isConstructor = method.isConstructor(); int severity = computeSeverity(isConstructor ? IProblem.UsingDeprecatedConstructor : IProblem.UsingDeprecatedMethod); @@ -1390,7 +1395,6 @@ statement.sourceStart, statement.sourceEnd); } - public void duplicateEnumSpecialMethod(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) { MethodBinding method = methodDecl.binding; this.handle( @@ -1406,6 +1410,7 @@ methodDecl.sourceStart, methodDecl.sourceEnd); } + public void duplicateFieldInType(SourceTypeBinding type, FieldDeclaration fieldDecl) { this.handle( IProblem.DuplicateField, @@ -1414,7 +1419,6 @@ fieldDecl.sourceStart, fieldDecl.sourceEnd); } - public void duplicateImport(ImportReference importRef) { String[] arguments = new String[] {CharOperation.toString(importRef.tokens)}; this.handle( @@ -1424,6 +1428,7 @@ importRef.sourceStart, importRef.sourceEnd); } + public void duplicateInheritedMethods(SourceTypeBinding type, MethodBinding inheritedMethod1, MethodBinding inheritedMethod2) { this.handle( IProblem.DuplicateParameterizedMethods, @@ -1458,7 +1463,6 @@ nodeSourceStart(local, location), nodeSourceEnd(local, location)); } - public void duplicateMethodInType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, boolean equalParameters) { MethodBinding method = methodDecl.binding; if (equalParameters) { @@ -1496,6 +1500,7 @@ methodDecl.sourceEnd); } } + public void duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) { /* to highlight modifiers use: this.handle( @@ -1696,6 +1701,21 @@ expression.sourceStart, expression.sourceEnd); } +public void fakeReachable(ASTNode location) { + int sourceStart = location.sourceStart; + int sourceEnd = location.sourceEnd; + if (location instanceof LocalDeclaration) { + LocalDeclaration declaration = (LocalDeclaration) location; + sourceStart = declaration.declarationSourceStart; + sourceEnd = declaration.declarationSourceEnd; + } + this.handle( + IProblem.DeadCode, + NoArgument, + NoArgument, + sourceStart, + sourceEnd); +} public void fieldHiding(FieldDeclaration fieldDecl, Binding hiddenVariable) { FieldBinding field = fieldDecl.binding; if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name) Index: compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties,v retrieving revision 1.244 diff -u -r1.244 messages.properties --- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 21 Nov 2008 20:03:08 -0000 1.244 +++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 24 Nov 2008 12:59:02 -0000 @@ -122,6 +122,7 @@ 146 = Default constructor cannot handle exception type {0} thrown by implicit super constructor. Must define an explicit constructor 147 = Unhandled exception type {0} thrown by implicit super constructor +149 = Dead code 150 = The type of the expression must be an array type but it resolved to {0} 151 = Must explicitly convert the char[] to a String 152 = String constant is exceeding the limit of 65535 bytes of UTF8 encoding Index: model/org/eclipse/jdt/core/JavaCore.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v retrieving revision 1.630 diff -u -r1.630 JavaCore.java --- model/org/eclipse/jdt/core/JavaCore.java 22 Oct 2008 08:27:57 -0000 1.630 +++ model/org/eclipse/jdt/core/JavaCore.java 24 Nov 2008 12:59:03 -0000 @@ -999,6 +999,20 @@ */ public static final String COMPILER_PB_MISSING_HASHCODE_METHOD = PLUGIN_ID + ".compiler.problem.missingHashCodeMethod"; //$NON-NLS-1$ /** + * Compiler option ID: Reporting Dead Code. + *

When enabled, the compiler will issue an error or a warning if some non fatal dead code is detected. For instance, if (false) foo(); + * is not reported as truly unreachable code by the Java Language Specification. If this diagnostic is enabled, then the invocation of foo() is + * going to be signaled as being dead code. + *

+ *
Option id:
"org.eclipse.jdt.core.compiler.problem.deadCode"
+ *
Possible values:
{ "error", "warning", "ignore" }
+ *
Default:
"ignore"
+ *
+ * @since 3.5 + * @category CompilerOptionID + */ + public static final String COMPILER_PB_DEAD_CODE = PLUGIN_ID + ".compiler.problem.deadCode"; //$NON-NLS-1$ + /** * Compiler option ID: Reporting Incomplete Enum Switch. *

When enabled, the compiler will issue an error or a warning whenever * an enum constant has no corresponding case label in an enum switch Index: batch/org/eclipse/jdt/internal/compiler/batch/Main.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java,v retrieving revision 1.336 diff -u -r1.336 Main.java --- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 20 Nov 2008 15:55:04 -0000 1.336 +++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 24 Nov 2008 12:58:58 -0000 @@ -3139,6 +3139,11 @@ CompilerOptions.OPTION_ReportDiscouragedReference, isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); return; + } else if (token.equals("deadCode")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportDeadCode, + isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); + return; } break; case 'e' : Index: compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java,v retrieving revision 1.209 diff -u -r1.209 CompilerOptions.java --- compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 10 Oct 2008 17:24:31 -0000 1.209 +++ compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 24 Nov 2008 12:59:01 -0000 @@ -123,6 +123,7 @@ public static final String OPTION_ReportComparingIdentical = "org.eclipse.jdt.core.compiler.problem.comparingIdentical"; //$NON-NLS-1$ public static final String OPTION_ReportMissingSynchronizedOnInheritedMethod = "org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$ public static final String OPTION_ReportMissingHashCodeMethod = "org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod"; //$NON-NLS-1$ + public static final String OPTION_ReportDeadCode = "org.eclipse.jdt.core.compiler.problem.deadCode"; //$NON-NLS-1$ // Backward compatibility public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$ @@ -225,7 +226,8 @@ public static final int MissingSynchronizedModifierInInheritedMethod= IrritantSet.GROUP1 | ASTNode.Bit29; // group 2 - public static final int ShouldImplementHashcode= IrritantSet.GROUP2 | ASTNode.Bit1; + public static final int ShouldImplementHashcode = IrritantSet.GROUP2 | ASTNode.Bit1; + public static final int DeadCode = IrritantSet.GROUP2 | ASTNode.Bit2; // Map: String optionKey --> Long irritant> private static Map OptionToIrritants; @@ -478,6 +480,8 @@ return OPTION_ReportMissingSynchronizedOnInheritedMethod; case ShouldImplementHashcode : return OPTION_ReportMissingHashCodeMethod; + case DeadCode : + return OPTION_ReportDeadCode; } return null; } @@ -580,6 +584,7 @@ OPTION_ReportAnnotationSuperInterface, OPTION_ReportAssertIdentifier, OPTION_ReportAutoboxing, + OPTION_ReportDeadCode, OPTION_ReportDeprecation, OPTION_ReportDiscouragedReference, OPTION_ReportEmptyStatement, @@ -893,6 +898,7 @@ optionsMap.put(OPTION_ReportComparingIdentical, getSeverityString(ComparingIdentical)); optionsMap.put(OPTION_ReportMissingSynchronizedOnInheritedMethod, getSeverityString(MissingSynchronizedModifierInInheritedMethod)); optionsMap.put(OPTION_ReportMissingHashCodeMethod, getSeverityString(ShouldImplementHashcode)); + optionsMap.put(OPTION_ReportDeadCode, getSeverityString(DeadCode)); return optionsMap; } @@ -1264,6 +1270,7 @@ if ((optionValue = optionsMap.get(OPTION_ReportComparingIdentical)) != null) updateSeverity(ComparingIdentical, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportMissingSynchronizedOnInheritedMethod)) != null) updateSeverity(MissingSynchronizedModifierInInheritedMethod, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportMissingHashCodeMethod)) != null) updateSeverity(ShouldImplementHashcode, optionValue); + if ((optionValue = optionsMap.get(OPTION_ReportDeadCode)) != null) updateSeverity(DeadCode, optionValue); // Javadoc options if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) { @@ -1461,6 +1468,7 @@ buf.append("\n\t- comparing identical expr: ").append(getSeverityString(ComparingIdentical)); //$NON-NLS-1$ buf.append("\n\t- missing synchronized on inherited method: ").append(getSeverityString(MissingSynchronizedModifierInInheritedMethod)); //$NON-NLS-1$ buf.append("\n\t- should implement hashCode() method: ").append(getSeverityString(ShouldImplementHashcode)); //$NON-NLS-1$ + buf.append("\n\t- dead code: ").append(getSeverityString(DeadCode)); //$NON-NLS-1$ return buf.toString(); } Index: compiler/org/eclipse/jdt/core/compiler/IProblem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java,v retrieving revision 1.210 diff -u -r1.210 IProblem.java --- compiler/org/eclipse/jdt/core/compiler/IProblem.java 21 Nov 2008 20:03:08 -0000 1.210 +++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 24 Nov 2008 12:58:59 -0000 @@ -426,6 +426,7 @@ int UnhandledExceptionInImplicitConstructorCall = TypeRelated + 147; // expressions + int DeadCode = Internal + 149; int ArrayReferenceRequired = Internal + 150; int NoImplicitStringConversionForCharArrayExpression = Internal + 151; // constant expressions #P org.eclipse.jdt.core.tests Index: Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java =================================================================== RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java,v retrieving revision 1.119 diff -u -r1.119 InitializationTest.java --- Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java 18 Nov 2008 20:22:39 -0000 1.119 +++ Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java 24 Nov 2008 12:59:07 -0000 @@ -78,13 +78,22 @@ " } \n"+ "} \n", }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " throw new InstantiationException(); \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unhandled exception type InstantiationException\n" + - "----------\n" - ); + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " throw new InstantiationException(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " throw new InstantiationException(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " throw new InstantiationException(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type InstantiationException\n" + + "----------\n"); } /** * 1FX0DEX: LFCOM:WINNT - NullPointerException compiling final local @@ -629,18 +638,23 @@ " } \n"+ "} \n" }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " } else { \n" + - " return true; \n" + - " } \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " System.out.println(\"unreachable\"); \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " for (int k = 1;;k++) { \n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " } else { \n" + + " return true; \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + "----------\n" ); } @@ -1616,13 +1630,23 @@ " }\n"+ "}\n" }, - "----------\n" + - "1. ERROR in dasg00702m5.java (at line 8)\n" + - " t = b2;\n" + - " ^^\n" + - "The local variable b2 may not have been initialized\n" + - "----------\n" - ); + "----------\n" + + "1. WARNING in dasg00702m5.java (at line 6)\n" + + " if ((t || (b2 = false)) && (true && (true && (true && (false && (b2 = false)))))) {\n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in dasg00702m5.java (at line 6)\n" + + " if ((t || (b2 = false)) && (true && (true && (true && (false && (b2 = false)))))) {\n" + + " } else {\n" + + " ^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in dasg00702m5.java (at line 8)\n" + + " t = b2;\n" + + " ^^\n" + + "The local variable b2 may not have been initialized\n" + + "----------\n"); } /* @@ -1821,26 +1845,62 @@ * jck1.3a - dasg00209 */ public void test057() { + if (this.complianceLevel < ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "dasg00209.java", + "public class dasg00209 { \n"+ + " final boolean b; \n"+ + " { \n"+ + " if (false && (b = false)); \n"+ + " } \n"+ + " dasg00209() { \n"+ + " if (true && (b = false)); \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. WARNING in dasg00209.java (at line 4)\n" + + " if (false && (b = false)); \n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in dasg00209.java (at line 7)\n" + + " if (true && (b = false)); \n" + + " ^\n" + + "The final field b may already have been assigned\n" + + "----------\n"); + return; + } this.runNegativeTest( - new String[] { - "dasg00209.java", - "public class dasg00209 { \n"+ - " final boolean b; \n"+ - " { \n"+ - " if (false && (b = false)); \n"+ - " } \n"+ - " dasg00209() { \n"+ - " if (true && (b = false)); \n"+ - " } \n"+ - "} \n" - }, - "----------\n" + - "1. ERROR in dasg00209.java (at line 7)\n" + - " if (true && (b = false)); \n" + - " ^\n" + - "The final field b may already have been assigned\n" + - "----------\n" - ); + new String[] { + "dasg00209.java", + "public class dasg00209 { \n"+ + " final boolean b; \n"+ + " { \n"+ + " if (false && (b = false)); \n"+ + " } \n"+ + " dasg00209() { \n"+ + " if (true && (b = false)); \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. WARNING in dasg00209.java (at line 4)\n" + + " if (false && (b = false)); \n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in dasg00209.java (at line 4)\n" + + " if (false && (b = false)); \n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in dasg00209.java (at line 7)\n" + + " if (true && (b = false)); \n" + + " ^\n" + + "The final field b may already have been assigned\n" + + "----------\n"); } /** @@ -2098,13 +2158,17 @@ " } \n"+ "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " if (true && (b = false)); \n" + - " ^\n" + - "The final field b may already have been assigned\n" + - "----------\n" - ); + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " boolean ignore = false && (b = false) ? true : true; \n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " if (true && (b = false)); \n" + + " ^\n" + + "The final field b may already have been assigned\n" + + "----------\n"); } public void test066() { this.runNegativeTest( @@ -2117,16 +2181,21 @@ " } \n"+ "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " boolean ignore = (false && (b = false) ? (b = true) : (b = false)); \n" + - " ^\n" + - "The final field b may already have been assigned\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + - " boolean ignore = (false && (b = false) ? (b = true) : (b = false)); \n" + - " ^\n" + - "The final field b may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " boolean ignore = (false && (b = false) ? (b = true) : (b = false)); \n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " boolean ignore = (false && (b = false) ? (b = true) : (b = false)); \n" + + " ^\n" + + "The final field b may already have been assigned\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " boolean ignore = (false && (b = false) ? (b = true) : (b = false)); \n" + + " ^\n" + + "The final field b may already have been assigned\n" + "----------\n"); } public void test067() { @@ -2142,16 +2211,28 @@ " } \n"+ "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 1)\n" + - " public class X { \n" + - " ^\n" + - "The blank final field b may not have been initialized\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " b = true; \n" + - " ^\n" + - "The final field b may already have been assigned\n" + + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X { \n" + + " ^\n" + + "The blank final field b may not have been initialized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (false && (b = false)) { \n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " if (false && (b = false)) { \n" + + " b = true; \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " b = true; \n" + + " ^\n" + + "The final field b may already have been assigned\n" + "----------\n"); } public void test067a() { @@ -2210,11 +2291,16 @@ " } \n" + "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " X(){ \n" + - " ^^^\n" + - "The blank final field blank may not have been initialized\n" + + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X(){ \n" + + " ^^^\n" + + "The blank final field blank may not have been initialized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " blank = 1; \n" + + " ^^^^^^^^^\n" + + "Dead code\n" + "----------\n"); } @@ -2474,16 +2560,29 @@ " } \n" + "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " blank = 0; \n" + - " ^^^^^\n" + - "The final field blank may already have been assigned\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " blank = 1; \n" + - " ^^^^^\n" + - "The final field blank may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false && (blank = 0)>0) { \n" + + " ^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (false && (blank = 0)>0) { \n" + + " blank = 0; \n" + + " return; \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " blank = 0; \n" + + " ^^^^^\n" + + "The final field blank may already have been assigned\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " blank = 1; \n" + + " ^^^^^\n" + + "The final field blank may already have been assigned\n" + "----------\n"); } @@ -2510,11 +2609,19 @@ " }\n"+ "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " X(int i){ \n" + - " ^^^^^^^^\n" + - "The blank final field blank may not have been initialized\n" + + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X(int i){ \n" + + " ^^^^^^^^\n" + + "The blank final field blank may not have been initialized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " if (false){ \n" + + " blank = 0; \n" + + " return; \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + "----------\n"); } @@ -2540,11 +2647,19 @@ " }\n"+ "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " X(int i){ \n" + - " ^^^^^^^^\n" + - "The blank final field blank may not have been initialized\n" + + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X(int i){ \n" + + " ^^^^^^^^\n" + + "The blank final field blank may not have been initialized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " if (false){ \n" + + " blank = 0; \n" + + " return; \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + "----------\n"); } @@ -2567,21 +2682,26 @@ "class E extends Exception { \n" + "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " System.out.println(blank); \n" + - " ^^^^^\n" + - "The blank final field blank may not have been initialized\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + - " blank = 1; \n" + - " ^^^^^\n" + - "The final field blank may already have been assigned\n" + - "----------\n" + - "3. WARNING in X.java (at line 13)\n" + - " class E extends Exception { \n" + - " ^\n" + - "The serializable class E does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " if (false) throw new E(); \n" + + " ^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " System.out.println(blank); \n" + + " ^^^^^\n" + + "The blank final field blank may not have been initialized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " blank = 1; \n" + + " ^^^^^\n" + + "The final field blank may already have been assigned\n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " class E extends Exception { \n" + + " ^\n" + + "The serializable class E does not declare a static final serialVersionUID field of type long\n" + "----------\n"); } // see also AssignmentTest#55 @@ -2611,16 +2731,32 @@ "class E extends Exception { \n" + "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 14)\n" + - " blank = 3; \n" + - " ^^^^^\n" + - "The final field blank may already have been assigned\n" + - "----------\n" + - "2. WARNING in X.java (at line 20)\n" + - " class E extends Exception { \n" + - " ^\n" + - "The serializable class E does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " if (false) { \n" + + " blank = 0; \n" + + " throw new E(); \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " if (false) { \n" + + " blank = 1; \n" + + " throw new E(); \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " blank = 3; \n" + + " ^^^^^\n" + + "The final field blank may already have been assigned\n" + + "----------\n" + + "4. WARNING in X.java (at line 20)\n" + + " class E extends Exception { \n" + + " ^\n" + + "The serializable class E does not declare a static final serialVersionUID field of type long\n" + "----------\n", JavacTestOptions.EclipseJustification.EclipseBug235543); } @@ -2652,16 +2788,32 @@ "class E extends Exception { \n" + "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 14)\n" + - " blank = 3; \n" + - " ^^^^^\n" + - "The final field blank may already have been assigned\n" + - "----------\n" + - "2. WARNING in X.java (at line 20)\n" + - " class E extends Exception { \n" + - " ^\n" + - "The serializable class E does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " if (false) { \n" + + " //blank = 0; \n" + + " throw new E(); \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " if (false) { \n" + + " blank = 1; \n" + + " throw new E(); \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " blank = 3; \n" + + " ^^^^^\n" + + "The final field blank may already have been assigned\n" + + "----------\n" + + "4. WARNING in X.java (at line 20)\n" + + " class E extends Exception { \n" + + " ^\n" + + "The serializable class E does not declare a static final serialVersionUID field of type long\n" + "----------\n", JavacTestOptions.EclipseJustification.EclipseBug235543); } @@ -2681,11 +2833,19 @@ " } \n" + "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " blank = 1; \n" + - " ^^^^^\n" + - "The final field blank may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " while (i > 0 && false) { \n" + + " blank = 0; \n" + + " break; \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " blank = 1; \n" + + " ^^^^^\n" + + "The final field blank may already have been assigned\n" + "----------\n"); } @@ -2726,11 +2886,20 @@ " } \n" + "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " blank = 2; \n" + - " ^^^^^\n" + - "The final local variable blank may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " else { \n" + + " System.out.println(blank); \n" + + " blank = 1; \n" + + " blank = 2; \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " blank = 2; \n" + + " ^^^^^\n" + + "The final local variable blank may already have been assigned\n" + "----------\n"); } @@ -2750,11 +2919,20 @@ " } \n" + "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " blank = 2; \n" + - " ^^^^^\n" + - "The final local variable blank may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " else { \n" + + " System.out.println(blank); \n" + + " blank = 1; \n" + + " blank = 2; \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " blank = 2; \n" + + " ^^^^^\n" + + "The final local variable blank may already have been assigned\n" + "----------\n"); } @@ -2799,26 +2977,31 @@ " }\n"+ "} \n" }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " final int i = i = 0; \n" + - " ^^^^^^^^^\n" + - "The assignment to variable i has no effect\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " final int i = i = 0; \n" + - " ^\n" + - "The final local variable i cannot be assigned. It must be blank and not using a compound assignment\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + - " ((blank2 = 0)>0 || true) \n" + - " ^^^^^^\n" + - "The final local variable blank2 cannot be assigned. It must be blank and not using a compound assignment\n" + - "----------\n" + - "4. ERROR in X.java (at line 7)\n" + - " : (blank2 = 2); \n" + - " ^^^^^^\n" + - "The final local variable blank2 cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " final int i = i = 0; \n" + + " ^^^^^^^^^\n" + + "The assignment to variable i has no effect\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " final int i = i = 0; \n" + + " ^\n" + + "The final local variable i cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " ((blank2 = 0)>0 || true) \n" + + " ^^^^^^\n" + + "The final local variable blank2 cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " : (blank2 = 2); \n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " : (blank2 = 2); \n" + + " ^^^^^^\n" + + "The final local variable blank2 cannot be assigned. It must be blank and not using a compound assignment\n" + "----------\n"); } @@ -2840,48 +3023,119 @@ " } \n" + "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " else blank = 1; \n" + - " ^^^^^\n" + - "The final local variable blank may already have been assigned\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " : (blank2 = 2); \n" + - " ^^^^^^\n" + - "The final local variable blank2 may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (true || (blank = 0)>0); \n" + + " ^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " else blank = 1; \n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " else blank = 1; \n" + + " ^^^^^\n" + + "The final local variable blank may already have been assigned\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " (true || (blank2 = 0)>0) \n" + + " ^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " : (blank2 = 2); \n" + + " ^^^^^^\n" + + "The final local variable blank2 may already have been assigned\n" + "----------\n"); } public void test095() { + if (this.complianceLevel < ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " X(){ \n"+ + " final int blank; \n" + + " if (false && (blank = 0)>0); \n" + + " else blank = 1; \n" + + " \n" + + " final int blank2; \n" + + " int i = \n" + + " (false && (blank2 = 0)>0) \n" + + " ? 1 \n" + + " : (blank2 = 2); \n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false && (blank = 0)>0); \n" + + " ^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " else blank = 1; \n" + + " ^^^^^\n" + + "The final local variable blank may already have been assigned\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " (false && (blank2 = 0)>0) \n" + + " ^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " : (blank2 = 2); \n" + + " ^^^^^^\n" + + "The final local variable blank2 may already have been assigned\n" + + "----------\n"); + return; + } this.runNegativeTest( - new String[] { - "X.java", - "public class X { \n"+ - " X(){ \n"+ - " final int blank; \n" + - " if (false && (blank = 0)>0); \n" + - " else blank = 1; \n" + - " \n" + - " final int blank2; \n" + - " int i = \n" + - " (false && (blank2 = 0)>0) \n" + - " ? 1 \n" + - " : (blank2 = 2); \n" + - " } \n" + - "} \n" - }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " else blank = 1; \n" + - " ^^^^^\n" + - "The final local variable blank may already have been assigned\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " : (blank2 = 2); \n" + - " ^^^^^^\n" + - "The final local variable blank2 may already have been assigned\n" + - "----------\n"); + new String[] { + "X.java", + "public class X { \n"+ + " X(){ \n"+ + " final int blank; \n" + + " if (false && (blank = 0)>0); \n" + + " else blank = 1; \n" + + " \n" + + " final int blank2; \n" + + " int i = \n" + + " (false && (blank2 = 0)>0) \n" + + " ? 1 \n" + + " : (blank2 = 2); \n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false && (blank = 0)>0); \n" + + " ^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (false && (blank = 0)>0); \n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " else blank = 1; \n" + + " ^^^^^\n" + + "The final local variable blank may already have been assigned\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " (false && (blank2 = 0)>0) \n" + + " ^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " : (blank2 = 2); \n" + + " ^^^^^^\n" + + "The final local variable blank2 may already have been assigned\n" + + "----------\n"); } public void test096() { @@ -2895,11 +3149,16 @@ " } \n"+ "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " int foo() { \n" + - " ^^^^^\n" + - "This method must return a result of type int\n" + + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int foo() { \n" + + " ^^^^^\n" + + "This method must return a result of type int\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " System.out.println(); \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + "----------\n"); } // test097 replaced by AssignmentTest#56 @@ -2924,16 +3183,21 @@ " }\n"+ "} \n" }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " blank = 0; \n" + - " ^^^^^^^^^\n" + - "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + - " blank = 1; \n" + - " ^^^^^\n" + - "The final field blank may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " blank = 0; \n" + + " ^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " blank = 0; \n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " blank = 1; \n" + + " ^^^^^\n" + + "The final field blank may already have been assigned\n" + "----------\n"); } @@ -2954,16 +3218,21 @@ " } \n" + "} \n" }, - "----------\n" + - "1. WARNING in X.java (at line 8)\n" + - " blank = 0; \n" + - " ^^^^^^^^^\n" + - "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + - " blank = 1; \n" + - " ^^^^^\n" + - "The final field blank may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " blank = 0; \n" + + " ^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " blank = 0; \n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " blank = 1; \n" + + " ^^^^^\n" + + "The final field blank may already have been assigned\n" + "----------\n"); } @@ -3103,11 +3372,21 @@ " } \n" + "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " blank = 2; \n" + - " ^^^^^\n" + - "The final local variable blank may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) blank = 1; \n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " if (true) ; else blank = 1; \n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " blank = 2; \n" + + " ^^^^^\n" + + "The final local variable blank may already have been assigned\n" + "----------\n"); } @@ -3124,11 +3403,21 @@ " } \n" + "} \n" }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " blank = 2; \n" + - " ^^^^^\n" + - "The final local variable blank may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " int a = false ? (blank = 1) : 0; \n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " int b = true ? 0 : (blank = 1); \n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " blank = 2; \n" + + " ^^^^^\n" + + "The final local variable blank may already have been assigned\n" + "----------\n"); } @@ -3237,16 +3526,25 @@ " }\n" + "}\n", }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " i = 1;\n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " i = 2;\n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " if (true) return; // if this one instead, will diagnose duplicate assignments\n" + + " i = 0;\n" + + " i = 1;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " i = 2;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + "----------\n" ); } @@ -3267,11 +3565,20 @@ " }\n" + "}\n", }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " i = 0;\n" + - " ^^^^^^\n" + - "Unreachable code\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " return;\n" + + " i = 0;\n" + + " i = 1;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " i = 0;\n" + + " ^^^^^^\n" + + "Unreachable code\n" + "----------\n"); } @@ -4361,11 +4668,26 @@ " }\n" + "}\n" }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " if (false) throw new Exception(); // uncaught\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unhandled exception type Exception\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (false) {\n" + + " try {\n" + + " try {\n" + + " if (false) throw new Exception(); // uncaught\n" + + " System.out.println(); // still fake reachable \n" + + " } finally {\n" + + " System.out.println();\n" + + " }\n" + + " } catch (InterruptedException e) {\n" + + " }\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " if (false) throw new Exception(); // uncaught\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Exception\n" + "----------\n"); } public void test163() { @@ -4645,11 +4967,19 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " x *= 1;\n" + - " ^\n" + - "The final local variable x may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " x = 1;\n" + + " x *= 1;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " x *= 1;\n" + + " ^\n" + + "The final local variable x may already have been assigned\n" + "----------\n"); } @@ -4687,11 +5017,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " System.out.println(\"unreachable\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " blank = 1;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " System.out.println(\"unreachable\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + "----------\n"); } Index: Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/FromJacksTest.java =================================================================== RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/FromJacksTest.java,v retrieving revision 1.27 diff -u -r1.27 FromJacksTest.java --- Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/FromJacksTest.java 27 Jun 2008 16:02:01 -0000 1.27 +++ Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/FromJacksTest.java 24 Nov 2008 12:59:06 -0000 @@ -15,6 +15,7 @@ import junit.framework.Test; import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; public class FromJacksTest extends AbstractRegressionTest { @@ -431,11 +432,16 @@ "\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " int j = i = 1;\n" + - " ^\n" + - "The final field i may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " i = 1;\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " int j = i = 1;\n" + + " ^\n" + + "The final field i may already have been assigned\n" + "----------\n"); } @@ -458,11 +464,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " i = 1;\n" + - " ^\n" + - "The final field i may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " i = 1;\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " i = 1;\n" + + " ^\n" + + "The final field i may already have been assigned\n" + "----------\n"); } @@ -485,11 +496,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " i = 1;\n" + - " ^\n" + - "The final field i may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " i = 1;\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " i = 1;\n" + + " ^\n" + + "The final field i may already have been assigned\n" + "----------\n"); } @@ -574,11 +590,16 @@ "}\n" + "" }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " ia[false ? x = 0 : 0] += x = 0;\n" + - " ^\n" + - "The final local variable x may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " ia[false ? x = 0 : 0] += x = 0;\n" + + " ^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " ia[false ? x = 0 : 0] += x = 0;\n" + + " ^\n" + + "The final local variable x may already have been assigned\n" + "----------\n"); } @@ -599,11 +620,16 @@ "}\n" + "" }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " (false ? x = new X() : null).s += x = null;\n" + - " ^\n" + - "The final field x may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " (false ? x = new X() : null).s += x = null;\n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " (false ? x = new X() : null).s += x = null;\n" + + " ^\n" + + "The final field x may already have been assigned\n" + "----------\n"); } @@ -793,11 +819,16 @@ "}\n" + "" }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (true ? true : (x = true));\n" + - " ^\n" + - "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (true ? true : (x = true));\n" + + " ^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " if (true ? true : (x = true));\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + "----------\n"); } @@ -806,22 +837,56 @@ * finals; initialized fields cannot be assigned */ public void test035() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " final boolean x = true; // constant\n" + - " if (false ? x = true : false);\n" + - " }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (false ? x = true : false);\n" + - " ^\n" + - "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + - "----------\n"); + if (this.complianceLevel < ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final boolean x = true; // constant\n" + + " if (false ? x = true : false);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false ? x = true : false);\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " if (false ? x = true : false);\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final boolean x = true; // constant\n" + + " if (false ? x = true : false);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false ? x = true : false);\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " if (false ? x = true : false);\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " if (false ? x = true : false);\n" + + " ^\n" + + "Dead code\n" + + "----------\n"); } /** @@ -839,11 +904,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (true ? true : (x = true));\n" + - " ^\n" + - "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (true ? true : (x = true));\n" + + " ^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " if (true ? true : (x = true));\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + "----------\n"); } @@ -852,23 +922,58 @@ * finals; initialized fields cannot be assigned */ public void test037() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " final boolean x = Boolean.TRUE.booleanValue(); // non-constant\n" + - " if (false ? x = true : false);\n" + - " }\n" + - "}\n" + - "" - }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (false ? x = true : false);\n" + - " ^\n" + - "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + - "----------\n"); + if (this.complianceLevel < ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final boolean x = Boolean.TRUE.booleanValue(); // non-constant\n" + + " if (false ? x = true : false);\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false ? x = true : false);\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " if (false ? x = true : false);\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final boolean x = Boolean.TRUE.booleanValue(); // non-constant\n" + + " if (false ? x = true : false);\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false ? x = true : false);\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " if (false ? x = true : false);\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " if (false ? x = true : false);\n" + + " ^\n" + + "Dead code\n" + + "----------\n"); } @@ -877,33 +982,88 @@ * finals; initialized fields cannot be assigned */ public void test038() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " try {\n" + - " throw new Exception();\n" + - " } catch (final Exception x) {\n" + - " if (true ? true : ((x = null) == null));\n" + - " }\n" + - " final boolean x = Boolean.TRUE.booleanValue(); // non-constant\n" + - " if (false ? x = true : false);\n" + - " }\n" + - "}\n" + - "" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " if (true ? true : ((x = null) == null));\n" + - " ^\n" + - "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " if (false ? x = true : false);\n" + - " ^\n" + - "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + - "----------\n"); + if (this.complianceLevel < ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new Exception();\n" + + " } catch (final Exception x) {\n" + + " if (true ? true : ((x = null) == null));\n" + + " }\n" + + " final boolean x = Boolean.TRUE.booleanValue(); // non-constant\n" + + " if (false ? x = true : false);\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " if (true ? true : ((x = null) == null));\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " if (true ? true : ((x = null) == null));\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " if (false ? x = true : false);\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " if (false ? x = true : false);\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new Exception();\n" + + " } catch (final Exception x) {\n" + + " if (true ? true : ((x = null) == null));\n" + + " }\n" + + " final boolean x = Boolean.TRUE.booleanValue(); // non-constant\n" + + " if (false ? x = true : false);\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " if (true ? true : ((x = null) == null));\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " if (true ? true : ((x = null) == null));\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " if (false ? x = true : false);\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " if (false ? x = true : false);\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " if (false ? x = true : false);\n" + + " ^\n" + + "Dead code\n" + + "----------\n"); } /** @@ -911,25 +1071,62 @@ * finals; initialized fields cannot be assigned */ public void test039() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " try {\n" + - " throw new Exception();\n" + - " } catch (final Exception x) {\n" + - " if (false ? (x = null) == null : false);\n" + - " }\n" + - " }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " if (false ? (x = null) == null : false);\n" + - " ^\n" + - "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + - "----------\n"); + if (this.complianceLevel < ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new Exception();\n" + + " } catch (final Exception x) {\n" + + " if (false ? (x = null) == null : false);\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " if (false ? (x = null) == null : false);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " if (false ? (x = null) == null : false);\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new Exception();\n" + + " } catch (final Exception x) {\n" + + " if (false ? (x = null) == null : false);\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " if (false ? (x = null) == null : false);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " if (false ? (x = null) == null : false);\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " if (false ? (x = null) == null : false);\n" + + " ^\n" + + "Dead code\n" + + "----------\n"); } /** * 16.1.3-definite-assignment-pass-3 V is DA after a || b when @@ -1151,13 +1348,17 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " i = 1;\n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + - "----------\n" -); + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " i = 1;\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + + "----------\n"); } /** @@ -1180,11 +1381,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " i = 1;\n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " i = 1;\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + "----------\n"); } @@ -1354,11 +1560,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " i = 1;\n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " i = 1;\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + "----------\n"); } /** @@ -1498,11 +1709,18 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " val = 0;\n" + - " ^^^\n" + - "The final field val may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " if (false) {\n" + + " val = 1;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " val = 0;\n" + + " ^^^\n" + + "The final field val may already have been assigned\n" + "----------\n"); } /** @@ -1901,11 +2119,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " i = 1;\n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + "----------\n"); } /** @@ -1934,11 +2157,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " i = 1;\n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + "----------\n"); } /** @@ -1966,11 +2194,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " i = 1;\n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + "----------\n"); } /** @@ -1999,11 +2232,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 15)\n" + - " i = 2; // i multiply assigned \n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " i = 2; // i multiply assigned \n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + "----------\n"); } /** @@ -2030,11 +2268,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 13)\n" + - " i = 2; // i multiply assigned \n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " i = 2; // i multiply assigned \n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + "----------\n"); } @@ -2116,11 +2359,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " i = 1;\n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + "----------\n"); } @@ -2186,11 +2434,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " i = 1;\n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " i = 1;\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + "----------\n"); } Index: Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java =================================================================== RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java,v retrieving revision 1.319 diff -u -r1.319 NegativeTest.java --- Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java 21 Nov 2008 20:03:10 -0000 1.319 +++ Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java 24 Nov 2008 12:59:10 -0000 @@ -1126,26 +1126,30 @@ "}\n" + "}", }, - "----------\n" + - "1. ERROR in p\\A1.java (at line 10)\n" + - " message += System.out.println(3);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The operator += is undefined for the argument type(s) String, void\n" + - "----------\n" + - "2. ERROR in p\\A1.java (at line 15)\n" + - " message += System.out.println(3);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The operator += is undefined for the argument type(s) String, void\n" + - "----------\n" + - "3. WARNING in p\\A1.java (at line 29)\n" + - " } finally {\n" + - " i = 1;\n" + - " continue;\n" + - " }\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "finally block does not complete normally\n" + - "----------\n" - ); + "----------\n" + + "1. ERROR in p\\A1.java (at line 10)\n" + + " message += System.out.println(3);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The operator += is undefined for the argument type(s) String, void\n" + + "----------\n" + + "2. ERROR in p\\A1.java (at line 15)\n" + + " message += System.out.println(3);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The operator += is undefined for the argument type(s) String, void\n" + + "----------\n" + + "3. WARNING in p\\A1.java (at line 29)\n" + + " } finally {\n" + + " i = 1;\n" + + " continue;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "finally block does not complete normally\n" + + "----------\n" + + "4. WARNING in p\\A1.java (at line 39)\n" + + " System.out.println(\"Hello\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); } public void test003() { @@ -3382,14 +3386,14 @@ " } finally {\n" + " if (true)\n" + " return 2;\n" + - " };\n" + + " }\n" + " return 1;\n" + "} \n" + "int foo11() {\n" + " synchronized (this) {\n" + " if (true)\n" + " return 1;\n" + - " };\n" + + " }\n" + " return 2;\n" + "} \n" + "int foo12() {\n" + @@ -3418,7 +3422,7 @@ " i = 1;\n" + " if (true)\n" + " break;\n" + - " };\n" + + " }\n" + " return 1;\n" + "} \n" + "int foo17() {\n" + @@ -3492,48 +3496,73 @@ " }\n" + "}", }, - "----------\n" + - "1. WARNING in p\\BytecodeA.java (at line 74)\n" + - " L1 :; // good\n" + - " ^^\n" + - "The label L1 is never explicitly referenced\n" + - "----------\n" + - "2. ERROR in p\\BytecodeA.java (at line 83)\n" + - " continue L; // bad\n" + - " ^^^^^^^^^^^\n" + - "continue cannot be used outside of a loop\n" + - "----------\n" + - "3. ERROR in p\\BytecodeA.java (at line 91)\n" + - " continue L; // bad\n" + - " ^^^^^^^^^^^\n" + - "continue cannot be used outside of a loop\n" + - "----------\n" + - "4. WARNING in p\\BytecodeA.java (at line 93)\n" + - " } finally {\n" + - " return;\n" + - " }\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "finally block does not complete normally\n" + - "----------\n" + - "5. WARNING in p\\BytecodeA.java (at line 104)\n" + - " L : K : for (;;) {\n" + - " ^\n" + - "The label K is never explicitly referenced\n" + - "----------\n" + - "6. ERROR in p\\BytecodeA.java (at line 105)\n" + - " continue L; // good\n" + - " ^^^^^^^^^^^\n" + - "continue cannot be used outside of a loop\n" + - "----------\n" + - "7. ERROR in p\\BytecodeA.java (at line 115)\n" + - " x [1] = (x = new Object[5]); // bad\n" + - " ^\n" + - "The local variable x may not have been initialized\n" + - "----------\n" + - "8. ERROR in p\\BytecodeA.java (at line 119)\n" + - " } catch (java.io.IOException e) {\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable catch block for IOException. This exception is never thrown from the try statement body\n" + + "----------\n" + + "1. WARNING in p\\BytecodeA.java (at line 13)\n" + + " return 5;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in p\\BytecodeA.java (at line 26)\n" + + " return 1;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in p\\BytecodeA.java (at line 33)\n" + + " return 2;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. WARNING in p\\BytecodeA.java (at line 45)\n" + + " for (int i = 1; i < 10; i++)\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "5. WARNING in p\\BytecodeA.java (at line 51)\n" + + " for (int i = 1; i < 10; i++)\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in p\\BytecodeA.java (at line 74)\n" + + " L1 :; // good\n" + + " ^^\n" + + "The label L1 is never explicitly referenced\n" + + "----------\n" + + "7. ERROR in p\\BytecodeA.java (at line 83)\n" + + " continue L; // bad\n" + + " ^^^^^^^^^^^\n" + + "continue cannot be used outside of a loop\n" + + "----------\n" + + "8. ERROR in p\\BytecodeA.java (at line 91)\n" + + " continue L; // bad\n" + + " ^^^^^^^^^^^\n" + + "continue cannot be used outside of a loop\n" + + "----------\n" + + "9. WARNING in p\\BytecodeA.java (at line 93)\n" + + " } finally {\n" + + " return;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "finally block does not complete normally\n" + + "----------\n" + + "10. WARNING in p\\BytecodeA.java (at line 104)\n" + + " L : K : for (;;) {\n" + + " ^\n" + + "The label K is never explicitly referenced\n" + + "----------\n" + + "11. ERROR in p\\BytecodeA.java (at line 105)\n" + + " continue L; // good\n" + + " ^^^^^^^^^^^\n" + + "continue cannot be used outside of a loop\n" + + "----------\n" + + "12. ERROR in p\\BytecodeA.java (at line 115)\n" + + " x [1] = (x = new Object[5]); // bad\n" + + " ^\n" + + "The local variable x may not have been initialized\n" + + "----------\n" + + "13. ERROR in p\\BytecodeA.java (at line 119)\n" + + " } catch (java.io.IOException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable catch block for IOException. This exception is never thrown from the try statement body\n" + "----------\n"); } public void test086() { @@ -4161,59 +4190,148 @@ ); } public void test104() { + if (this.complianceLevel < ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "p/G.java", + "package p;\n" + + "class G {\n" + + " final int x;\n" + + " static class BMember {\n" + + " int bar(){ return foo(); }\n" + + " }\n" + + " G(B b, int i){\n" + + " this.x = i; \n" + + " } \n" + + " int foo(){ return 1;}\n" + + "}", + + "p/B.java", + "package p;\n" + + "class B{\n" + + " int f(){\n" + + " final int i;" + + " i = 1;\n" + + " if (false) i = 2;\n" + + " return i;\n" + + " }\n" + + " int g(){\n" + + " int i; \n" + + " if(true) i = 1;\n" + + " return i; \n" + + " }\n" + + " int h(){\n" + + " if(true) return 1;\n" + + " return 2;\n" + + " return 3;\n" + + " } \n" + + " int i(){\n" + + " if(false) ; else return 1;\n" + + " return 2;\n" + + " } \n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\G.java (at line 5)\n" + + " int bar(){ return foo(); }\n" + + " ^^^\n" + + "Cannot make a static reference to the non-static method foo() from the type G\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\B.java (at line 5)\n" + + " if (false) i = 2;\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in p\\B.java (at line 15)\n" + + " return 2;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in p\\B.java (at line 16)\n" + + " return 3;\n" + + " ^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "4. WARNING in p\\B.java (at line 20)\n" + + " return 2;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); + return; + } this.runNegativeTest( - new String[] { - "p/G.java", - "package p;\n" + - "class G {\n" + - " final int x;\n" + - " static class BMember {\n" + - " int bar(){ return foo(); }\n" + - " }\n" + - " G(B b, int i){\n" + - " this.x = i; \n" + - " } \n" + - " int foo(){ return 1;}\n" + - "}", - - "p/B.java", - "package p;\n" + - "class B{\n" + - " int f(){\n" + - " final int i;" + - " i = 1;\n" + - " if (false) i = 2;\n" + - " return i;\n" + - " }\n" + - " int g(){\n" + - " int i; \n" + - " if(true) i = 1;\n" + - " return i; \n" + - " }\n" + - " int h(){\n" + - " if(true) return 1;\n" + - " return 2;\n" + - " return 3;\n" + - " } \n" + - " int i(){\n" + - " if(false) ; else return 1;\n" + - " return 2;\n" + - " } \n" + - "}", - }, - "----------\n" + - "1. ERROR in p\\G.java (at line 5)\n" + - " int bar(){ return foo(); }\n" + - " ^^^\n" + - "Cannot make a static reference to the non-static method foo() from the type G\n" + - "----------\n" + - "----------\n" + - "1. ERROR in p\\B.java (at line 16)\n" + - " return 3;\n" + - " ^^^^^^^^^\n" + - "Unreachable code\n" + - "----------\n" - ); + new String[] { + "p/G.java", + "package p;\n" + + "class G {\n" + + " final int x;\n" + + " static class BMember {\n" + + " int bar(){ return foo(); }\n" + + " }\n" + + " G(B b, int i){\n" + + " this.x = i; \n" + + " } \n" + + " int foo(){ return 1;}\n" + + "}", + + "p/B.java", + "package p;\n" + + "class B{\n" + + " int f(){\n" + + " final int i;" + + " i = 1;\n" + + " if (false) i = 2;\n" + + " return i;\n" + + " }\n" + + " int g(){\n" + + " int i; \n" + + " if(true) i = 1;\n" + + " return i; \n" + + " }\n" + + " int h(){\n" + + " if(true) return 1;\n" + + " return 2;\n" + + " return 3;\n" + + " } \n" + + " int i(){\n" + + " if(false) ; else return 1;\n" + + " return 2;\n" + + " } \n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\G.java (at line 5)\n" + + " int bar(){ return foo(); }\n" + + " ^^^\n" + + "Cannot make a static reference to the non-static method foo() from the type G\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\B.java (at line 5)\n" + + " if (false) i = 2;\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in p\\B.java (at line 15)\n" + + " return 2;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in p\\B.java (at line 16)\n" + + " return 3;\n" + + " ^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "4. WARNING in p\\B.java (at line 19)\n" + + " if(false) ; else return 1;\n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "5. WARNING in p\\B.java (at line 20)\n" + + " return 2;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); } public void test105() { this.runNegativeTest( @@ -5545,85 +5663,202 @@ } public void test153() { + if (this.complianceLevel < ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "p/A3.java", + "package p;\n" + + "class A3 extends B {\n" + + " void fee() {\n" + + " C c = new C() {\n" + + " void foo() {\n" + + " B b = B.this;\n" + + " }\n" + + " };\n" + + " }\n" + + "}", + + "p/B.java", + "package p;\n" + + "class B{\n" + + " int f(){\n" + + " final int i;" + + " i = 1;\n" + + " if (false) i = 2;\n" + + " return i;\n" + + " }\n" + + " int g(){\n" + + " int i; \n" + + " if(true) i = 1;\n" + + " return i; \n" + + " }\n" + + " int h(){\n" + + " if(true) return 1;\n" + + " return 2;\n" + + " return 3;\n" + + " } \n" + + " int i(){\n" + + " if(false) ; else return 1;\n" + + " return 2;\n" + + " } \n" + + "}", + + "p/C.java", + "package p;\n" + + "public class C {\n" + + "void bar(int i){\n" + + " class Local {\n" + + " int x = i;\n" + + " }\n" + + "}\n" + + " void foo(){\n" + + " int k;\n" + + " int n = 5;\n" + + " if (n > 2) k = 3;\n" + + " System.out.println(k); // k is not \"definitely assigned\" before this\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\A3.java (at line 6)\n" + + " B b = B.this;\n" + + " ^^^^^^\n" + + "No enclosing instance of the type B is accessible in scope\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\B.java (at line 5)\n" + + " if (false) i = 2;\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in p\\B.java (at line 15)\n" + + " return 2;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in p\\B.java (at line 16)\n" + + " return 3;\n" + + " ^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "4. WARNING in p\\B.java (at line 20)\n" + + " return 2;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p\\C.java (at line 5)\n" + + " int x = i;\n" + + " ^\n" + + "Cannot refer to a non-final variable i inside an inner class defined in a different method\n" + + "----------\n" + + "2. ERROR in p\\C.java (at line 12)\n" + + " System.out.println(k); // k is not \"definitely assigned\" before this\n" + + " ^\n" + + "The local variable k may not have been initialized\n" + + "----------\n" + ); + return; + } this.runNegativeTest( - new String[] { - "p/A3.java", - "package p;\n" + - "class A3 extends B {\n" + - " void fee() {\n" + - " C c = new C() {\n" + - " void foo() {\n" + - " B b = B.this;\n" + - " }\n" + - " };\n" + - " }\n" + - "}", - - "p/B.java", - "package p;\n" + - "class B{\n" + - " int f(){\n" + - " final int i;" + - " i = 1;\n" + - " if (false) i = 2;\n" + - " return i;\n" + - " }\n" + - " int g(){\n" + - " int i; \n" + - " if(true) i = 1;\n" + - " return i; \n" + - " }\n" + - " int h(){\n" + - " if(true) return 1;\n" + - " return 2;\n" + - " return 3;\n" + - " } \n" + - " int i(){\n" + - " if(false) ; else return 1;\n" + - " return 2;\n" + - " } \n" + - "}", + new String[] { + "p/A3.java", + "package p;\n" + + "class A3 extends B {\n" + + " void fee() {\n" + + " C c = new C() {\n" + + " void foo() {\n" + + " B b = B.this;\n" + + " }\n" + + " };\n" + + " }\n" + + "}", - "p/C.java", - "package p;\n" + - "public class C {\n" + - "void bar(int i){\n" + - " class Local {\n" + - " int x = i;\n" + - " }\n" + - "}\n" + - " void foo(){\n" + - " int k;\n" + - " int n = 5;\n" + - " if (n > 2) k = 3;\n" + - " System.out.println(k); // k is not \"definitely assigned\" before this\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. ERROR in p\\A3.java (at line 6)\n" + - " B b = B.this;\n" + - " ^^^^^^\n" + - "No enclosing instance of the type B is accessible in scope\n" + - "----------\n" + - "----------\n" + - "1. ERROR in p\\B.java (at line 16)\n" + - " return 3;\n" + - " ^^^^^^^^^\n" + - "Unreachable code\n" + - "----------\n" + - "----------\n" + - "1. ERROR in p\\C.java (at line 5)\n" + - " int x = i;\n" + - " ^\n" + - "Cannot refer to a non-final variable i inside an inner class defined in a different method\n" + - "----------\n" + - "2. ERROR in p\\C.java (at line 12)\n" + - " System.out.println(k); // k is not \"definitely assigned\" before this\n" + - " ^\n" + - "The local variable k may not have been initialized\n" + - "----------\n" - ); + "p/B.java", + "package p;\n" + + "class B{\n" + + " int f(){\n" + + " final int i;" + + " i = 1;\n" + + " if (false) i = 2;\n" + + " return i;\n" + + " }\n" + + " int g(){\n" + + " int i; \n" + + " if(true) i = 1;\n" + + " return i; \n" + + " }\n" + + " int h(){\n" + + " if(true) return 1;\n" + + " return 2;\n" + + " return 3;\n" + + " } \n" + + " int i(){\n" + + " if(false) ; else return 1;\n" + + " return 2;\n" + + " } \n" + + "}", + + "p/C.java", + "package p;\n" + + "public class C {\n" + + "void bar(int i){\n" + + " class Local {\n" + + " int x = i;\n" + + " }\n" + + "}\n" + + " void foo(){\n" + + " int k;\n" + + " int n = 5;\n" + + " if (n > 2) k = 3;\n" + + " System.out.println(k); // k is not \"definitely assigned\" before this\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\A3.java (at line 6)\n" + + " B b = B.this;\n" + + " ^^^^^^\n" + + "No enclosing instance of the type B is accessible in scope\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\B.java (at line 5)\n" + + " if (false) i = 2;\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in p\\B.java (at line 15)\n" + + " return 2;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in p\\B.java (at line 16)\n" + + " return 3;\n" + + " ^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "4. WARNING in p\\B.java (at line 19)\n" + + " if(false) ; else return 1;\n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "5. WARNING in p\\B.java (at line 20)\n" + + " return 2;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p\\C.java (at line 5)\n" + + " int x = i;\n" + + " ^\n" + + "Cannot refer to a non-final variable i inside an inner class defined in a different method\n" + + "----------\n" + + "2. ERROR in p\\C.java (at line 12)\n" + + " System.out.println(k); // k is not \"definitely assigned\" before this\n" + + " ^\n" + + "The local variable k may not have been initialized\n" + + "----------\n"); + } public void test154() { this.runNegativeTest( @@ -7142,59 +7377,79 @@ " }\n" + "} ", }, - "----------\n" + - "1. ERROR in p\\DCBug.java (at line 7)\n" + - " class SubMember extends Member {\n" + - " ^^^^^^^^^\n" + - "Default constructor cannot handle exception type IOException thrown by implicit super constructor. Must define an explicit constructor\n" + - "----------\n" + - "2. ERROR in p\\DCBug.java (at line 12)\n" + - " catch(java.io.IOException e){};\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable catch block for IOException. This exception is never thrown from the try statement body\n" + - "----------\n" + - "3. WARNING in p\\DCBug.java (at line 15)\n" + - " private static void check_break ()\n" + - " ^^^^^^^^^^^^^^\n" + - "The method check_break() from the type DCBug is never used locally\n" + - "----------\n" + - "4. WARNING in p\\DCBug.java (at line 20)\n" + - " outer:\n" + - " ^^^^^\n" + - "The label outer is never explicitly referenced\n" + - "----------\n" + - "5. WARNING in p\\DCBug.java (at line 23)\n" + - " middle:\n" + - " ^^^^^^\n" + - "The label middle is never explicitly referenced\n" + - "----------\n" + - "6. WARNING in p\\DCBug.java (at line 41)\n" + - " outer:\n" + - " ^^^^^\n" + - "The label outer is never explicitly referenced\n" + - "----------\n" + - "7. WARNING in p\\DCBug.java (at line 47)\n" + - " inner:\n" + - " ^^^^^\n" + - "The label inner is never explicitly referenced\n" + - "----------\n" + - "8. WARNING in p\\DCBug.java (at line 63)\n" + - " middle:\n" + - " ^^^^^^\n" + - "The label middle is never explicitly referenced\n" + - "----------\n" + - "9. WARNING in p\\DCBug.java (at line 66)\n" + - " inner:\n" + - " ^^^^^\n" + - "The label inner is never explicitly referenced\n" + - "----------\n" + - "10. WARNING in p\\DCBug.java (at line 90)\n" + - " {\n" + - " i = 20;\n" + - " continue;\n" + - " }\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n" + + "1. ERROR in p\\DCBug.java (at line 7)\n" + + " class SubMember extends Member {\n" + + " ^^^^^^^^^\n" + + "Default constructor cannot handle exception type IOException thrown by implicit super constructor. Must define an explicit constructor\n" + + "----------\n" + + "2. ERROR in p\\DCBug.java (at line 12)\n" + + " catch(java.io.IOException e){};\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable catch block for IOException. This exception is never thrown from the try statement body\n" + + "----------\n" + + "3. WARNING in p\\DCBug.java (at line 15)\n" + + " private static void check_break ()\n" + + " ^^^^^^^^^^^^^^\n" + + "The method check_break() from the type DCBug is never used locally\n" + + "----------\n" + + "4. WARNING in p\\DCBug.java (at line 20)\n" + + " outer:\n" + + " ^^^^^\n" + + "The label outer is never explicitly referenced\n" + + "----------\n" + + "5. WARNING in p\\DCBug.java (at line 23)\n" + + " middle:\n" + + " ^^^^^^\n" + + "The label middle is never explicitly referenced\n" + + "----------\n" + + "6. WARNING in p\\DCBug.java (at line 41)\n" + + " outer:\n" + + " ^^^^^\n" + + "The label outer is never explicitly referenced\n" + + "----------\n" + + "7. WARNING in p\\DCBug.java (at line 42)\n" + + " for (int i = 0; i < 1000; i++)\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "8. WARNING in p\\DCBug.java (at line 45)\n" + + " for (int j = 0; j < 1000; j++)\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "9. WARNING in p\\DCBug.java (at line 47)\n" + + " inner:\n" + + " ^^^^^\n" + + "The label inner is never explicitly referenced\n" + + "----------\n" + + "10. WARNING in p\\DCBug.java (at line 48)\n" + + " for (int k = 0; k < 1000; k++)\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "11. WARNING in p\\DCBug.java (at line 63)\n" + + " middle:\n" + + " ^^^^^^\n" + + "The label middle is never explicitly referenced\n" + + "----------\n" + + "12. WARNING in p\\DCBug.java (at line 66)\n" + + " inner:\n" + + " ^^^^^\n" + + "The label inner is never explicitly referenced\n" + + "----------\n" + + "13. WARNING in p\\DCBug.java (at line 67)\n" + + " for (int k = 0; k < 1000; k++)\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "14. WARNING in p\\DCBug.java (at line 90)\n" + + " {\n" + + " i = 20;\n" + + " continue;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + "----------\n"); } public void test199() { @@ -9259,83 +9514,93 @@ "}", }, - "----------\n" + - "1. WARNING in p\\d\\One1.java (at line 7)\n" + - " public void problem2() {\n" + - " ^^^^^^^^^^\n" + - "The method problem2() from the type new Object(){} is never used locally\n" + - "----------\n" + - "----------\n" + - "1. WARNING in p\\d\\JE_5_AWT.java (at line 4)\n" + - " public class JE_5_AWT extends Frame {\n" + - " ^^^^^^^^\n" + - "The serializable class JE_5_AWT does not declare a static final serialVersionUID field of type long\n" + - "----------\n" + - "2. WARNING in p\\d\\JE_5_AWT.java (at line 21)\n" + - " Object obj = JE_5_AWT.this; //<---------OK\n" + - " ^^^\n" + - "The field new Object(){}.obj is never read locally\n" + - "----------\n" + - "3. WARNING in p\\d\\JE_5_AWT.java (at line 26)\n" + - " Object obj = JE_5_AWT.this; //<---------KO \n" + - " ^^^\n" + - "The field new Object(){}.obj is never read locally\n" + - "----------\n" + - "4. ERROR in p\\d\\JE_5_AWT.java (at line 26)\n" + - " Object obj = JE_5_AWT.this; //<---------KO \n" + - " ^^^^^^^^^^^^^\n" + - "No enclosing instance of the type JE_5_AWT is accessible in scope\n" + - "----------\n" + - "5. ERROR in p\\d\\JE_5_AWT.java (at line 32)\n" + - " Object obj2 = d; // KO\n" + - " ^\n" + - "Cannot refer to an instance field d while explicitly invoking a constructor\n" + - "----------\n" + - "6. WARNING in p\\d\\JE_5_AWT.java (at line 37)\n" + - " Object myself() {\n" + - " ^^^^^^^^\n" + - "The method myself() from the type new Object(){} is never used locally\n" + - "----------\n" + - "7. WARNING in p\\d\\JE_5_AWT.java (at line 43)\n" + - " class Local {\n" + - " ^^^^^\n" + - "The type Local is never used locally\n" + - "----------\n" + - "8. WARNING in p\\d\\JE_5_AWT.java (at line 44)\n" + - " JE_5_AWT obj = JE_5_AWT.this;\n" + - " ^^^\n" + - "The field Local.obj is never read locally\n" + - "----------\n" + - "9. WARNING in p\\d\\JE_5_AWT.java (at line 49)\n" + - " Object outer() {\n" + - " ^^^^^^^\n" + - "The method outer() from the type new Object(){} is never used locally\n" + - "----------\n" + - "10. ERROR in p\\d\\JE_5_AWT.java (at line 50)\n" + - " return JE_5_AWT.this; //<---- KO\n" + - " ^^^^^^^^^^^^^\n" + - "No enclosing instance of the type JE_5_AWT is accessible in scope\n" + - "----------\n" + - "11. WARNING in p\\d\\JE_5_AWT.java (at line 55)\n" + - " class Local extends Thread {\n" + - " ^^^^^\n" + - "The type Local is never used locally\n" + - "----------\n" + - "12. WARNING in p\\d\\JE_5_AWT.java (at line 56)\n" + - " Local() {\n" + - " ^^^^^^^\n" + - "The constructor Local() is never used locally\n" + - "----------\n" + - "----------\n" + - "1. WARNING in p\\d\\One.java (at line 13)\n" + - " public void problem2() {\n" + - " ^^^^^^^^^^\n" + - "The method problem2() from the type new Object(){} is never used locally\n" + - "----------\n" + - "2. ERROR in p\\d\\One.java (at line 24)\n" + - " fireTableCellUpdated();\n" + - " ^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot refer to an instance method while explicitly invoking a constructor\n" + + "----------\n" + + "1. WARNING in p\\d\\One1.java (at line 7)\n" + + " public void problem2() {\n" + + " ^^^^^^^^^^\n" + + "The method problem2() from the type new Object(){} is never used locally\n" + + "----------\n" + + "2. WARNING in p\\d\\One1.java (at line 8)\n" + + " if(dialog == 3) return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\d\\JE_5_AWT.java (at line 4)\n" + + " public class JE_5_AWT extends Frame {\n" + + " ^^^^^^^^\n" + + "The serializable class JE_5_AWT does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in p\\d\\JE_5_AWT.java (at line 21)\n" + + " Object obj = JE_5_AWT.this; //<---------OK\n" + + " ^^^\n" + + "The field new Object(){}.obj is never read locally\n" + + "----------\n" + + "3. WARNING in p\\d\\JE_5_AWT.java (at line 26)\n" + + " Object obj = JE_5_AWT.this; //<---------KO \n" + + " ^^^\n" + + "The field new Object(){}.obj is never read locally\n" + + "----------\n" + + "4. ERROR in p\\d\\JE_5_AWT.java (at line 26)\n" + + " Object obj = JE_5_AWT.this; //<---------KO \n" + + " ^^^^^^^^^^^^^\n" + + "No enclosing instance of the type JE_5_AWT is accessible in scope\n" + + "----------\n" + + "5. ERROR in p\\d\\JE_5_AWT.java (at line 32)\n" + + " Object obj2 = d; // KO\n" + + " ^\n" + + "Cannot refer to an instance field d while explicitly invoking a constructor\n" + + "----------\n" + + "6. WARNING in p\\d\\JE_5_AWT.java (at line 37)\n" + + " Object myself() {\n" + + " ^^^^^^^^\n" + + "The method myself() from the type new Object(){} is never used locally\n" + + "----------\n" + + "7. WARNING in p\\d\\JE_5_AWT.java (at line 43)\n" + + " class Local {\n" + + " ^^^^^\n" + + "The type Local is never used locally\n" + + "----------\n" + + "8. WARNING in p\\d\\JE_5_AWT.java (at line 44)\n" + + " JE_5_AWT obj = JE_5_AWT.this;\n" + + " ^^^\n" + + "The field Local.obj is never read locally\n" + + "----------\n" + + "9. WARNING in p\\d\\JE_5_AWT.java (at line 49)\n" + + " Object outer() {\n" + + " ^^^^^^^\n" + + "The method outer() from the type new Object(){} is never used locally\n" + + "----------\n" + + "10. ERROR in p\\d\\JE_5_AWT.java (at line 50)\n" + + " return JE_5_AWT.this; //<---- KO\n" + + " ^^^^^^^^^^^^^\n" + + "No enclosing instance of the type JE_5_AWT is accessible in scope\n" + + "----------\n" + + "11. WARNING in p\\d\\JE_5_AWT.java (at line 55)\n" + + " class Local extends Thread {\n" + + " ^^^^^\n" + + "The type Local is never used locally\n" + + "----------\n" + + "12. WARNING in p\\d\\JE_5_AWT.java (at line 56)\n" + + " Local() {\n" + + " ^^^^^^^\n" + + "The constructor Local() is never used locally\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\d\\One.java (at line 13)\n" + + " public void problem2() {\n" + + " ^^^^^^^^^^\n" + + "The method problem2() from the type new Object(){} is never used locally\n" + + "----------\n" + + "2. WARNING in p\\d\\One.java (at line 14)\n" + + " if(dialog == 3) return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in p\\d\\One.java (at line 24)\n" + + " fireTableCellUpdated();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot refer to an instance method while explicitly invoking a constructor\n" + "----------\n"); } public void test236() { @@ -9888,16 +10153,21 @@ " } \n" + "} \n", }, - "----------\n" + - "1. ERROR in p1\\X.java (at line 5)\n" + - " new Object(){ \n" + - " { \n" + - " if (true) throw new IOException(); \n" + - " if (true) throw new Exception(); \n" + - " } \n" + - " }; \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unhandled exception type Exception\n" + + "----------\n" + + "1. ERROR in p1\\X.java (at line 5)\n" + + " new Object(){ \n" + + " { \n" + + " if (true) throw new IOException(); \n" + + " if (true) throw new Exception(); \n" + + " } \n" + + " }; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Exception\n" + + "----------\n" + + "2. WARNING in p1\\X.java (at line 8)\n" + + " if (true) throw new Exception(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + "----------\n" ); } @@ -11307,16 +11577,38 @@ "} \n", }, null, customOptions, - "----------\n" + - "1. WARNING in Test.java (at line 3)\n" + - " private void doTest() { \n" + - " ^^^^^^^^\n" + - "The method doTest() from the type Test is never used locally\n" + - "----------\n" + - "2. WARNING in Test.java (at line 12)\n" + - " int i = 0; \n" + - " ^\n" + - "The local variable i is never read\n" + + "----------\n" + + "1. WARNING in Test.java (at line 3)\n" + + " private void doTest() { \n" + + " ^^^^^^^^\n" + + "The method doTest() from the type Test is never used locally\n" + + "----------\n" + + "2. WARNING in Test.java (at line 5)\n" + + " if (DEBUG){ \n" + + " time = System.currentTimeMillis(); \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in Test.java (at line 9)\n" + + " if (DEBUG) { \n" + + " System.out.println(\"Bob takes: \" + (System.currentTimeMillis() - time) + \" ms\"); \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. WARNING in Test.java (at line 12)\n" + + " int i = 0; \n" + + " ^\n" + + "The local variable i is never read\n" + + "----------\n" + + "5. WARNING in Test.java (at line 13)\n" + + " if (DEBUG){ \n" + + " int j = 1; \n" + + " j++; \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + "----------\n", null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); } @@ -11438,41 +11730,93 @@ " } \n"+ "}", }, - "----------\n" + - "1. WARNING in X.java (at line 28)\n" + - " Object obj = \"dummy\"; \n" + - " ^^^\n" + - "The local variable obj is never read\n" + - "----------\n" + - "2. ERROR in X.java (at line 44)\n" + - " while (false) { \n" + - " doit(obj); //this is DEFINITELY unreachable code, and is recognized as such, with error \n" + - " } \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + - "----------\n" + - "3. ERROR in X.java (at line 48)\n" + - " while (FALSE) { \n" + - " doit(obj); //this is conditionnally unreachable code, but is recognized as definitely unreacheable code, with error \n" + - " } \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + - "----------\n" + - "4. ERROR in X.java (at line 52)\n" + - " for (; false;) { \n" + - " doit(obj); //this is DEFINITELY unreachable code, but is recognized as definitely unreacheable code, with error \n" + - " } \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + - "----------\n" + - "5. ERROR in X.java (at line 56)\n" + - " for (; FALSE;) { \n" + - " doit(obj); //this is conditionnally unreachable code, but is recognized as definitely unreacheable code, with error \n" + - " } \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + - "----------\n" -, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " if (TRUE || obj != null) { \n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 18)\n" + + " if (FALSE) { \n" + + " doit(obj); \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in X.java (at line 22)\n" + + " if (false) { \n" + + " doit(obj); \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. WARNING in X.java (at line 28)\n" + + " Object obj = \"dummy\"; \n" + + " ^^^\n" + + "The local variable obj is never read\n" + + "----------\n" + + "5. WARNING in X.java (at line 36)\n" + + " if (false) { \n" + + " doit(obj); //this is DEFINITELY unreachable code, but is not recognized as such \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in X.java (at line 40)\n" + + " if (FALSE) { \n" + + " doit(obj); //this is conditionnally unreachable code, but is not recognized as such \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "7. ERROR in X.java (at line 44)\n" + + " while (false) { \n" + + " doit(obj); //this is DEFINITELY unreachable code, and is recognized as such, with error \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "8. ERROR in X.java (at line 48)\n" + + " while (FALSE) { \n" + + " doit(obj); //this is conditionnally unreachable code, but is recognized as definitely unreacheable code, with error \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "9. ERROR in X.java (at line 52)\n" + + " for (; false;) { \n" + + " doit(obj); //this is DEFINITELY unreachable code, but is recognized as definitely unreacheable code, with error \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "10. ERROR in X.java (at line 56)\n" + + " for (; FALSE;) { \n" + + " doit(obj); //this is conditionnally unreachable code, but is recognized as definitely unreacheable code, with error \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "11. WARNING in X.java (at line 60)\n" + + " int i = (false ? doit(\"0\") : doit(\"1\")); \n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "12. WARNING in X.java (at line 63)\n" + + " int j = (FALSE ? doit(\"0\") : doit(\"1\")); \n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "13. WARNING in X.java (at line 77)\n" + + " doit(obj); //this is conditionnally unreachable code \n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "14. WARNING in X.java (at line 91)\n" + + " doit(obj); //this is DEFINITELY unreachable code \n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", null, true, customOptions); @@ -16048,11 +16392,17 @@ " }\n" + "}\n" }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " break label2;\n" + - " ^^^^^^^^^^^^^\n" + - "The label label2 is missing\n" + + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " if (false) \n" + + " break label2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " break label2;\n" + + " ^^^^^^^^^^^^^\n" + + "The label label2 is missing\n" + "----------\n"); } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java,v retrieving revision 1.34 diff -u -r1.34 FlowAnalysisTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 9 Sep 2008 16:39:25 -0000 1.34 +++ src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 24 Nov 2008 12:59:15 -0000 @@ -48,11 +48,18 @@ " } \n" + "}\n", }, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public String foo(int i) {\n" + - " ^^^^^^^^^^\n" + - "This method must return a result of type String\n" + + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public String foo(int i) {\n" + + " ^^^^^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " if (i > 0) {\n" + + " return null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + "----------\n"); } @@ -712,11 +719,16 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " x.foo();\n" + - " ^\n" + - "The local variable x may not have been initialized\n" + + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " x = new X();\n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " x.foo();\n" + + " ^\n" + + "The local variable x may not have been initialized\n" + "----------\n", JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); } @@ -1169,11 +1181,19 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " System.out.println(s);\n" + - " ^\n" + - "The local variable s may not have been initialized\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (false) {\n" + + " String s;\n" + + " System.out.println(s);\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " System.out.println(s);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 @@ -1210,11 +1230,21 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " System.out.println(s);\n" + - " ^\n" + - "The local variable s may not have been initialized\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (false) {\n" + + " String s;\n" + + " if (System.out != null) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " System.out.println(s);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 @@ -1232,11 +1262,18 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " s = \"\";\n" + - " ^\n" + - "The final local variable s cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " s = \"\";\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " s = \"\";\n" + + " ^\n" + + "The final local variable s cannot be assigned. It must be blank and not using a compound assignment\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 @@ -1273,11 +1310,18 @@ " }\n" + "}" }, - "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " s = \"\";\n" + - " ^\n" + - "The final local variable s may already have been assigned\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " s = \"\";\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " s = \"\";\n" + + " ^\n" + + "The final local variable s may already have been assigned\n" + "----------\n"); } // switch and definite assignment @@ -1375,7 +1419,12 @@ " }\n" + "}\n", }, - "", + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " for (final int i; 0 < (i = 1); i = i + 1) {\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", "1", "", JavacTestOptions.JavacHasABug.JavacBug4660984); @@ -1421,11 +1470,20 @@ "}\n" }, false /* expectingCompilerErrors */, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " label: while (bar()) {\n" + - " ^^^^^\n" + - "The label label is never explicitly referenced\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (b) {\n" + + " label: while (bar()) {\n" + + " }\n" + + " return null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " label: while (bar()) {\n" + + " ^^^^^\n" + + "The label label is never explicitly referenced\n" + "----------\n" /* expectedCompilerLog */, "" /* expectedOutputString */, "" /* expectedErrorString */, @@ -1460,7 +1518,16 @@ "}\n" }, false /* expectingCompilerErrors */, - "" /* expectedCompilerLog */, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (b) {\n" + + " while (bar()) {\n" + + " }\n" + + " return null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" /* expectedCompilerLog */, "" /* expectedOutputString */, "" /* expectedErrorString */, false /* forceExecution */, @@ -1506,6 +1573,300 @@ } ); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 +public void test052() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " if (b && false) {\n" + + " int i = 0; // deadcode\n" + + " return; // 1\n" + + " }\n" + + " return;\n" + + " return;\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (b && false) {\n" + + " int i = 0; // deadcode\n" + + " return; // 1\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test053() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " if (false && b) {\n" + + " int j = 0; // deadcode\n" + + " return; // 2\n" + + " }\n" + + " return;\n" + + " return;\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (false && b) {\n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " if (false && b) {\n" + + " int j = 0; // deadcode\n" + + " return; // 2\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test054() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " while (true) {\n" + + " if (true) break;\n" + + " int k = 0; // deadcode\n" + + " }\n" + + " return;\n" + + " return;\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " int k = 0; // deadcode\n" + + " ^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test055() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " if (true || b) {\n" + + " int l = 0; // deadcode\n" + + " return; // 2a\n" + + " } \n" + + " return;\n" + + " return;\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (true || b) {\n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test056() { + if (this.complianceLevel < ClassFileConstants.JDK1_4) { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void bar() {\n" + + " return;\n" + + " {\n" + + " return; // 3\n" + + " }\n" + + " }\n" + + " void baz() {\n" + + " return;\n" + + " {\n" + + " }\n" + + " } \n" + + " void baz2() {\n" + + " return;\n" + + " ; // 4\n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " {\n" + + " return; // 3\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " {\n" + + " }\n" + + " ^^^^^\n" + + "Unreachable code\n" + + "----------\n"); + return; + } + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void bar() {\n" + + " return;\n" + + " {\n" + + " return; // 3\n" + + " }\n" + + " }\n" + + " void baz() {\n" + + " return;\n" + + " {\n" + + " }\n" + + " } \n" + + " void baz2() {\n" + + " return;\n" + + " ; // 4\n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " {\n" + + " return; // 3\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " {\n" + + " }\n" + + " ^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " ; // 4\n" + + " ^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110544 +public void test057() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(int x, int[] array) {\n" + + " for (int i = 0; \n" + + " i < array.length; \n" + + " i++) {//dead code\n" + + " if (x == array[i])\n" + + " return;\n" + + " else\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " i++) {//dead code\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " break;\n" + + " ^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test058() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo() {\n" + + " if (false) {\n" + + " class Local {\n" + + " int i = 12;\n" + + " { i++; }\n" + + " void method() {\n" + + " if (false)\n" + + " System.out.println();\n" + + " return;\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (false) {\n" + + " class Local {\n" + + " int i = 12;\n" + + " { i++; }\n" + + " void method() {\n" + + " if (false)\n" + + " System.out.println();\n" + + " return;\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " class Local {\n" + + " ^^^^^\n" + + "The type Local is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " void method() {\n" + + " ^^^^^^^^\n" + + "The method method() from the type Local is never used locally\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} public static Class testClass() { return FlowAnalysisTest.class; } Index: src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java,v retrieving revision 1.78 diff -u -r1.78 NullReferenceTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 27 Jun 2008 16:04:45 -0000 1.78 +++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 24 Nov 2008 12:59:24 -0000 @@ -638,12 +638,17 @@ " o.toString();\n" + " }\n" + "}\n"}, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " o.toString();\n" + - " ^\n" + - "Null pointer access: The variable o can only be null at this location\n" + - "----------\n", + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object o = true ? null : null;\n" + + " ^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } @@ -658,12 +663,17 @@ " o.toString();\n" + " }\n" + "}\n"}, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " o.toString();\n" + - " ^\n" + - "Null pointer access: The variable o can only be null at this location\n" + - "----------\n", + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object o = true ? null : new Object();\n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } @@ -692,12 +702,17 @@ " o.toString();\n" + " }\n" + "}\n"}, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " o.toString();\n" + - " ^\n" + - "Null pointer access: The variable o can only be null at this location\n" + - "----------\n", + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object o = (1 == 1) ? null : new Object();\n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } @@ -1604,12 +1619,26 @@ " o.toString();\n" + " }\n" + "}\n"}, - "----------\n" + - "1. ERROR in X.java (at line 13)\n" + - " o.toString();\n" + - " ^\n" + - "Null pointer access: The variable o can only be null at this location\n" + - "----------\n", + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " o = new Object();\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " else {\n" + + " o = new Object();\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } @@ -7869,7 +7898,12 @@ " if (o == null) { };\n" + // quiet " }\n" + "}\n"}, - ""); + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " assert(false && o != null);\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); } } Index: src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java,v retrieving revision 1.53 diff -u -r1.53 AssignmentTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 10 Sep 2008 16:31:51 -0000 1.53 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 24 Nov 2008 12:59:12 -0000 @@ -977,10 +977,17 @@ options /* custom options */, // compiler results "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 4)\n" + - " b = false;\n" + - " ^\n" + - "The parameter b should not be assigned\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (false) {\n" + + " b = false;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " b = false;\n" + + " ^\n" + + "The parameter b should not be assigned\n" + "----------\n", // javac options JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); @@ -1010,10 +1017,15 @@ options /* custom options */, // compiler results "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 6)\n" + - " b = false;\n" + - " ^\n" + - "The parameter b should not be assigned\n" + + "1. WARNING in X.java (at line 6)\n" + + " b = false;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " b = false;\n" + + " ^\n" + + "The parameter b should not be assigned\n" + "----------\n", // javac options JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); @@ -1036,10 +1048,17 @@ "}\n", }, "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " b = false;\n" + - " ^\n" + - "The final local variable b cannot be assigned. It must be blank and not using a compound assignment\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (false) {\n" + + " b = false;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " b = false;\n" + + " ^\n" + + "The final local variable b cannot be assigned. It must be blank and not using a compound assignment\n" + "----------\n", null, true, options); } @@ -1356,10 +1375,19 @@ }, // compiler results "----------\n" + /* expected compiler log */ - "1. ERROR in X.java (at line 11)\n" + - " i = 1;\n" + - " ^\n" + - "The final local variable i may already have been assigned\n" + + "1. WARNING in X.java (at line 5)\n" + + " if (false) {\n" + + " i = 0;\n" + + " System.out.println(i);\n" + + " throw new MyException();\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + "----------\n", // javac options JavacTestOptions.EclipseJustification.EclipseBug235543 /* javac test options */); Index: src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java,v retrieving revision 1.78 diff -u -r1.78 Compliance_1_5.java --- src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java 27 Jun 2008 16:04:44 -0000 1.78 +++ src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java 24 Nov 2008 12:59:15 -0000 @@ -108,28 +108,37 @@ " } \n" + "} \n" }, - "----------\n" + - "1. ERROR in p1\\X.java (at line 4)\n" + - " while (false); \n" + - " ^\n" + - "Unreachable code\n" + - "----------\n" + - "2. ERROR in p1\\X.java (at line 5)\n" + - " while (false) System.out.println(\"unreachable\"); \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + - "----------\n" + - "3. ERROR in p1\\X.java (at line 8)\n" + - " for (;false;); \n" + - " ^\n" + - "Unreachable code\n" + - "----------\n" + - "4. ERROR in p1\\X.java (at line 9)\n" + - " for (;false;) System.out.println(\"unreachable\"); \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + - "----------\n" - ); + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " while (false); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 5)\n" + + " while (false) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in p1\\X.java (at line 8)\n" + + " for (;false;); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "4. ERROR in p1\\X.java (at line 9)\n" + + " for (;false;) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "5. WARNING in p1\\X.java (at line 10)\n" + + " if (false); \n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in p1\\X.java (at line 11)\n" + + " if (false)System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); } /// binary compatibility public void test012() { @@ -783,12 +792,18 @@ " } \n"+ "} \n" }, - "----------\n" + - "1. ERROR in p1\\X.java (at line 4)\n" + - " for (;false;p()); \n" + - " ^\n" + - "Unreachable code\n" + - "----------\n"); + "----------\n" + + "1. WARNING in p1\\X.java (at line 4)\n" + + " for (;false;p()); \n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 4)\n" + + " for (;false;p()); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" +); } /* * http://bugs.eclipse.org/bugs/show_bug.cgi?id=12445 @@ -1255,26 +1270,36 @@ " } \n"+ "} \n", }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " for (;false;); \n" + - " ^\n" + - "Unreachable code\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " for (;false;){} \n" + - " ^^\n" + - "Unreachable code\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " while (false); \n" + - " ^\n" + - "Unreachable code\n" + - "----------\n" + - "4. ERROR in X.java (at line 8)\n" + - " while (false){} \n" + - " ^^\n" + - "Unreachable code\n" + + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " for (;false;); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " for (;false;){} \n" + + " ^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " while (false); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " while (false){} \n" + + " ^^\n" + + "Unreachable code\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " if (false) {} else {} \n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " if (false) ; else ; \n" + + " ^\n" + + "Dead code\n" + "----------\n"); } // jls6.5.5.1 - simple type names favor member type over toplevel one. Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java,v retrieving revision 1.768 diff -u -r1.768 GenericTypeTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 20 Nov 2008 16:32:23 -0000 1.768 +++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 24 Nov 2008 12:59:22 -0000 @@ -25316,11 +25316,21 @@ " }\n" + "}\n", }, - "----------\n" + - "1. ERROR in X.java (at line 13)\n" + - " return true ? superList : superList;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type mismatch: cannot convert from ArrayList to ArrayList\n" + + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " return true ? list : list;\n" + + " ^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " return true ? superList : superList;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from ArrayList to ArrayList\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " return true ? extendsList : extendsList;\n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=106865 @@ -44275,81 +44285,91 @@ " } \n" + "}\n", // ================= }, - "----------\n" + - "1. WARNING in X.java (at line 11)\n" + - " if (false) return new Y(b);//1\n" + - " ^^^^^^^^\n" + - "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " if (false) return new Y(b);//1\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "3. WARNING in X.java (at line 12)\n" + - " if (false) return new Y((K) b);//2\n" + - " ^^^^^^^^^^^^\n" + - "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + - "----------\n" + - "4. WARNING in X.java (at line 12)\n" + - " if (false) return new Y((K) b);//2\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 12)\n" + - " if (false) return new Y((K) b);//2\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from B to K\n" + - "----------\n" + - "6. WARNING in X.java (at line 12)\n" + - " if (false) return new Y((K) b);//2\n" + - " ^^^^^\n" + - "Unnecessary cast from B to K\n" + - "----------\n" + - "7. WARNING in X.java (at line 13)\n" + - " return new Y((K) (Object) b);//3\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + - "----------\n" + - "8. WARNING in X.java (at line 13)\n" + - " return new Y((K) (Object) b);//3\n" + - " ^\n" + - "Y is a raw type. References to generic type Y should be parameterized\n" + - "----------\n" + - "9. WARNING in X.java (at line 13)\n" + - " return new Y((K) (Object) b);//3\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to K\n" + - "----------\n" + - "10. WARNING in X.java (at line 13)\n" + - " return new Y((K) (Object) b);//3\n" + - " ^^^^^^^^^^^^^^\n" + - "Unnecessary cast from Object to K\n" + - "----------\n" + - "11. WARNING in X.java (at line 13)\n" + - " return new Y((K) (Object) b);//3\n" + - " ^^^^^^^^^^\n" + - "Unnecessary cast from B to Object\n" + - "----------\n" + - "12. ERROR in X.java (at line 16)\n" + - " if (false) return new Y(b);//4\n" + - " ^^^^^^^^^^^\n" + - "The constructor Y(B) is undefined\n" + - "----------\n" + - "13. WARNING in X.java (at line 17)\n" + - " if (false) return new Y((K) b);//5\n" + - " ^^^^^\n" + - "Type safety: Unchecked cast from B to K\n" + - "----------\n" + - "14. WARNING in X.java (at line 18)\n" + - " return new Y((K) (Object) b);//6\n" + - " ^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to K\n" + - "----------\n" + - "15. WARNING in X.java (at line 18)\n" + - " return new Y((K) (Object) b);//6\n" + - " ^^^^^^^^^^\n" + - "Unnecessary cast from B to Object\n" + + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " if (false) return new Y(b);//1\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " if (false) return new Y(b);//1\n" + + " ^^^^^^^^\n" + + "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " if (false) return new Y(b);//1\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from B to K\n" + + "----------\n" + + "8. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^^^^^\n" + + "Unnecessary cast from B to K\n" + + "----------\n" + + "9. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "10. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to K\n" + + "----------\n" + + "12. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to K\n" + + "----------\n" + + "13. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from B to Object\n" + + "----------\n" + + "14. ERROR in X.java (at line 16)\n" + + " if (false) return new Y(b);//4\n" + + " ^^^^^^^^^^^\n" + + "The constructor Y(B) is undefined\n" + + "----------\n" + + "15. WARNING in X.java (at line 17)\n" + + " if (false) return new Y((K) b);//5\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from B to K\n" + + "----------\n" + + "16. WARNING in X.java (at line 18)\n" + + " return new Y((K) (Object) b);//6\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to K\n" + + "----------\n" + + "17. WARNING in X.java (at line 18)\n" + + " return new Y((K) (Object) b);//6\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from B to Object\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=228291 Index: src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java,v retrieving revision 1.44 diff -u -r1.44 CastTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java 4 Jul 2008 10:06:02 -0000 1.44 +++ src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java 24 Nov 2008 12:59:13 -0000 @@ -1479,7 +1479,16 @@ "}\n" }, // compiler results - "" /* expected compiler log */, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " null : new Base() {\n" + + " public final String test() {\n" + + " return (\"anonymous\");\n" + + " }\n" + + " };\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", /* expected compiler log */ // runtime results "no base" /* expected output string */, "" /* expected error string */, Index: src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java,v retrieving revision 1.102 diff -u -r1.102 Compliance_1_4.java --- src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java 17 Sep 2008 09:07:31 -0000 1.102 +++ src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java 24 Nov 2008 12:59:15 -0000 @@ -107,26 +107,36 @@ " } \n" + "} \n" }, - "----------\n" + - "1. ERROR in p1\\X.java (at line 4)\n" + - " while (false); \n" + - " ^\n" + - "Unreachable code\n" + - "----------\n" + - "2. ERROR in p1\\X.java (at line 5)\n" + - " while (false) System.out.println(\"unreachable\"); \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + - "----------\n" + - "3. ERROR in p1\\X.java (at line 8)\n" + - " for (;false;); \n" + - " ^\n" + - "Unreachable code\n" + - "----------\n" + - "4. ERROR in p1\\X.java (at line 9)\n" + - " for (;false;) System.out.println(\"unreachable\"); \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " while (false); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 5)\n" + + " while (false) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in p1\\X.java (at line 8)\n" + + " for (;false;); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "4. ERROR in p1\\X.java (at line 9)\n" + + " for (;false;) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "5. WARNING in p1\\X.java (at line 10)\n" + + " if (false); \n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in p1\\X.java (at line 11)\n" + + " if (false)System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + "----------\n" ); } @@ -777,11 +787,16 @@ " } \n"+ "} \n" }, - "----------\n" + - "1. ERROR in p1\\X.java (at line 4)\n" + - " for (;false;p()); \n" + - " ^\n" + - "Unreachable code\n" + + "----------\n" + + "1. WARNING in p1\\X.java (at line 4)\n" + + " for (;false;p()); \n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 4)\n" + + " for (;false;p()); \n" + + " ^\n" + + "Unreachable code\n" + "----------\n"); } /* @@ -1223,27 +1238,38 @@ " } \n"+ "} \n", }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " for (;false;); \n" + - " ^\n" + - "Unreachable code\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " for (;false;){} \n" + - " ^^\n" + - "Unreachable code\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " while (false); \n" + - " ^\n" + - "Unreachable code\n" + - "----------\n" + - "4. ERROR in X.java (at line 8)\n" + - " while (false){} \n" + - " ^^\n" + - "Unreachable code\n" + - "----------\n"); + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " for (;false;); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " for (;false;){} \n" + + " ^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " while (false); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " while (false){} \n" + + " ^^\n" + + "Unreachable code\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " if (false) {} else {} \n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " if (false) ; else ; \n" + + " ^\n" + + "Dead code\n" + + "----------\n" +); } // jls6.5.5.1 - simple type names favor member type over toplevel one. //http://bugs.eclipse.org/bugs/show_bug.cgi?id=30705 Index: src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java,v retrieving revision 1.47 diff -u -r1.47 InnerEmulationTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java 1 Oct 2008 22:27:50 -0000 1.47 +++ src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java 24 Nov 2008 12:59:23 -0000 @@ -3751,7 +3751,14 @@ " } \n"+ "} \n", }, - "", + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " } else { \n" + + " System.out.println(\"unreachable inner class = \" + new Object() {}.getClass()); \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", "first inner class = class X$1\n" + "Always true\n" + "last inner class = class X$2", Index: src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java,v retrieving revision 1.24 diff -u -r1.24 CompilerInvocationTests.java --- src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java 21 Nov 2008 20:03:12 -0000 1.24 +++ src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java 24 Nov 2008 12:59:14 -0000 @@ -547,6 +547,8 @@ expectedProblemAttributes.put("RedundantSuperinterface", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("ShouldImplementHashcode", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("AbstractMethodsInConcreteClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("AbstractMethodInEnum", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("DeadCode", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("SuperclassNotFound", DEPRECATED); expectedProblemAttributes.put("SuperclassNotVisible", DEPRECATED); expectedProblemAttributes.put("SuperclassAmbiguous", DEPRECATED); @@ -841,7 +843,6 @@ expectedProblemAttributes.put("EnumStaticFieldInInInitializerContext", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("EnumConstantMustImplementAbstractMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("EnumConstantCannotDefineAbstractMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); - expectedProblemAttributes.put("AbstractMethodInEnum", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("IllegalExtendedDimensionsForVarArgs", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("MethodVarargsArgumentNeedCast", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("ConstructorVarargsArgumentNeedCast", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); @@ -1043,6 +1044,7 @@ expectedProblemAttributes.put("AmbiguousConstructorInImplicitConstructorCall", SKIP); expectedProblemAttributes.put("UnhandledExceptionInDefaultConstructor", SKIP); expectedProblemAttributes.put("UnhandledExceptionInImplicitConstructorCall", SKIP); + expectedProblemAttributes.put("DeadCode", new ProblemAttributes(JavaCore.COMPILER_PB_DEAD_CODE)); expectedProblemAttributes.put("ArrayReferenceRequired", SKIP); expectedProblemAttributes.put("NoImplicitStringConversionForCharArrayExpression", new ProblemAttributes(JavaCore.COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION)); expectedProblemAttributes.put("StringConstantIsExceedingUtf8Limit", SKIP); @@ -1174,6 +1176,7 @@ expectedProblemAttributes.put("RedundantSuperinterface", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_SUPERINTERFACE)); expectedProblemAttributes.put("ShouldImplementHashcode", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_HASHCODE_METHOD)); expectedProblemAttributes.put("AbstractMethodsInConcreteClass", SKIP); + expectedProblemAttributes.put("AbstractMethodInEnum", SKIP); expectedProblemAttributes.put("SuperclassNotFound", SKIP); expectedProblemAttributes.put("SuperclassNotVisible", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_SUPERINTERFACE)); expectedProblemAttributes.put("SuperclassAmbiguous", SKIP); @@ -1468,7 +1471,6 @@ expectedProblemAttributes.put("EnumStaticFieldInInInitializerContext", SKIP); expectedProblemAttributes.put("EnumConstantMustImplementAbstractMethod", SKIP); expectedProblemAttributes.put("EnumConstantCannotDefineAbstractMethod", SKIP); - expectedProblemAttributes.put("AbstractMethodInEnum", SKIP); expectedProblemAttributes.put("IllegalExtendedDimensionsForVarArgs", SKIP); expectedProblemAttributes.put("MethodVarargsArgumentNeedCast", new ProblemAttributes(JavaCore.COMPILER_PB_VARARGS_ARGUMENT_NEED_CAST)); expectedProblemAttributes.put("ConstructorVarargsArgumentNeedCast", new ProblemAttributes(JavaCore.COMPILER_PB_VARARGS_ARGUMENT_NEED_CAST)); Index: src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java,v retrieving revision 1.116 diff -u -r1.116 AbstractRegressionTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java 28 Aug 2008 18:53:46 -0000 1.116 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java 24 Nov 2008 12:59:11 -0000 @@ -1006,6 +1006,7 @@ defaultOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.WARNING); defaultOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); defaultOptions.put(CompilerOptions.OPTION_ReportUnnecessaryElse, CompilerOptions.WARNING ); + defaultOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.WARNING); return defaultOptions; } Index: src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java,v retrieving revision 1.101 diff -u -r1.101 Compliance_1_3.java --- src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java 27 Jun 2008 16:04:45 -0000 1.101 +++ src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java 24 Nov 2008 12:59:14 -0000 @@ -107,18 +107,22 @@ " } \n" + "} \n" }, - "----------\n" + - "1. ERROR in p1\\X.java (at line 5)\n" + - " while (false) System.out.println(\"unreachable\"); \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + - "----------\n" + - "2. ERROR in p1\\X.java (at line 9)\n" + - " for (;false;) System.out.println(\"unreachable\"); \n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Unreachable code\n" + - "----------\n" - ); + "----------\n" + + "1. ERROR in p1\\X.java (at line 5)\n" + + " while (false) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 9)\n" + + " for (;false;) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. WARNING in p1\\X.java (at line 11)\n" + + " if (false)System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); } // binary compatibility public void test012() { Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v retrieving revision 1.181 diff -u -r1.181 BatchCompilerTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 20 Nov 2008 16:12:38 -0000 1.181 +++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 24 Nov 2008 12:59:13 -0000 @@ -1776,6 +1776,7 @@ "