Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 155989 Details for
Bug 236385
[compiler] Warn for potential programming problem if an object is created but not used
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Same patch with a regression test
patch_236385_2.txt (text/plain), 3.43 KB, created by
Olivier Thomann
on 2010-01-13 10:31:57 EST
(
hide
)
Description:
Same patch with a regression test
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-01-13 10:31:57 EST
Size:
3.43 KB
patch
obsolete
>### 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; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 236385
:
110739
|
111358
|
153869
|
155923
|
155983
|
155987
| 155989 |
156030