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

Collapse All | Expand All

(-)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 (-2 / +4 lines)
Lines 97-103 Link Here
97
			// group-2 warnings enabled by default
97
			// group-2 warnings enabled by default
98
			.set(
98
			.set(
99
				CompilerOptions.DeadCode
99
				CompilerOptions.DeadCode
100
				|CompilerOptions.Tasks);
100
				|CompilerOptions.Tasks
101
				|CompilerOptions.UnusedObjectAllocation);
101
			
102
			
102
		ALL.setAll();
103
		ALL.setAll();
103
		HIDING
104
		HIDING
Lines 117-123 Link Here
117
			.set(CompilerOptions.UnusedImport)
118
			.set(CompilerOptions.UnusedImport)
118
			.set(CompilerOptions.UnusedTypeArguments)
119
			.set(CompilerOptions.UnusedTypeArguments)
119
			.set(CompilerOptions.RedundantSuperinterface)
120
			.set(CompilerOptions.RedundantSuperinterface)
120
			.set(CompilerOptions.DeadCode);
121
			.set(CompilerOptions.DeadCode)
122
			.set(CompilerOptions.UnusedObjectAllocation);
121
		String suppressRawWhenUnchecked = System.getProperty("suppressRawWhenUnchecked"); //$NON-NLS-1$
123
		String suppressRawWhenUnchecked = System.getProperty("suppressRawWhenUnchecked"); //$NON-NLS-1$
