View | Details | Raw Unified | Return to bug 236385 | Differences between
and this patch

Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (+4 lines)
Lines 10-15 Link Here
10
 *     Tom Tromey - Contribution for bug 125961
10
 *     Tom Tromey - Contribution for bug 125961
11
 *     Tom Tromey - Contribution for bug 159641
11
 *     Tom Tromey - Contribution for bug 159641
12
 *     Benjamin Muskalla - Contribution for bug 239066
12
 *     Benjamin Muskalla - Contribution for bug 239066
13
 *     Stephan Herrmann  - Contribution for bug 236385
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.internal.compiler.batch;
15
package org.eclipse.jdt.internal.compiler.batch;
15
16
Lines 3450-3455 Link Here
3450
			} else if (token.equals("unusedImport") || token.equals("unusedImports")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
3451
			} else if (token.equals("unusedImport") || token.equals("unusedImports")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
3451
				setSeverity(CompilerOptions.OPTION_ReportUnusedImport, severity, isEnabling);
3452
				setSeverity(CompilerOptions.OPTION_ReportUnusedImport, severity, isEnabling);
3452
				return;
3453
				return;
3454
			} else if (token.equals("unusedAllocation")) { //$NON-NLS-1$
3455
				setSeverity(CompilerOptions.OPTION_ReportUnusedObjectAllocation, severity, isEnabling);
3456
				return;
3453
			} else if (token.equals("unusedPrivate")) { //$NON-NLS-1$
3457
			} else if (token.equals("unusedPrivate")) { //$NON-NLS-1$
3454
				setSeverity(CompilerOptions.OPTION_ReportUnusedPrivateMember, severity, isEnabling);
3458
				setSeverity(CompilerOptions.OPTION_ReportUnusedPrivateMember, severity, isEnabling);
3455
				return;
3459
				return;
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (-3 / +4 lines)
Lines 305-313 Link Here
305
\      unchecked          + unchecked type operation\n\
305
\      unchecked          + unchecked type operation\n\
306
\      unnecessaryElse      unnecessary else clause\n\
306
\      unnecessaryElse      unnecessary else clause\n\
307
\      unqualifiedField     unqualified reference to field\n\
307
\      unqualifiedField     unqualified reference to field\n\
308
\      unused               macro for unusedArgument, unusedImport, unusedLabel,\n\
308
\      unused               macro for unusedAllocation, unusedArgument,\n\
309
\                               unusedLocal, unusedPrivate, unusedThrown,\n\
309
\                               unusedImport, unusedLabel, unusedLocal,\n\
310
\                               and unusedTypeArgs\n\
310
\                               unusedPrivate, unusedThrown, and unusedTypeArgs\n\
311
\      unusedAllocation     allocating an object that is not used\n\
311
\      unusedArgument       unread method parameter\n\
312
\      unusedArgument       unread method parameter\n\
312
\      unusedImport       + unused import declaration\n\
313
\      unusedImport       + unused import declaration\n\
313
\      unusedLabel        + unused label\n\
314
\      unusedLabel        + unused label\n\
(-)compiler/org/eclipse/jdt/core/compiler/IProblem.java (-1 / +4 lines)
Lines 115-121 Link Here
115
 *								   RedundantSuperinterface
115
 *								   RedundantSuperinterface
116
 *		Benjamin Muskalla - added the following constants
116
 *		Benjamin Muskalla - added the following constants
117
 *									MissingSynchronizedModifierInInheritedMethod
117
 *									MissingSynchronizedModifierInInheritedMethod
118
 *									
118
 *		Stephan Herrmann  - added the following constants
119
 *									UnusedObjectAllocation									
119
 *******************************************************************************/
120
 *******************************************************************************/
120
package org.eclipse.jdt.core.compiler;
121
package org.eclipse.jdt.core.compiler;
121
122
Lines 428-433 Link Here
428
	int UnhandledExceptionInImplicitConstructorCall = TypeRelated + 147;
429
	int UnhandledExceptionInImplicitConstructorCall = TypeRelated + 147;
429
430
430
	// expressions
431
	// expressions
432
	/** @since 3.6 */
433
	int UnusedObjectAllocation = Internal + 148;
431
	/** @since 3.5 */
434
	/** @since 3.5 */
432
	int DeadCode = Internal + 149;
435
	int DeadCode = Internal + 149;
433
	int ArrayReferenceRequired = Internal + 150;
436
	int ArrayReferenceRequired = Internal + 150;
(-)compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java (-1 / +5 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann - Contribution for bug 236385
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
12
package org.eclipse.jdt.internal.compiler.ast;
12
13
Lines 82-89 Link Here
82
}
83
}
83
84
84
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
85
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
86
	if (!valueRequired)
