### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java,v retrieving revision 1.97 diff -u -r1.97 QualifiedAllocationExpression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 25 Nov 2009 04:56:02 -0000 1.97 +++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 13 Jan 2010 15:31:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -104,6 +104,8 @@ } public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { + if (!valueRequired) + currentScope.problemReporter().unusedObjectAllocation(this); int pc = codeStream.position; MethodBinding codegenBinding = this.binding.original(); ReferenceBinding allocatedType = codegenBinding.declaringClass; #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.43 diff -u -r1.43 FlowAnalysisTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 13 Jan 2010 15:13:36 -0000 1.43 +++ src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 13 Jan 2010 15:31:27 -0000 @@ -27,7 +27,9 @@ import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; public class FlowAnalysisTest extends AbstractRegressionTest { - +static { +// TESTS_NUMBERS = new int[] { 69 }; +} public FlowAnalysisTest(String name) { super(name); } @@ -2069,7 +2071,6 @@ true /* shouldFlushOutputDirectory */, compilerOptions); } - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 // warning suppressed public void test065() { @@ -2160,7 +2161,32 @@ compilerOptions /* customOptions */, null /* clientRequestor */); } - +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 +//anonymous type +public void test069() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bar() { return false; } \n" + + " public void foo() {" + + " if (bar())\n" + + " new Object() {};\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new Object() {};\n" + + " ^^^^^^^^^^^^^^^\n" + + "The allocated object is never used\n" + + "----------\n", + null /* classLibraries */, + true /* shouldFlushOutputDirectory */, + compilerOptions); +} public static Class testClass() { return FlowAnalysisTest.class; }