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 155983 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]
Updated patch
patch_236385.txt (text/plain), 30.35 KB, created by
Olivier Thomann
on 2010-01-13 10:14:17 EST
(
hide
)
Description:
Updated patch
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-01-13 10:14:17 EST
Size:
30.35 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >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.348 >diff -u -r1.348 Main.java >--- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 4 Jan 2010 19:19:59 -0000 1.348 >+++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 13 Jan 2010 15:13:18 -0000 >@@ -10,6 +10,7 @@ > * Tom Tromey - Contribution for bug 125961 > * Tom Tromey - Contribution for bug 159641 > * Benjamin Muskalla - Contribution for bug 239066 >+ * Stephan Herrmann - Contribution for bug 236385 > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.batch; > >@@ -3450,6 +3451,9 @@ > } else if (token.equals("unusedImport") || token.equals("unusedImports")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$ > setSeverity(CompilerOptions.OPTION_ReportUnusedImport, severity, isEnabling); > return; >+ } else if (token.equals("unusedAllocation")) { //$NON-NLS-1$ >+ setSeverity(CompilerOptions.OPTION_ReportUnusedObjectAllocation, severity, isEnabling); >+ return; > } else if (token.equals("unusedPrivate")) { //$NON-NLS-1$ > setSeverity(CompilerOptions.OPTION_ReportUnusedPrivateMember, severity, isEnabling); > return; >Index: batch/org/eclipse/jdt/internal/compiler/batch/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties,v >retrieving revision 1.874 >diff -u -r1.874 messages.properties >--- batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 7 Jan 2010 20:18:49 -0000 1.874 >+++ batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 13 Jan 2010 15:13:18 -0000 >@@ -15,7 +15,7 @@ > #Format: compiler.name = word1 word2 word3 > compiler.name = Eclipse Compiler for Java(TM) > #Format: compiler.version = 0.XXX[, other words (don't forget the comma if adding other words)] >-compiler.version = 0.A30, 3.6.0 M5 >+compiler.version = 0.A31, 3.6.0 M5 > compiler.copyright = Copyright IBM Corp 2000, 2010. All rights reserved. > > ### progress >@@ -305,9 +305,10 @@ > \ unchecked + unchecked type operation\n\ > \ unnecessaryElse unnecessary else clause\n\ > \ unqualifiedField unqualified reference to field\n\ >-\ unused macro for unusedArgument, unusedImport, unusedLabel,\n\ >-\ unusedLocal, unusedPrivate, unusedThrown,\n\ >-\ and unusedTypeArgs\n\ >+\ unused macro for unusedAllocation, unusedArgument,\n\ >+\ unusedImport, unusedLabel, unusedLocal,\n\ >+\ unusedPrivate, unusedThrown, and unusedTypeArgs\n\ >+\ unusedAllocation allocating an object that is not used\n\ > \ unusedArgument unread method parameter\n\ > \ unusedImport + unused import declaration\n\ > \ unusedLabel + unused label\n\ >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.220 >diff -u -r1.220 IProblem.java >--- compiler/org/eclipse/jdt/core/compiler/IProblem.java 11 Nov 2009 19:28:04 -0000 1.220 >+++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 13 Jan 2010 15:13:18 -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 >@@ -115,7 +115,8 @@ > * RedundantSuperinterface > * Benjamin Muskalla - added the following constants > * MissingSynchronizedModifierInInheritedMethod >- * >+ * Stephan Herrmann - added the following constants >+ * UnusedObjectAllocation > *******************************************************************************/ > package org.eclipse.jdt.core.compiler; > >@@ -428,6 +429,8 @@ > int UnhandledExceptionInImplicitConstructorCall = TypeRelated + 147; > > // expressions >+ /** @since 3.6 */ >+ int UnusedObjectAllocation = Internal + 148; > /** @since 3.5 */ > int DeadCode = Internal + 149; > int ArrayReferenceRequired = Internal + 150; >Index: compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java,v >retrieving revision 1.82 >diff -u -r1.82 AllocationExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 25 Nov 2009 04:56:02 -0000 1.82 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 13 Jan 2010 15:13:18 -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 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Stephan Herrmann - Contribution for bug 236385 > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.ast; > >@@ -82,8 +83,11 @@ > } > > public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { >+ if (!valueRequired) >+ currentScope.problemReporter().unusedObjectAllocation(this); >+ > int pc = codeStream.position; >- MethodBinding codegenBinding = this.binding.original(); >+ MethodBinding codegenBinding = this.binding.original(); > ReferenceBinding allocatedType = codegenBinding.declaringClass; > > codeStream.new_(allocatedType); >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.228 >diff -u -r1.228 CompilerOptions.java >--- compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 12 Jan 2010 17:51:47 -0000 1.228 >+++ compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 13 Jan 2010 15:13:18 -0000 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Benjamin Muskalla - Contribution for bug 239066 >+ * Stephan Herrmann - Contribution for bug 236385 > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.impl; > >@@ -127,6 +128,7 @@ > public static final String OPTION_ReportDeadCode = "org.eclipse.jdt.core.compiler.problem.deadCode"; //$NON-NLS-1$ > public static final String OPTION_ReportDeadCodeInTrivialIfStatement = "org.eclipse.jdt.core.compiler.problem.deadCodeInTrivialIfStatement"; //$NON-NLS-1$ > public static final String OPTION_ReportTasks = "org.eclipse.jdt.core.compiler.problem.tasks"; //$NON-NLS-1$ >+ public static final String OPTION_ReportUnusedObjectAllocation = "org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation"; //$NON-NLS-1$ > > // Backward compatibility > public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$ >@@ -232,6 +234,7 @@ > public static final int ShouldImplementHashcode = IrritantSet.GROUP2 | ASTNode.Bit1; > public static final int DeadCode = IrritantSet.GROUP2 | ASTNode.Bit2; > public static final int Tasks = IrritantSet.GROUP2 | ASTNode.Bit3; >+ public static final int UnusedObjectAllocation = IrritantSet.GROUP2 | ASTNode.Bit4; > > // Severity level for handlers > /** >@@ -515,6 +518,8 @@ > return OPTION_ReportMissingHashCodeMethod; > case DeadCode : > return OPTION_ReportDeadCode; >+ case UnusedObjectAllocation: >+ return OPTION_ReportUnusedObjectAllocation; > } > return null; > } >@@ -641,6 +646,7 @@ > OPTION_ReportUnusedDeclaredThrownException, > OPTION_ReportUnusedImport, > OPTION_ReportUnusedLocal, >+ OPTION_ReportUnusedObjectAllocation, > OPTION_ReportUnusedParameter, > OPTION_ReportUnusedPrivateMember, > OPTION_ReportVarargsArgumentNeedCast, >@@ -701,6 +707,7 @@ > case UnusedPrivateMember : > case UnusedDeclaredThrownException : > case DeadCode : >+ case UnusedObjectAllocation : > return "unused"; //$NON-NLS-1$ > case DiscouragedReference : > case ForbiddenReference : >@@ -891,6 +898,7 @@ > optionsMap.put(OPTION_ReportDeadCode, getSeverityString(DeadCode)); > optionsMap.put(OPTION_ReportDeadCodeInTrivialIfStatement, this.reportDeadCodeInTrivialIfStatement ? ENABLED : DISABLED); > optionsMap.put(OPTION_ReportTasks, getSeverityString(Tasks)); >+ optionsMap.put(OPTION_ReportUnusedObjectAllocation, getSeverityString(UnusedObjectAllocation)); > return optionsMap; > } > >@@ -1287,6 +1295,7 @@ > if ((optionValue = optionsMap.get(OPTION_ReportMissingHashCodeMethod)) != null) updateSeverity(ShouldImplementHashcode, optionValue); > if ((optionValue = optionsMap.get(OPTION_ReportDeadCode)) != null) updateSeverity(DeadCode, optionValue); > if ((optionValue = optionsMap.get(OPTION_ReportTasks)) != null) updateSeverity(Tasks, optionValue); >+ if ((optionValue = optionsMap.get(OPTION_ReportUnusedObjectAllocation)) != null) updateSeverity(UnusedObjectAllocation, optionValue); > > // Javadoc options > if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) { >@@ -1488,6 +1497,7 @@ > buf.append("\n\t- dead code: ").append(getSeverityString(DeadCode)); //$NON-NLS-1$ > buf.append("\n\t- dead code in trivial if statement: ").append(this.reportDeadCodeInTrivialIfStatement ? ENABLED : DISABLED); //$NON-NLS-1$ > buf.append("\n\t- tasks severity: ").append(getSeverityString(Tasks)); //$NON-NLS-1$ >+ buf.append("\n\t- unused object allocation: ").append(getSeverityString(UnusedObjectAllocation)); //$NON-NLS-1$ > return buf.toString(); > } > >Index: compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java,v >retrieving revision 1.8 >diff -u -r1.8 IrritantSet.java >--- compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java 6 Oct 2009 19:24:18 -0000 1.8 >+++ compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java 13 Jan 2010 15:13:18 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 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 >@@ -117,7 +117,8 @@ > .set(CompilerOptions.UnusedImport) > .set(CompilerOptions.UnusedTypeArguments) > .set(CompilerOptions.RedundantSuperinterface) >- .set(CompilerOptions.DeadCode); >+ .set(CompilerOptions.DeadCode) >+ .set(CompilerOptions.UnusedObjectAllocation); > String suppressRawWhenUnchecked = System.getProperty("suppressRawWhenUnchecked"); //$NON-NLS-1$ > if (suppressRawWhenUnchecked != null && "true".equalsIgnoreCase(suppressRawWhenUnchecked)) { //$NON-NLS-1$ > UNCHECKED.set(CompilerOptions.RawTypeReference); >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.402 >diff -u -r1.402 ProblemReporter.java >--- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 23 Nov 2009 16:45:35 -0000 1.402 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 13 Jan 2010 15:13:18 -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 >@@ -414,6 +414,9 @@ > > case IProblem.Task : > return CompilerOptions.Tasks; >+ >+ case IProblem.UnusedObjectAllocation: >+ return CompilerOptions.UnusedObjectAllocation; > } > return 0; > } >@@ -484,6 +487,7 @@ > case CompilerOptions.UnusedWarningToken : > case CompilerOptions.UnusedLabel : > case CompilerOptions.RedundantSuperinterface : >+ case CompilerOptions.UnusedObjectAllocation : > return CategorizedProblem.CAT_UNNECESSARY_CODE; > > case CompilerOptions.UsingDeprecatedAPI : >@@ -7124,6 +7128,14 @@ > localDecl.sourceStart, > localDecl.sourceEnd); > } >+public void unusedObjectAllocation(AllocationExpression allocationExpression) { >+ this.handle( >+ IProblem.UnusedObjectAllocation, >+ NoArgument, >+ NoArgument, >+ allocationExpression.sourceStart, >+ allocationExpression.sourceEnd); >+} > public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) { > > int severity = computeSeverity(IProblem.UnusedPrivateConstructor); >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.255 >diff -u -r1.255 messages.properties >--- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 11 Nov 2009 19:28:04 -0000 1.255 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 13 Jan 2010 15:13:19 -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 >@@ -123,6 +123,8 @@ > 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 > >+ >+148 = The allocated object is never used > 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 >Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java,v >retrieving revision 1.78 >diff -u -r1.78 DefaultCodeFormatter.java >--- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java 28 Oct 2009 09:57:10 -0000 1.78 >+++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java 13 Jan 2010 15:13:19 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 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 >@@ -387,6 +387,7 @@ > optionsMap.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.DISABLED); > optionsMap.put(CompilerOptions.OPTION_ReportHiddenCatchBlock, CompilerOptions.IGNORE); > optionsMap.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); >+ optionsMap.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); > optionsMap.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.IGNORE); > optionsMap.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE); > optionsMap.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); >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.646 >diff -u -r1.646 JavaCore.java >--- model/org/eclipse/jdt/core/JavaCore.java 7 Jan 2010 14:39:42 -0000 1.646 >+++ model/org/eclipse/jdt/core/JavaCore.java 13 Jan 2010 15:13:19 -0000 >@@ -81,7 +81,9 @@ > * COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_EXEMPT_EXCEPTION_AND_THROWABLE > * IBM Corporation - added getOptionForConfigurableSeverity(int) > * Benjamin Muskalla - added COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD >+ * Stephan Herrmann - added COMPILER_PB_UNUSED_OBJECT_ALLOCATION > *******************************************************************************/ >+ > package org.eclipse.jdt.core; > > import java.util.ArrayList; >@@ -1542,6 +1544,19 @@ > */ > public static final String COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD = PLUGIN_ID + ".compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$ > /** >+ * Compiler option ID: Reporting Allocation of an Unused Object. >+ * <p>When enabled, the compiler will issue an error or a warning if an object is allocated but never used, >+ * neither by holding a reference nor by invoking one of the object's methods. >+ * <dl> >+ * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation"</code></dd> >+ * <dt>Possible values:</dt><dd><code>{ "error", "warning", "ignore" }</code></dd> >+ * <dt>Default:</dt><dd><code>"ignore"</code></dd> >+ * </dl> >+ * @since 3.6 >+ * @category CompilerOptionID >+ */ >+ public static final String COMPILER_PB_UNUSED_OBJECT_ALLOCATION = PLUGIN_ID + ".compiler.problem.unusedObjectAllocation"; //$NON-NLS-1$ >+ /** > * Core option ID: Computing Project Build Order. > * <p>Indicate whether JavaCore should enforce the project build order to be based on > * the classpath prerequisite chain. When requesting to compute, this takes over >#P org.eclipse.jdt.core.tests.compiler >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.201 >diff -u -r1.201 BatchCompilerTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 4 Jan 2010 19:28:16 -0000 1.201 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 13 Jan 2010 15:13:23 -0000 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Benjamin Muskalla - Contribution for bug 239066 >+ * Stephan Herrmann - Contribution for bug 236385 > *******************************************************************************/ > package org.eclipse.jdt.core.tests.compiler.regression; > >@@ -1703,9 +1704,10 @@ > " unchecked + unchecked type operation\n" + > " unnecessaryElse unnecessary else clause\n" + > " unqualifiedField unqualified reference to field\n" + >- " unused macro for unusedArgument, unusedImport, unusedLabel,\n" + >- " unusedLocal, unusedPrivate, unusedThrown,\n" + >- " and unusedTypeArgs\n" + >+ " unused macro for unusedAllocation, unusedArgument,\n" + >+ " unusedImport, unusedLabel, unusedLocal,\n" + >+ " unusedPrivate, unusedThrown, and unusedTypeArgs\n" + >+ " unusedAllocation allocating an object that is not used\n" + > " unusedArgument unread method parameter\n" + > " unusedImport + unused import declaration\n" + > " unusedLabel + unused label\n" + >@@ -1858,6 +1860,7 @@ > " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedImport\" value=\"warning\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedLabel\" value=\"warning\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedLocal\" value=\"warning\"/>\n" + >+ " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameter\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference\" value=\"enabled\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract\" value=\"disabled\"/>\n" + >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.33 >diff -u -r1.33 CompilerInvocationTests.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java 12 Nov 2009 17:37:03 -0000 1.33 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java 13 Jan 2010 15:13:23 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2009 IBM Corporation and others. >+ * Copyright (c) 2006, 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 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Benjamin Muskalla - Contribution for bug 239066 >+ * Stephan Herrmann - Contribution for bug 236385 > *******************************************************************************/ > package org.eclipse.jdt.core.tests.compiler.regression; > >@@ -843,6 +844,7 @@ > expectedProblemAttributes.put("UnusedImport", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); > expectedProblemAttributes.put("UnusedLabel", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); > expectedProblemAttributes.put("UnusedMethodDeclaredThrownException", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); >+ expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); > expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); > expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); > expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); >@@ -1475,6 +1477,7 @@ > expectedProblemAttributes.put("UnusedImport", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_IMPORT)); > expectedProblemAttributes.put("UnusedLabel", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_LABEL)); > expectedProblemAttributes.put("UnusedMethodDeclaredThrownException", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_WHEN_OVERRIDING)); >+ expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION)); > expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); > expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); > expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); >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.42 >diff -u -r1.42 FlowAnalysisTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 4 Jan 2010 19:28:16 -0000 1.42 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 13 Jan 2010 15:13:23 -0000 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Stephan Herrmann - Contribution for bug 236385 > *******************************************************************************/ > package org.eclipse.jdt.core.tests.compiler.regression; > >@@ -2016,6 +2017,150 @@ > "Unreachable code\n" + > "----------\n"); > } >+ >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 >+public void test063() { >+ 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 IllegalArgumentException(\"You must not bar!\");\n" + >+ " }\n" + >+ "}", >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " new IllegalArgumentException(\"You must not bar!\");\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "The allocated object is never used\n" + >+ "----------\n", >+ null /* classLibraries */, >+ true /* shouldFlushOutputDirectory */, >+ compilerOptions); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 >+// non-throwable type >+public void test064() { >+ 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 String(\"You must not bar!\");\n" + >+ " }\n" + >+ "}", >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " new String(\"You must not bar!\");\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "The allocated object is never used\n" + >+ "----------\n", >+ null /* classLibraries */, >+ true /* shouldFlushOutputDirectory */, >+ compilerOptions); >+} >+ >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 >+// warning suppressed >+public void test065() { >+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; >+ Map compilerOptions = getCompilerOptions(); >+ compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.WARNING); >+ runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " boolean bar() { return false; }\n" + >+ " @SuppressWarnings(\"unused\")\n" + >+ " public void foo() {" + >+ " if (bar())\n" + >+ " new IllegalArgumentException(\"You must not bar!\");\n" + >+ " }\n" + >+ "}", >+ }, >+ "" /* expectedOutputString */, >+ null /* classLib */, >+ true /* shouldFlushOutputDirectory */, >+ null /* vmArguments */, >+ compilerOptions /* customOptions */, >+ null /* clientRequestor */); >+} >+ >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 >+// warning ignored (default) >+public void test066() { >+ runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " boolean bar() { return false; }\n" + >+ " public void foo() {" + >+ " if (bar())\n" + >+ " new IllegalArgumentException(\"You must not bar!\");\n" + >+ " }\n" + >+ "}", >+ }, >+ "" /* expectedOutputString */); >+} >+ >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 >+// instance is assigned >+public void test067() { >+ Map compilerOptions = getCompilerOptions(); >+ compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.ERROR); >+ runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " boolean bar() { return false; }\n" + >+ " Throwable t;\n" + >+ " public void foo() {" + >+ " t = new IllegalArgumentException(\"You must not bar!\");\n" + >+ " }\n" + >+ "}", >+ }, >+ "" /* expectedOutputString */, >+ null /* classLib */, >+ true /* shouldFlushOutputDirectory */, >+ null /* vmArguments */, >+ compilerOptions /* customOptions */, >+ null /* clientRequestor */); >+} >+ >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 >+// method invoked >+public void test068() { >+ Map compilerOptions = getCompilerOptions(); >+ compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.ERROR); >+ runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " boolean bar() { return false; }\n" + >+ " public void foo() {" + >+ " if (bar())\n" + >+ " new IllegalArgumentException(\"You must not bar!\").printStackTrace();\n" + >+ " }\n" + >+ "}", >+ }, >+ "" /* expectedOutputString */, >+ null /* classLib */, >+ true /* shouldFlushOutputDirectory */, >+ null /* vmArguments */, >+ compilerOptions /* customOptions */, >+ null /* clientRequestor */); >+} >+ > 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