Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression')
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java9
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java5
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java145
3 files changed, 155 insertions, 4 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
index bd218a09e6..c431241279 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
@@ -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 @@ public void test012b(){
" 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 @@ public void test012b(){
" <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" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index 5d913181a8..1b57c22c66 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
@@ -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 @@ public void test011_problem_categories() {
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 @@ public void test012_compiler_problems_tuning() {
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));
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java
index a3d9b1438b..f7c4af4720 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java
@@ -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 @@ public void test062() {
"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;
}

Back to the top