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 81477 Details for
Bug 207758
[1.5][compiler] Unused SupressWarnings detection should consider more error situations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
work in progress
207758.txt (text/plain), 19.13 KB, created by
Philipe Mulet
on 2007-10-29 13:37:48 EDT
(
hide
)
Description:
work in progress
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2007-10-29 13:37:48 EDT
Size:
19.13 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java,v >retrieving revision 1.74 >diff -u -r1.74 CompilationUnitDeclaration.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 27 Oct 2007 17:33:14 -0000 1.74 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 29 Oct 2007 17:36:14 -0000 >@@ -15,6 +15,7 @@ > > import org.eclipse.jdt.core.compiler.CategorizedProblem; > import org.eclipse.jdt.core.compiler.CharOperation; >+import org.eclipse.jdt.core.compiler.IProblem; > import org.eclipse.jdt.internal.compiler.ASTVisitor; > import org.eclipse.jdt.internal.compiler.ClassFile; > import org.eclipse.jdt.internal.compiler.CompilationResult; >@@ -207,34 +208,36 @@ > CategorizedProblem[] problems = this.compilationResult.problems; > int problemCount = this.compilationResult.problemCount; > long[] foundIrritants = new long[this.suppressWarningsCount]; >+ CompilerOptions options = scope.compilerOptions(); >+ boolean hasErrors = false; > nextProblem: for (int iProblem = 0, length = problemCount; iProblem < length; iProblem++) { > CategorizedProblem problem = problems[iProblem]; > int problemID = problem.getID(); >- long problemIrritant = ProblemReporter.getIrritant(problemID); >- boolean isWarning = problem.isWarning(); >+ if (problem.isError()) { >+ if (problemID != IProblem.UnusedWarningToken) { >+ // tolerate unused warning tokens which were promoted as errors >+ hasErrors = true; >+ } >+ continue; >+ } > int start = problem.getSourceStart(); > int end = problem.getSourceEnd(); >+ long irritant = ProblemReporter.getIrritant(problemID); > nextSuppress: for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) { > long position = this.suppressWarningScopePositions[iSuppress]; > int startSuppress = (int) (position >>> 32); > int endSuppress = (int) position; > if (start < startSuppress) continue nextSuppress; > if (end > endSuppress) continue nextSuppress; >- if (isWarning) { >- if ((problemIrritant & this.suppressWarningIrritants[iSuppress]) == 0) >- continue nextSuppress; >- // discard suppressed warning >- removed++; >- problems[iProblem] = null; >- if (compilationResult.problemsMap != null) compilationResult.problemsMap.remove(problem); >- if (compilationResult.firstErrors != null) compilationResult.firstErrors.remove(problem); >- foundIrritants[iSuppress] |= problemIrritant; >- continue nextProblem; >- } else { >- // any error may prevent further warnings to be emitted, hence shouldn't report unused warning tokens if in same scope >- foundIrritants[iSuppress] = this.suppressWarningIrritants[iSuppress]; // treat as used >- continue nextSuppress; >- } >+ if ((irritant & this.suppressWarningIrritants[iSuppress]) == 0) >+ continue nextSuppress; >+ // discard suppressed warning >+ removed++; >+ problems[iProblem] = null; >+ if (compilationResult.problemsMap != null) compilationResult.problemsMap.remove(problem); >+ if (compilationResult.firstErrors != null) compilationResult.firstErrors.remove(problem); >+ foundIrritants[iSuppress] |= irritant; >+ continue nextProblem; > } > } > // compact remaining problems >@@ -251,28 +254,52 @@ > } > this.compilationResult.problemCount -= removed; > } >- // flag SuppressWarnings which had no effect >- if (scope.compilerOptions().getSeverity(CompilerOptions.UnusedWarningToken) != ProblemSeverities.Ignore) { >- for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) { >- Annotation annotation = this.suppressWarningAnnotations[iSuppress]; >- if (annotation == null) continue; // implicit annotation >- long irritants = this.suppressWarningIrritants[iSuppress]; >- if (~irritants == 0) continue; // @SuppressWarnings("all") also suppresses unused warning token >- if (irritants != foundIrritants[iSuppress]) { // mismatch, some warning tokens were unused >- MemberValuePair[] pairs = annotation.memberValuePairs(); >- pairLoop: for (int iPair = 0, pairCount = pairs.length; iPair < pairCount; iPair++) { >- MemberValuePair pair = pairs[iPair]; >- if (CharOperation.equals(pair.name, TypeConstants.VALUE)) { >- Expression value = pair.value; >- if (value instanceof ArrayInitializer) { >- ArrayInitializer initializer = (ArrayInitializer) value; >- Expression[] inits = initializer.expressions; >- if (inits != null) { >- for (int iToken = 0, tokenCount = inits.length; iToken < tokenCount; iToken++) { >- Constant cst = inits[iToken].constant; >- if (cst != Constant.NotAConstant && cst.typeID() == TypeIds.T_JavaLangString) { >- long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue()); >- if (irritant != 0 && (foundIrritants[iSuppress] & irritant) == 0) { >+ // flag SuppressWarnings which had no effect (only if no (mandatory) error got detected within unit >+ if (!hasErrors) { >+ int severity = options.getSeverity(CompilerOptions.UnusedWarningToken); >+ if (severity != ProblemSeverities.Ignore) { >+ for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) { >+ Annotation annotation = this.suppressWarningAnnotations[iSuppress]; >+ if (annotation == null) continue; // implicit annotation >+ long irritants = this.suppressWarningIrritants[iSuppress]; >+ if (severity == ProblemSeverities.Warning && ~irritants == 0) continue; // @SuppressWarnings("all") also suppresses unused warning token >+ if (irritants != foundIrritants[iSuppress]) { // mismatch, some warning tokens were unused >+ MemberValuePair[] pairs = annotation.memberValuePairs(); >+ pairLoop: for (int iPair = 0, pairCount = pairs.length; iPair < pairCount; iPair++) { >+ MemberValuePair pair = pairs[iPair]; >+ if (CharOperation.equals(pair.name, TypeConstants.VALUE)) { >+ Expression value = pair.value; >+ if (value instanceof ArrayInitializer) { >+ ArrayInitializer initializer = (ArrayInitializer) value; >+ Expression[] inits = initializer.expressions; >+ if (inits != null) { >+ for (int iToken = 0, tokenCount = inits.length; iToken < tokenCount; iToken++) { >+ Constant cst = inits[iToken].constant; >+ if (cst != Constant.NotAConstant && cst.typeID() == TypeIds.T_JavaLangString) { >+ long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue()); >+ if (irritant != 0 && (foundIrritants[iSuppress] & irritant) == 0) { >+ if (severity == ProblemSeverities.Warning) { >+ int start = value.sourceStart, end = value.sourceEnd; >+ nextSuppress: for (int jSuppress = iSuppress - 1; jSuppress >= 0; jSuppress--) { >+ long position = this.suppressWarningScopePositions[jSuppress]; >+ int startSuppress = (int) (position >>> 32); >+ int endSuppress = (int) position; >+ if (start < startSuppress) continue nextSuppress; >+ if (end > endSuppress) continue nextSuppress; >+ if (~this.suppressWarningIrritants[jSuppress] == 0) break pairLoop; // suppress all? >+ } >+ } >+ scope.problemReporter().unusedWarningToken(inits[iToken]); >+ } >+ } >+ } >+ } >+ } else { >+ Constant cst = value.constant; >+ if (cst != Constant.NotAConstant && cst.typeID() == T_JavaLangString) { >+ long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue()); >+ if (irritant != 0 && (foundIrritants[iSuppress] & irritant) == 0) { >+ if (severity == ProblemSeverities.Warning) { > int start = value.sourceStart, end = value.sourceEnd; > nextSuppress: for (int jSuppress = iSuppress - 1; jSuppress >= 0; jSuppress--) { > long position = this.suppressWarningScopePositions[jSuppress]; >@@ -282,30 +309,13 @@ > if (end > endSuppress) continue nextSuppress; > if (~this.suppressWarningIrritants[jSuppress] == 0) break pairLoop; // suppress all? > } >- scope.problemReporter().unusedWarningToken(inits[iToken]); > } >+ scope.problemReporter().unusedWarningToken(value); > } >- } >+ } > } >- } else { >- Constant cst = value.constant; >- if (cst != Constant.NotAConstant && cst.typeID() == T_JavaLangString) { >- long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue()); >- if (irritant != 0 && (foundIrritants[iSuppress] & irritant) == 0) { >- int start = value.sourceStart, end = value.sourceEnd; >- nextSuppress: for (int jSuppress = iSuppress - 1; jSuppress >= 0; jSuppress--) { >- long position = this.suppressWarningScopePositions[jSuppress]; >- int startSuppress = (int) (position >>> 32); >- int endSuppress = (int) position; >- if (start < startSuppress) continue nextSuppress; >- if (end > endSuppress) continue nextSuppress; >- if (~this.suppressWarningIrritants[jSuppress] == 0) break pairLoop; // suppress all? >- } >- scope.problemReporter().unusedWarningToken(value); >- } >- } >+ break pairLoop; > } >- break pairLoop; > } > } > } >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java,v >retrieving revision 1.167 >diff -u -r1.167 AnnotationTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java 27 Oct 2007 07:33:56 -0000 1.167 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java 29 Oct 2007 17:36:16 -0000 >@@ -7627,6 +7627,9 @@ > " @SuppressWarnings(\"unchecked\") //unused\n" + > " void doNoEvil(){\n" + > " }\n" + >+ "}\n", >+ "Y.java", >+ "public class Y {\n" + > " Zork z;\n" + > "}\n", > }, >@@ -7636,7 +7639,8 @@ > " ^^^^^^^^^^^\n" + > "Unnecessary @SuppressWarnings(\"unchecked\")\n" + > "----------\n" + >- "2. ERROR in X.java (at line 5)\n" + >+ "----------\n" + >+ "1. ERROR in Y.java (at line 2)\n" + > " Zork z;\n" + > " ^^^^\n" + > "Zork cannot be resolved to a type\n" + >@@ -7665,6 +7669,8 @@ > > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation > public void test230() { >+ Map options = this.getCompilerOptions(); >+ options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); > this.runNegativeTest( > new String[] { > "X.java", >@@ -7675,7 +7681,7 @@ > "@SuppressWarnings({\"all\"})\n" + > "class X2 {\n" + > " @SuppressWarnings({\"zork\", \"unused\" })\n" + >- " Zork foo() {}\n" + >+ " void foo() {}\n" + > "}\n", > }, > "----------\n" + >@@ -7684,20 +7690,25 @@ > " ^^^^^^\n" + > "Unsupported @SuppressWarnings(\"zork\")\n" + > "----------\n" + >- "2. WARNING in X.java (at line 2)\n" + >+ "2. ERROR in X.java (at line 2)\n" + > " @SuppressWarnings({\"zork\", \"unused\" })\n" + > " ^^^^^^^^\n" + > "Unnecessary @SuppressWarnings(\"unused\")\n" + > "----------\n" + >- "3. ERROR in X.java (at line 8)\n" + >- " Zork foo() {}\n" + >- " ^^^^\n" + >- "Zork cannot be resolved to a type\n" + >- "----------\n"); >+ "3. ERROR in X.java (at line 7)\n" + >+ " @SuppressWarnings({\"zork\", \"unused\" })\n" + >+ " ^^^^^^^^\n" + >+ "Unnecessary @SuppressWarnings(\"unused\")\n" + >+ "----------\n", >+ null, >+ false, >+ options); > } > > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation > public void test231() { >+ Map options = this.getCompilerOptions(); >+ options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); > this.runNegativeTest( > new String[] { > "X.java", >@@ -7710,19 +7721,34 @@ > "class X2 {\n" + > " @SuppressWarnings(\"unused\")\n" + > " void foo() {}\n" + >- " Zork z;\n" + >+ " Object z;\n" + > "}\n", > }, > "----------\n" + >- "1. ERROR in X.java (at line 10)\n" + >- " Zork z;\n" + >- " ^^^^\n" + >- "Zork cannot be resolved to a type\n" + >- "----------\n"); >+ "1. ERROR in X.java (at line 2)\n" + >+ " @SuppressWarnings({\"zork\", \"unused\",\"all\"})\n" + >+ " ^^^^^^^^\n" + >+ "Unnecessary @SuppressWarnings(\"unused\")\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 6)\n" + >+ " @SuppressWarnings({\"all\"})\n" + >+ " ^^^^^\n" + >+ "Unnecessary @SuppressWarnings(\"all\")\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 8)\n" + >+ " @SuppressWarnings(\"unused\")\n" + >+ " ^^^^^^^^\n" + >+ "Unnecessary @SuppressWarnings(\"unused\")\n" + >+ "----------\n", >+ null, >+ false, >+ options); > } > > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation > public void test232() { >+ Map options = this.getCompilerOptions(); >+ options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); > this.runNegativeTest( > new String[] { > "X.java", >@@ -7736,19 +7762,17 @@ > " }\n" + > " }\n" + > "}\n" + >- "class Y extends Zork{}", >+ "class Y {}", > }, > "----------\n" + >- "1. WARNING in X.java (at line 2)\n" + >+ "1. ERROR in X.java (at line 2)\n" + > " @SuppressWarnings({\"finally\",\"finally\"})\n" + > " ^^^^^^^^^\n" + > "Unnecessary @SuppressWarnings(\"finally\")\n" + >- "----------\n" + >- "2. ERROR in X.java (at line 11)\n" + >- " class Y extends Zork{}\n" + >- " ^^^^\n" + >- "Zork cannot be resolved to a type\n" + >- "----------\n"); >+ "----------\n", >+ null, >+ false, >+ options); > } > > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation >@@ -7799,4 +7823,101 @@ > "Zork cannot be resolved\n" + > "----------\n"); > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207758 >+public void test235() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.List;\n" + >+ "public class X {\n" + >+ " void foo() {\n" + >+ " ArrayList al = null;\n" + >+ " @SuppressWarnings(\"unchecked\")\n" + >+ " List<String> ls = al;\n" + >+ " }\n" + >+ "}", >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " ArrayList al = null;\n" + >+ " ^^^^^^^^^\n" + >+ "ArrayList cannot be resolved to a type\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207758 - variation >+public void test236() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.List;\n" + >+ "public class X {\n" + >+ " void foo() {\n" + >+ " @SuppressWarnings(\"unchecked\")\n" + >+ " List<String> ls = bar();\n" + >+ " }\n" + >+ " ArrayList bar() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}", >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " List<String> ls = bar();\n" + >+ " ^^^\n" + >+ "The method bar() is undefined for the type X\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 7)\n" + >+ " ArrayList bar() {\n" + >+ " ^^^^^^^^^\n" + >+ "ArrayList cannot be resolved to a type\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207758 - variation >+public void test237() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.List;\n" + >+ "public class X<B extends ArrayList> {\n" + >+ " B get() { return null; }\n" + >+ " void foo() {\n" + >+ " @SuppressWarnings(\"unchecked\")\n" + >+ " List<String> ls = get();\n" + >+ " }\n" + >+ "}", >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 2)\n" + >+ " public class X<B extends ArrayList> {\n" + >+ " ^^^^^^^^^\n" + >+ "ArrayList cannot be resolved to a type\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 6)\n" + >+ " List<String> ls = get();\n" + >+ " ^^^^^\n" + >+ "Type mismatch: cannot convert from B to List<String>\n" + >+ "----------\n"); >+} >+public void test238() { >+ // check that if promoted to ERROR, unhandled warning token shouldn't be suppressed by @SuppressWarnings("all") >+ Map options = this.getCompilerOptions(); >+ options.put(CompilerOptions.OPTION_ReportUnhandledWarningToken, CompilerOptions.ERROR); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " @SuppressWarnings({\"zork\",\"all\"})\n" + >+ " void foo() {}\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 2)\n" + >+ " @SuppressWarnings({\"zork\",\"all\"})\n" + >+ " ^^^^^^\n" + >+ "Unsupported @SuppressWarnings(\"zork\")\n" + >+ "----------\n", >+ null, >+ false, >+ options); >+} > } >Index: src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java,v >retrieving revision 1.55 >diff -u -r1.55 VarargsTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java 27 Oct 2007 07:33:55 -0000 1.55 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java 29 Oct 2007 17:36:17 -0000 >@@ -1918,17 +1918,12 @@ > " ^^^^\n" + > "Zork cannot be resolved to a type\n" + > "----------\n" + >- "2. WARNING in X.java (at line 17)\n" + >- " @SuppressWarnings(\"boxing\")\n" + >- " ^^^^^^^^\n" + >- "Unnecessary @SuppressWarnings(\"boxing\")\n" + >- "----------\n" + >- "3. WARNING in X.java (at line 19)\n" + >+ "2. WARNING in X.java (at line 19)\n" + > " varargs(i);\n" + > " ^^^^^^^^^^\n" + > "The argument of type Integer[] should explicitly be cast to Object[] for the invocation of the varargs method varargs(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" + > "----------\n" + >- "4. WARNING in X.java (at line 22)\n" + >+ "3. WARNING in X.java (at line 22)\n" + > " varargs(i.clone());\n" + > " ^^^^^^^^^^^^^^^^^^\n" + > "The argument of type Integer[] should explicitly be cast to Object[] for the invocation of the varargs method varargs(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" +
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 207758
: 81477