87
		currentScope.problemReporter().unusedObjectAllocation(this);
88
85
	int pc = codeStream.position;
89
	int pc = codeStream.position;
86
	 MethodBinding codegenBinding = this.binding.original();
90
	MethodBinding codegenBinding = this.binding.original();
87
	ReferenceBinding allocatedType = codegenBinding.declaringClass;
91
	ReferenceBinding allocatedType = codegenBinding.declaringClass;
88
92
89
	codeStream.new_(allocatedType);
93
	codeStream.new_(allocatedType);
(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (+10 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Muskalla - Contribution for bug 239066
10
 *     Benjamin Muskalla - Contribution for bug 239066
11
 *     Stephan Herrmann  - Contribution for bug 236385
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.internal.compiler.impl;
13
package org.eclipse.jdt.internal.compiler.impl;
13
14
Lines 127-132 Link Here
127
	public static final String OPTION_ReportDeadCode =  "org.eclipse.jdt.core.compiler.problem.deadCode"; //$NON-NLS-1$
128
	public static final String OPTION_ReportDeadCode =  "org.eclipse.jdt.core.compiler.problem.deadCode"; //$NON-NLS-1$
128
	public static final String OPTION_ReportDeadCodeInTrivialIfStatement =  "org.eclipse.jdt.core.compiler.problem.deadCodeInTrivialIfStatement"; //$NON-NLS-1$
129
	public static final String OPTION_ReportDeadCodeInTrivialIfStatement =  "org.eclipse.jdt.core.compiler.problem.deadCodeInTrivialIfStatement"; //$NON-NLS-1$
129
	public static final String OPTION_ReportTasks = "org.eclipse.jdt.core.compiler.problem.tasks"; //$NON-NLS-1$
130
	public static final String OPTION_ReportTasks = "org.eclipse.jdt.core.compiler.problem.tasks"; //$NON-NLS-1$
131
	public static final String OPTION_ReportUnusedObjectAllocation = "org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation";  //$NON-NLS-1$
130
132
131
	// Backward compatibility
133
	// Backward compatibility
132
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
134
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
Lines 232-237 Link Here
232
	public static final int ShouldImplementHashcode = IrritantSet.GROUP2 | ASTNode.Bit1;
234
	public static final int ShouldImplementHashcode = IrritantSet.GROUP2 | ASTNode.Bit1;
233
	public static final int DeadCode = IrritantSet.GROUP2 | ASTNode.Bit2;
235
	public static final int DeadCode = IrritantSet.GROUP2 | ASTNode.Bit2;
234
	public static final int Tasks = IrritantSet.GROUP2 | ASTNode.Bit3;
236
	public static final int Tasks = IrritantSet.GROUP2 | ASTNode.Bit3;
237
	public static final int UnusedObjectAllocation = IrritantSet.GROUP2 | ASTNode.Bit4;
235
238
236
	// Severity level for handlers
239
	// Severity level for handlers
237
	/** 
240
	/** 
Lines 515-520 Link Here
515
				return OPTION_ReportMissingHashCodeMethod;
518
				return OPTION_ReportMissingHashCodeMethod;
516
			case DeadCode :
519
			case DeadCode :
517
				return OPTION_ReportDeadCode;
520
				return OPTION_ReportDeadCode;
521
			case UnusedObjectAllocation:
522
				return OPTION_ReportUnusedObjectAllocation;
518
		}
523
		}
519
		return null;
524
		return null;
520
	}
525
	}
Lines 641-646 Link Here
641
			OPTION_ReportUnusedDeclaredThrownException,
646
			OPTION_ReportUnusedDeclaredThrownException,
642
			OPTION_ReportUnusedImport,
647
			OPTION_ReportUnusedImport,
643
			OPTION_ReportUnusedLocal,
648
			OPTION_ReportUnusedLocal,
649
			OPTION_ReportUnusedObjectAllocation,
644
			OPTION_ReportUnusedParameter,
650
			OPTION_ReportUnusedParameter,
645
			OPTION_ReportUnusedPrivateMember,
651
			OPTION_ReportUnusedPrivateMember,
646
			OPTION_ReportVarargsArgumentNeedCast,
652
			OPTION_ReportVarargsArgumentNeedCast,
Lines 701-706 Link Here
701
			case UnusedPrivateMember :
707
			case UnusedPrivateMember :
702
			case UnusedDeclaredThrownException :
708
			case UnusedDeclaredThrownException :
703
			case DeadCode :
709
			case DeadCode :
710
			case UnusedObjectAllocation :
704
				return "unused"; //$NON-NLS-1$
711
				return "unused"; //$NON-NLS-1$
705
			case DiscouragedReference :
712
			case DiscouragedReference :
706
			case ForbiddenReference :
713
			case ForbiddenReference :
Lines 891-896 Link Here
891
		optionsMap.put(OPTION_ReportDeadCode, getSeverityString(DeadCode));
898
		optionsMap.put(OPTION_ReportDeadCode, getSeverityString(DeadCode));
892
		optionsMap.put(OPTION_ReportDeadCodeInTrivialIfStatement, this.reportDeadCodeInTrivialIfStatement ? ENABLED : DISABLED);
899
		optionsMap.put(OPTION_ReportDeadCodeInTrivialIfStatement, this.reportDeadCodeInTrivialIfStatement ? ENABLED : DISABLED);
893
		optionsMap.put(OPTION_ReportTasks, getSeverityString(Tasks));
900
		optionsMap.put(OPTION_ReportTasks, getSeverityString(Tasks));
901
		optionsMap.put(OPTION_ReportUnusedObjectAllocation, getSeverityString(UnusedObjectAllocation));
894
		return optionsMap;
902
		return optionsMap;
895
	}
903
	}
896
904
Lines 1287-1292 Link Here
1287
		if ((optionValue = optionsMap.get(OPTION_ReportMissingHashCodeMethod)) != null) updateSeverity(ShouldImplementHashcode, optionValue);
1295
		if ((optionValue = optionsMap.get(OPTION_ReportMissingHashCodeMethod)) != null) updateSeverity(ShouldImplementHashcode, optionValue);
1288
		if ((optionValue = optionsMap.get(OPTION_ReportDeadCode)) != null) updateSeverity(DeadCode, optionValue);
1296
		if ((optionValue = optionsMap.get(OPTION_ReportDeadCode)) != null) updateSeverity(DeadCode, optionValue);
1289
		if ((optionValue = optionsMap.get(OPTION_ReportTasks)) != null) updateSeverity(Tasks, optionValue);
1297
		if ((optionValue = optionsMap.get(OPTION_ReportTasks)) != null) updateSeverity(Tasks, optionValue);
1298
		if ((optionValue = optionsMap.get(OPTION_ReportUnusedObjectAllocation)) != null) updateSeverity(UnusedObjectAllocation, optionValue);
1290
1299
1291
		// Javadoc options
1300
		// Javadoc options
1292
		if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) {
1301
		if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) {
Lines 1488-1493 Link Here
1488
		buf.append("\n\t- dead code: ").append(getSeverityString(DeadCode)); //$NON-NLS-1$
1497
		buf.append("\n\t- dead code: ").append(getSeverityString(DeadCode)); //$NON-NLS-1$
1489
		buf.append("\n\t- dead code in trivial if statement: ").append(this.reportDeadCodeInTrivialIfStatement ? ENABLED : DISABLED); //$NON-NLS-1$
1498
		buf.append("\n\t- dead code in trivial if statement: ").append(this.reportDeadCodeInTrivialIfStatement ? ENABLED : DISABLED); //$NON-NLS-1$
1490
		buf.append("\n\t- tasks severity: ").append(getSeverityString(Tasks)); //$NON-NLS-1$
1499
		buf.append("\n\t- tasks severity: ").append(getSeverityString(Tasks)); //$NON-NLS-1$
1500
		buf.append("\n\t- unused object allocation: ").append(getSeverityString(UnusedObjectAllocation)); //$NON-NLS-1$
1491
		return buf.toString();
1501
		return buf.toString();
1492
	}
1502
	}
1493
	
1503
	
(-)compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java (-1 / +2 lines)
Lines 117-123 Link Here
117
			.set(CompilerOptions.UnusedImport)
117
			.set(CompilerOptions.UnusedImport)
118
			.set(CompilerOptions.UnusedTypeArguments)
118
			.set(CompilerOptions.UnusedTypeArguments)
119
			.set(CompilerOptions.RedundantSuperinterface)
119
			.set(CompilerOptions.RedundantSuperinterface)
120
			.set(CompilerOptions.DeadCode);
120
			.set(CompilerOptions.DeadCode)
121
			.set(CompilerOptions.UnusedObjectAllocation);
121
		String suppressRawWhenUnchecked = System.getProperty("suppressRawWhenUnchecked"); //$NON-NLS-1$
122
		String suppressRawWhenUnchecked = System.getProperty("suppressRawWhenUnchecked"); //$NON-NLS-1$
122
		if (suppressRawWhenUnchecked != null && "true".equalsIgnoreCase(suppressRawWhenUnchecked)) { //$NON-NLS-1$
123
		if (suppressRawWhenUnchecked != null && "true".equalsIgnoreCase(suppressRawWhenUnchecked)) { //$NON-NLS-1$
123
			UNCHECKED.set(CompilerOptions.RawTypeReference);
124
			UNCHECKED.set(CompilerOptions.RawTypeReference);
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+12 lines)
Lines 414-419 Link Here
414
			
414
			
415
		case IProblem.Task :
415
		case IProblem.Task :
416
			return CompilerOptions.Tasks;
416
			return CompilerOptions.Tasks;
417
418
		case IProblem.UnusedObjectAllocation:
419
			return CompilerOptions.UnusedObjectAllocation;
417
	}
420
	}
418
	return 0;
421
	return 0;
419
}
422
}
Lines 484-489 Link Here
484
			case CompilerOptions.UnusedWarningToken :
487
			case CompilerOptions.UnusedWarningToken :
485
			case CompilerOptions.UnusedLabel :
488
			case CompilerOptions.UnusedLabel :
486
			case CompilerOptions.RedundantSuperinterface :	
489
			case CompilerOptions.RedundantSuperinterface :	
490
			case CompilerOptions.UnusedObjectAllocation :
487
				return CategorizedProblem.CAT_UNNECESSARY_CODE;
491
				return CategorizedProblem.CAT_UNNECESSARY_CODE;
488
492
489
			case CompilerOptions.UsingDeprecatedAPI :
493
			case CompilerOptions.UsingDeprecatedAPI :
Lines 7124-7129 Link Here
7124
		localDecl.sourceStart,
7128
		localDecl.sourceStart,
7125
		localDecl.sourceEnd);
7129
		localDecl.sourceEnd);
7126
}
7130
}
7131
public void unusedObjectAllocation(AllocationExpression allocationExpression) {
7132
	this.handle(
7133
		IProblem.UnusedObjectAllocation, 
7134
		NoArgument, 
7135
		NoArgument, 
7136
		allocationExpression.sourceStart, 
7137
		allocationExpression.sourceEnd);
7138
}
7127
public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
7139
public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
7128
7140
7129
	int severity = computeSeverity(IProblem.UnusedPrivateConstructor);
7141
	int severity = computeSeverity(IProblem.UnusedPrivateConstructor);
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (+2 lines)
Lines 123-128 Link Here
123
146 = Default constructor cannot handle exception type {0} thrown by implicit super constructor. Must define an explicit constructor
123
146 = Default constructor cannot handle exception type {0} thrown by implicit super constructor. Must define an explicit constructor
124
147 = Unhandled exception type {0} thrown by implicit super constructor
124
147 = Unhandled exception type {0} thrown by implicit super constructor
125
125
126
127
148 = The allocated object is never used
126
149 = Dead code
128
149 = Dead code
127
150 = The type of the expression must be an array type but it resolved to {0}
129
150 = The type of the expression must be an array type but it resolved to {0}
128
151 = Must explicitly convert the char[] to a String
130
151 = Must explicitly convert the char[] to a String
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java (+1 lines)
Lines 387-392 Link Here
387
			optionsMap.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.DISABLED);
387
			optionsMap.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.DISABLED);
388
			optionsMap.put(CompilerOptions.OPTION_ReportHiddenCatchBlock, CompilerOptions.IGNORE);
388
			optionsMap.put(CompilerOptions.OPTION_ReportHiddenCatchBlock, CompilerOptions.IGNORE);
389
			optionsMap.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE);
389
			optionsMap.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE);
390
			optionsMap.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE);
390
			optionsMap.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.IGNORE);
391
			optionsMap.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.IGNORE);
391
			optionsMap.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
392
			optionsMap.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
392
			optionsMap.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE);
393
			optionsMap.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE);
(-)model/org/eclipse/jdt/core/JavaCore.java (+15 lines)
Lines 81-87 Link Here
81
 *                                 COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_EXEMPT_EXCEPTION_AND_THROWABLE
81
 *                                 COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_EXEMPT_EXCEPTION_AND_THROWABLE
82
 *     IBM Corporation - added getOptionForConfigurableSeverity(int)
82
 *     IBM Corporation - added getOptionForConfigurableSeverity(int)
83
 *     Benjamin Muskalla - added COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD
83
 *     Benjamin Muskalla - added COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD
84
 *     Stephan Herrmann  - added COMPILER_PB_UNUSED_OBJECT_ALLOCATION
84
 *******************************************************************************/
85
 *******************************************************************************/
86
85
package org.eclipse.jdt.core;
87
package org.eclipse.jdt.core;
86
88
87
import java.util.ArrayList;
89
import java.util.ArrayList;
Lines 1542-1547 Link Here
1542
	 */
1544
	 */
1543
	public static final String COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD = PLUGIN_ID + ".compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$
1545
	public static final String COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD = PLUGIN_ID + ".compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$
1544
	/**
1546
	/**
1547
	 * Compiler option ID: Reporting Allocation of an Unused Object.
1548
	 * <p>When enabled, the compiler will issue an error or a warning if an object is allocated but never used,
1549
	 * neither by holding a reference nor by invoking one of the object's methods.
1550
	 * <dl>
1551
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation"</code></dd>
1552
	 * <dt>Possible values:</dt><dd><code>{ "error", "warning", "ignore" }</code></dd>
1553
	 * <dt>Default:</dt><dd><code>"ignore"</code></dd>
1554
	 * </dl>
1555
	 * @since 3.6
1556
	 * @category CompilerOptionID
1557
	 */
1558
	public static final String COMPILER_PB_UNUSED_OBJECT_ALLOCATION = PLUGIN_ID + ".compiler.problem.unusedObjectAllocation";  //$NON-NLS-1$
1559
	/**
1545
	 * Core option ID: Computing Project Build Order.
1560
	 * Core option ID: Computing Project Build Order.
1546
	 * <p>Indicate whether JavaCore should enforce the project build order to be based on
1561
	 * <p>Indicate whether JavaCore should enforce the project build order to be based on
1547
	 *    the classpath prerequisite chain. When requesting to compute, this takes over
1562
	 *    the classpath prerequisite chain. When requesting to compute, this takes over
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (-3 / +6 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Muskalla - Contribution for bug 239066
10
 *     Benjamin Muskalla - Contribution for bug 239066
11
 *     Stephan Herrmann  - Contribution for bug 236385
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.core.tests.compiler.regression;
13
package org.eclipse.jdt.core.tests.compiler.regression;
13
14
Lines 1703-1711 Link Here
1703
        "      unchecked          + unchecked type operation\n" +
1704
        "      unchecked          + unchecked type operation\n" +
1704
        "      unnecessaryElse      unnecessary else clause\n" +
1705
        "      unnecessaryElse      unnecessary else clause\n" +
1705
        "      unqualifiedField     unqualified reference to field\n" +
1706
        "      unqualifiedField     unqualified reference to field\n" +
1706
        "      unused               macro for unusedArgument, unusedImport, unusedLabel,\n" +
1707
        "      unused               macro for unusedAllocation, unusedArgument,\n" +
1707
        "                               unusedLocal, unusedPrivate, unusedThrown,\n" +
1708
        "                               unusedImport, unusedLabel, unusedLocal,\n" +
1708
        "                               and unusedTypeArgs\n" +
1709
        "                               unusedPrivate, unusedThrown, and unusedTypeArgs\n" +
1710
        "      unusedAllocation     allocating an object that is not used\n" +
1709
        "      unusedArgument       unread method parameter\n" +
1711
        "      unusedArgument       unread method parameter\n" +
1710
        "      unusedImport       + unused import declaration\n" +
1712
        "      unusedImport       + unused import declaration\n" +
1711
        "      unusedLabel        + unused label\n" +
1713
        "      unusedLabel        + unused label\n" +
Lines 1858-1863 Link Here
1858
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedImport\" value=\"warning\"/>\n" +
1860
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedImport\" value=\"warning\"/>\n" +
1859
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedLabel\" value=\"warning\"/>\n" +
1861
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedLabel\" value=\"warning\"/>\n" +
1860
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedLocal\" value=\"warning\"/>\n" +
1862
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedLocal\" value=\"warning\"/>\n" +
1863
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation\" value=\"ignore\"/>\n" +
1861
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameter\" value=\"ignore\"/>\n" +
1864
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameter\" value=\"ignore\"/>\n" +
1862
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference\" value=\"enabled\"/>\n" +
1865
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference\" value=\"enabled\"/>\n" +
1863
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract\" value=\"disabled\"/>\n" +
1866
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract\" value=\"disabled\"/>\n" +
(-)src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java (+3 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Muskalla - Contribution for bug 239066
10
 *     Benjamin Muskalla - Contribution for bug 239066
11
 *     Stephan Herrmann  - Contribution for bug 236385
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.core.tests.compiler.regression;
13
package org.eclipse.jdt.core.tests.compiler.regression;
13
14
Lines 843-848 Link Here
843
		expectedProblemAttributes.put("UnusedImport", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
844
		expectedProblemAttributes.put("UnusedImport", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
844
		expectedProblemAttributes.put("UnusedLabel", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
845
		expectedProblemAttributes.put("UnusedLabel", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
845
		expectedProblemAttributes.put("UnusedMethodDeclaredThrownException", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
846
		expectedProblemAttributes.put("UnusedMethodDeclaredThrownException", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
847
		expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
846
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
848
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
847
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
849
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
848
		expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
850
		expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
Lines 1475-1480 Link Here
1475
		expectedProblemAttributes.put("UnusedImport", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_IMPORT));
1477
		expectedProblemAttributes.put("UnusedImport", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_IMPORT));
1476
		expectedProblemAttributes.put("UnusedLabel", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_LABEL));
1478
		expectedProblemAttributes.put("UnusedLabel", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_LABEL));
1477
		expectedProblemAttributes.put("UnusedMethodDeclaredThrownException", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_WHEN_OVERRIDING));
1479
		expectedProblemAttributes.put("UnusedMethodDeclaredThrownException", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_WHEN_OVERRIDING));
1480
		expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION));
1478
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1481
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1479
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1482
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1480
		expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1483
		expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
(-)src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java (+145 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann - Contribution for bug 236385
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 2016-2021 Link Here
2016
		"Unreachable code\n" + 
2017
		"Unreachable code\n" + 
2017
		"----------\n");
2018
		"----------\n");
2018
}
2019
}
2020
2021
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2022
public void test063() {
2023
	Map compilerOptions = getCompilerOptions();
2024
	compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.WARNING);
2025
	runNegativeTest(
2026
		new String[] {
2027
			"X.java",
2028
			"public class X {\n" +
2029
			"   boolean bar() { return false; } \n" +
2030
			"	public void foo() {" +
2031
			"		if (bar())\n" +
2032
			"			new IllegalArgumentException(\"You must not bar!\");\n" +
2033
			"	}\n" +
2034
			"}",
2035
		},
2036
		"----------\n" + 
2037
		"1. WARNING in X.java (at line 4)\n" + 
2038
		"	new IllegalArgumentException(\"You must not bar!\");\n" + 
2039
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
2040
		"The allocated object is never used\n" + 
2041
		"----------\n",
2042
		null /* classLibraries */,
2043
		true /* shouldFlushOutputDirectory */,
2044
		compilerOptions);
2045
}
2046
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2047
// non-throwable type
2048
public void test064() {
2049
	Map compilerOptions = getCompilerOptions();
2050
	compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.WARNING);
