diff options
| author | Stephan Herrmann | 2015-03-14 17:37:31 +0000 |
|---|---|---|
| committer | Stephan Herrmann | 2015-03-14 17:37:31 +0000 |
| commit | d516022cc45faaf269239c9a3eb11f62f3444f69 (patch) | |
| tree | 8000b64b4c7442ae5e39f848866c12954654b388 | |
| parent | 27e2724327c75ddbe7646447a4af212947b149ed (diff) | |
| download | eclipse.jdt.core-d516022cc45faaf269239c9a3eb11f62f3444f69.tar.gz eclipse.jdt.core-d516022cc45faaf269239c9a3eb11f62f3444f69.tar.xz eclipse.jdt.core-d516022cc45faaf269239c9a3eb11f62f3444f69.zip | |
Bug 408815 - [batch][null] Add CLI option for
COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS
Change-Id: I92fe482db7160b0ead59f17f28e15760c8976d4b
Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
3 files changed, 73 insertions, 2 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 a4c3c1d4a2..ae38a2c798 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 @@ -26,6 +26,7 @@ * Bug 392099 - [1.8][compiler][null] Apply null annotation on types for null analysis * Bug 440477 - [null] Infrastructure for feeding external annotations into compilation * Bug 440687 - [compiler][batch][null] improve command line option for external annotations + * Bug 408815 - [batch][null] Add CLI option for COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS * Jesper Steen Moller - Contributions for * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code * bug 407297 - [1.8][compiler] Control generation of parameter names by option @@ -78,7 +79,7 @@ public class BatchCompilerTest extends AbstractRegressionTest { "import java.lang.annotation.*;\n" + "@Documented\n" + "@Retention(RetentionPolicy.CLASS)\n" + - "@Target({ METHOD, PARAMETER })\n" + + "@Target({ METHOD, PARAMETER, FIELD })\n" + "public @interface Nullable{\n" + "}\n"; private static final String NONNULL_ANNOTATION_CONTENT = "package org.eclipse.jdt.annotation;\n" + @@ -86,7 +87,7 @@ public class BatchCompilerTest extends AbstractRegressionTest { "import java.lang.annotation.*;\n" + "@Documented\n" + "@Retention(RetentionPolicy.CLASS)\n" + - "@Target({ METHOD, PARAMETER })\n" + + "@Target({ METHOD, PARAMETER, FIELD })\n" + "public @interface NonNull{\n" + "}\n"; @@ -1861,12 +1862,14 @@ public void test012b(){ " errors and warnings\n" + " switchDefault + switch statement lacking a default case\n" + " syncOverride missing synchronized in synchr. method override\n" + + " syntacticAnalysis perform syntax-based null analysis for fields\n" + " syntheticAccess synthetic access for innerclass\n" + " tasks(<tags separated by |>) tasks identified by tags inside comments\n" + " typeHiding + type parameter hiding another type\n" + " unavoidableGenericProblems + ignore unavoidable type safety problems\n" + " due to raw APIs\n" + " unchecked + unchecked type operation\n" + + " unlikelyArgumentType invoking Map.get() et al with an unlikely argument\n" + " unnecessaryElse unnecessary else clause\n" + " unqualifiedField unqualified reference to field\n" + " unused macro for unusedAllocation, unusedArgument,\n" + @@ -12902,6 +12905,39 @@ public void test316_warn_options() { true); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=408815 +// -warn option - regression tests to check option syntacticAnalysis +// Null warnings because of annotations, null spec violations, suppressed by null-check +public void test316b_warn_options() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object f;\n" + + " @NonNull Object foo() {\n" + + " if (this.f != null)\n" + + " return this.f;\n" + + " return this;\n" + + " }\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+nullAnnot -warn:+null,syntacticAnalysis -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 // -warn/-error option : enumSwitchPedantic public void test317_warn_options() { @@ -13385,6 +13421,29 @@ public void test329_nowarn_options() { true); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=408815 +// -warn option - regression tests to check option unlikelyArgumentType +public void test330_warn_options() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " Integer foo(Map<String,Integer> map) {\n" + + " return map.get(3);\n" + + " }\n" + + "}\n", + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:-unlikelyArgumentType -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375409 public void testBug375409a() { this.runConformTest( diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java index 5abfda081a..2dc326d878 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -21,6 +21,7 @@ * bug 381443 - [compiler][null] Allow parameter widening from @NonNull to unannotated * Bug 440477 - [null] Infrastructure for feeding external annotations into compilation * Bug 440687 - [compiler][batch][null] improve command line option for external annotations + * Bug 408815 - [batch][null] Add CLI option for COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS * Jesper S Moller - Contributions for * bug 407297 - [1.8][compiler] Control generation of parameter names by option * Mat Booth - Contribution for bug 405176 @@ -3829,6 +3830,11 @@ private void handleErrorOrWarningToken(String token, boolean isEnabling, int sev } else if (token.equals("switchDefault")) { //$NON-NLS-1$ setSeverity(CompilerOptions.OPTION_ReportMissingDefaultCase, severity, isEnabling); return; + } else if (token.equals("syntacticAnalysis")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_SyntacticNullAnalysisForFields, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; } break; case 't' : @@ -3882,6 +3888,9 @@ private void handleErrorOrWarningToken(String token, boolean isEnabling, int sev } else if (token.equals("unchecked") || token.equals("unsafe")) {//$NON-NLS-1$ //$NON-NLS-2$ setSeverity(CompilerOptions.OPTION_ReportUncheckedTypeOperation, severity, isEnabling); return; + } else if (token.equals("unlikelyArgumentType")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportDiscouragedInvocationIncompatibleArgument, severity, isEnabling); + return; } else if (token.equals("unnecessaryElse")) {//$NON-NLS-1$ setSeverity(CompilerOptions.OPTION_ReportUnnecessaryElse, severity, isEnabling); return; diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties index 26a0c843eb..ced9ca188e 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties @@ -16,6 +16,7 @@ # bug 374605 - Unreasonable warning for enum-based switch statements # bug 388281 - [compiler][null] inheritance of null annotations as an option # bug 440687 - [compiler][batch][null] improve command line option for external annotations +# Bug 408815 - [batch][null] Add CLI option for COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS # Alan Moraes <alan@kelon.org> - Contribution for bug 383644 # Jesper S Moller - Contribution for bug 407297 - [1.8][compiler] Control generation of parameter names by option ############################################################################### @@ -384,12 +385,14 @@ misc.usage.warn = {1} {2}\n\ \ errors and warnings\n\ \ switchDefault + switch statement lacking a default case\n\ \ syncOverride missing synchronized in synchr. method override\n\ +\ syntacticAnalysis perform syntax-based null analysis for fields\n\ \ syntheticAccess synthetic access for innerclass\n\ \ tasks(<tags separated by |>) tasks identified by tags inside comments\n\ \ typeHiding + type parameter hiding another type\n\ \ unavoidableGenericProblems + ignore unavoidable type safety problems\n\ \ due to raw APIs\n\ \ unchecked + unchecked type operation\n\ +\ unlikelyArgumentType invoking Map.get() et al with an unlikely argument\n\ \ unnecessaryElse unnecessary else clause\n\ \ unqualifiedField unqualified reference to field\n\ \ unused macro for unusedAllocation, unusedArgument,\n\ |