122
		if (suppressRawWhenUnchecked != null && "true".equalsIgnoreCase(suppressRawWhenUnchecked)) { //$NON-NLS-1$
124
		if (suppressRawWhenUnchecked != null && "true".equalsIgnoreCase(suppressRawWhenUnchecked)) { //$NON-NLS-1$
123
			UNCHECKED.set(CompilerOptions.RawTypeReference);
125
			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 464-469 Link Here
464
			case CompilerOptions.MissingSynchronizedModifierInInheritedMethod :
467
			case CompilerOptions.MissingSynchronizedModifierInInheritedMethod :
465
			case CompilerOptions.ShouldImplementHashcode :
468
			case CompilerOptions.ShouldImplementHashcode :
466
			case CompilerOptions.DeadCode :
469
			case CompilerOptions.DeadCode :
470
			case CompilerOptions.UnusedObjectAllocation :
467
				return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM;
471
				return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM;
468
			
472
			
469
			case CompilerOptions.OverriddenPackageDefaultMethod :
473
			case CompilerOptions.OverriddenPackageDefaultMethod :
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 = Allocating an object that 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
(-)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 1541-1546 Link Here
1541
	 */
1543
	 */
1542
	public static final String COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD = PLUGIN_ID + ".compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$
1544
	public static final String COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD = PLUGIN_ID + ".compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$
1543
	/**
1545
	/**
1546
	 * Compiler option ID: Reporting Allocation of an Unused Object.
1547
	 * <p>When enabled, the compiler will issue an error or a warning if an object is allocated but never used,
1548
	 * neither by holding a reference nor by invoking one of the object's methods.
1549
	 * <dl>
1550
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation"</code></dd>
1551
	 * <dt>Possible values:</dt><dd><code>{ "error", "warning", "ignore" }</code></dd>
1552
	 * <dt>Default:</dt><dd><code>"warning"</code></dd>
1553
	 * </dl>
1554
	 * @since 3.6
1555
	 * @category CompilerOptionID
1556
	 */
1557
	public static final String COMPILER_PB_UNUSED_OBJECT_ALLOCATION = PLUGIN_ID + ".compiler.problem.unusedObjectAllocation";  //$NON-NLS-1$
1558
	/**
1544
	 * Core option ID: Computing Project Build Order.
1559
	 * Core option ID: Computing Project Build Order.
1545
	 * <p>Indicate whether JavaCore should enforce the project build order to be based on
1560
	 * <p>Indicate whether JavaCore should enforce the project build order to be based on
1546
	 *    the classpath prerequisite chain. When requesting to compute, this takes over
1561
	 *    the classpath prerequisite chain. When requesting to compute, this takes over
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (+1 lines)
Lines 1856-1861 Link Here
1856
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedImport\" value=\"warning\"/>\n" +
1856
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedImport\" value=\"warning\"/>\n" +
1857
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedLabel\" value=\"warning\"/>\n" +
1857
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedLabel\" value=\"warning\"/>\n" +
1858
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedLocal\" value=\"warning\"/>\n" +
1858
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedLocal\" value=\"warning\"/>\n" +
1859
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation\" value=\"warning\"/>\n" +
1859
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameter\" value=\"ignore\"/>\n" +
1860
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameter\" value=\"ignore\"/>\n" +
1860
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference\" value=\"enabled\"/>\n" +
1861
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference\" value=\"enabled\"/>\n" +
1861
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract\" value=\"disabled\"/>\n" +
1862
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract\" value=\"disabled\"/>\n" +
(-)src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java (+2 lines)
Lines 843-848 Link Here
843
		expectedProblemAttributes.put("UnusedImport", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
843
		expectedProblemAttributes.put("UnusedImport", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
844
		expectedProblemAttributes.put("UnusedLabel", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
844
		expectedProblemAttributes.put("UnusedLabel", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
845
		expectedProblemAttributes.put("UnusedMethodDeclaredThrownException", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
845
		expectedProblemAttributes.put("UnusedMethodDeclaredThrownException", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
846
		expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
846
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
847
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
847
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
848
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
848
		expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
849
		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));
1476
		expectedProblemAttributes.put("UnusedImport", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_IMPORT));
1476
		expectedProblemAttributes.put("UnusedLabel", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_LABEL));
1477
		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));
1478
		expectedProblemAttributes.put("UnusedMethodDeclaredThrownException", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_WHEN_OVERRIDING));
1479
		expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION));
1478
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1480
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1479
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1481
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1480
		expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1482
		expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
(-)src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java (+118 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 2021-2026 Link Here
2021
		"Unreachable code\n" + 
2022
		"Unreachable code\n" + 
2022
		"----------\n");
2023
		"----------\n");
2023
}
2024
}
2025
2026
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2027
public void test063() {
2028
	runNegativeTest(
2029
		new String[] {
2030
			"X.java",
2031
			"public class X {\n" +
2032
			"   boolean bar() { return false; } \n" +
2033
			"	public void foo() {" +
2034
			"		if (bar())\n" +
2035
			"			new IllegalArgumentException(\"You must not bar!\");\n" +
2036
			"	}\n" +
2037
			"}",
2038
		},
2039
		"----------\n" + 
2040
		"1. WARNING in X.java (at line 4)\n" + 
2041
		"	new IllegalArgumentException(\"You must not bar!\");\n" + 
2042
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
2043
		"Allocating an object that is never used\n" + 
2044
		"----------\n");
2045
}
2046
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2047
// non-throwable type
2048
public void test064() {
2049
	runNegativeTest(
2050
		new String[] {
2051
			"X.java",
2052
			"public class X {\n" +
2053
			"   boolean bar() { return false; } \n" +
2054
			"	public void foo() {" +
2055
			"		if (bar())\n" +
2056
			"			new String(\"You must not bar!\");\n" +
2057
			"	}\n" +
2058
			"}",
2059
		},
2060
		"----------\n" + 
2061
		"1. WARNING in X.java (at line 4)\n" + 
2062
		"	new String(\"You must not bar!\");\n" + 
2063
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
2064
		"Allocating an object that is never used\n" + 
2065
		"----------\n");
2066
}
2067
2068
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2069
// warning suppressed
2070
public void test065() {
2071
	if (this.complianceLevel < ClassFileConstants.JDK1_5) return;
2072
	runConformTest(
2073
		new String[] {
2074
			"X.java",
2075
			"public class X {\n" +
2076
			"   boolean bar() { return false; }\n" +
2077
			"   @SuppressWarnings(\"unused\")\n" +
2078
			"	public void foo() {" +
2079
			"		if (bar())\n" +
2080
			"			new IllegalArgumentException(\"You must not bar!\");\n" +
2081
			"	}\n" +
2082
			"}",
2083
		});
2084
}
2085
2086
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2087
// warning ignored
2088
public void test066() {
2089
	Map compilerOptions = getCompilerOptions();
2090
	compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE);
2091
	runConformTest(
2092
		new String[] {
2093
			"X.java",
2094
			"public class X {\n" +
2095
			"   boolean bar() { return false; }\n" +
2096
			"	public void foo() {" +
2097
			"		if (bar())\n" +
2098
			"			new IllegalArgumentException(\"You must not bar!\");\n" +
2099
			"	}\n" +
2100
			"}",
2101
		},
2102
		"" /* expectedOutputString */,
2103
		null /* classLib */,
2104
		true /* shouldFlushOutputDirectory */, 
2105
		null /* vmArguments */, 
2106
		compilerOptions /* customOptions */,
2107
		null /* clientRequestor */);
2108
}
2109
2110
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2111
// instance is assigned
2112
public void test067() {
2113
	runConformTest(
2114
		new String[] {
2115
			"X.java",
2116
			"public class X {\n" +
2117
			"   boolean bar() { return false; }\n" +
2118
			"   Throwable t;\n" +
2119
			"	public void foo() {" +
2120
			"		t = new IllegalArgumentException(\"You must not bar!\");\n" +
2121
			"	}\n" +
2122
			"}",
2123
		});
2124
}
2125
2126
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385
2127
// method invoked
2128
public void test068() {
2129
	runConformTest(
2130
		new String[] {
2131
			"X.java",
2132
			"public class X {\n" +
2133
			"   boolean bar() { return false; }\n" +
2134
			"	public void foo() {" +
2135
			"		if (bar())\n" +
2136
			"			new IllegalArgumentException(\"You must not bar!\").printStackTrace();\n" +
2137
			"	}\n" +
2138
			"}",
2139
		});
2140
}
2141
2024
public static Class testClass() {
2142
public static Class testClass() {
2025
	return FlowAnalysisTest.class;
2143
	return FlowAnalysisTest.class;
2026
}
2144
}

Return to bug 236385