2051
	runNegativeTest(
2052
		new String[] {
2053
			"X.java",
2054
			"public class X {\n" +
2055
			"   boolean bar() { return false; } \n" +
2056
			"	public void foo() {" +
2057
			"		if (bar())\n" +
2058
			"			new String(\"You must not bar!\");\n" +
2059
			"	}\n" +
2060
			"}",
2061
		},
2062
		"----------\n" + 
2063
		"1. WARNING in X.java (at line 4)\n" + 
2064
		"	new String(\"You must not bar!\");\n" + 
2065
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
2066
		"The allocated object is never used\n" + 
2067
		"----------\n",
2068
		null /* classLibraries */,
2069
		true /* shouldFlushOutputDirectory */,
2070
		compilerOptions);
2071
}
2072
2073
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2074
// warning suppressed
2075
public void test065() {
2076
	if (this.complianceLevel < ClassFileConstants.JDK1_5) return;
2077
	Map compilerOptions = getCompilerOptions();
2078
	compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.WARNING);
2079
	runConformTest(
2080
		new String[] {
2081
			"X.java",
2082
			"public class X {\n" +
2083
			"   boolean bar() { return false; }\n" +
2084
			"   @SuppressWarnings(\"unused\")\n" +
2085
			"	public void foo() {" +
2086
			"		if (bar())\n" +
2087
			"			new IllegalArgumentException(\"You must not bar!\");\n" +
2088
			"	}\n" +
2089
			"}",
2090
		},
2091
		"" /* expectedOutputString */,
2092
		null /* classLib */,
2093
		true /* shouldFlushOutputDirectory */, 
2094
		null /* vmArguments */, 
2095
		compilerOptions /* customOptions */,
2096
		null /* clientRequestor */);
2097
}
2098
2099
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2100
// warning ignored (default)
2101
public void test066() {
2102
	runConformTest(
2103
		new String[] {
2104
			"X.java",
2105
			"public class X {\n" +
2106
			"   boolean bar() { return false; }\n" +
2107
			"	public void foo() {" +
2108
			"		if (bar())\n" +
2109
			"			new IllegalArgumentException(\"You must not bar!\");\n" +
2110
			"	}\n" +
2111
			"}",
2112
		},
2113
		"" /* expectedOutputString */);
2114
}
2115
2116
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2117
// instance is assigned
2118
public void test067() {
2119
	Map compilerOptions = getCompilerOptions();
2120
	compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.WARNING);
2121
	runConformTest(
2122
		new String[] {
2123
			"X.java",
2124
			"public class X {\n" +
2125
			"   boolean bar() { return false; }\n" +
2126
			"   Throwable t;\n" +
2127
			"	public void foo() {" +
2128
			"		t = new IllegalArgumentException(\"You must not bar!\");\n" +
2129
			"	}\n" +
2130
			"}",
2131
		},
2132
		"" /* expectedOutputString */,
2133
		null /* classLib */,
2134
		true /* shouldFlushOutputDirectory */, 
2135
		null /* vmArguments */, 
2136
		compilerOptions /* customOptions */,
2137
		null /* clientRequestor */);
2138
}
2139
2140
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2141
// method invoked
2142
public void test068() {
2143
	Map compilerOptions = getCompilerOptions();
2144
	compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.WARNING);
2145
	runConformTest(
2146
		new String[] {
2147
			"X.java",
2148
			"public class X {\n" +
2149
			"   boolean bar() { return false; }\n" +
2150
			"	public void foo() {" +
2151
			"		if (bar())\n" +
2152
			"			new IllegalArgumentException(\"You must not bar!\").printStackTrace();\n" +
2153
			"	}\n" +
2154
			"}",
2155
		},
2156
		"" /* expectedOutputString */,
2157
		null /* classLib */,
2158
		true /* shouldFlushOutputDirectory */, 
2159
		null /* vmArguments */, 
2160
		compilerOptions /* customOptions */,
2161
		null /* clientRequestor */);
2162
}
2163
2019
public static Class testClass() {
2164
public static Class testClass() {
2020
	return FlowAnalysisTest.class;
2165
	return FlowAnalysisTest.class;
2021
}
2166
}

Return to bug 236385