List of usage examples for org.eclipse.jdt.internal.compiler.impl CompilerOptions OPTION_ReportNullReference
String OPTION_ReportNullReference
To view the source code for org.eclipse.jdt.internal.compiler.impl CompilerOptions OPTION_ReportNullReference.
Click Source Link
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
protected Map getCompilerOptions() { Map defaultOptions = super.getCompilerOptions(); if (setNullRelatedOptions) { defaultOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); defaultOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); defaultOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); defaultOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); defaultOptions.put(CompilerOptions.OPTION_IncludeNullInfoFromAsserts, CompilerOptions.ENABLED); defaultOptions.put(/*from ww w . j a va2 s. c om*/ CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); // enable null annotations: defaultOptions.put(NullCompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED); // leave other new options at these defaults: // defaultOptions.put(CompilerOptions.OPTION_ReportNullSpecViolation, CompilerOptions.ERROR); // defaultOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, CompilerOptions.ERROR); // defaultOptions.put(CompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.WARNING); // defaultOptions.put(CompilerOptions.OPTION_ReportRedundantNullAnnotation, CompilerOptions.WARNING); // defaultOptions.put(CompilerOptions.OPTION_NullableAnnotationName, "org.eclipse.jdt.annotation.Nullable"); // defaultOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "org.eclipse.jdt.annotation.NonNull"); } return defaultOptions; }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_parameter_specification_inheritance_010() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runConformTestWithLibs(/*w w w. ja va2 s .com*/ new String[] { "p1/X.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "@NonNullByDefault\n" + "public class X {\n" + " protected String getString(String s) {\n" + " if (Character.isLowerCase(s.charAt(0)))\n" + " return getString(s);\n" + " return s;\n" + " }\n" + "}\n", "p1/Y.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "@NonNullByDefault\n" + "public class Y extends X {\n" + " @Override\n" + " protected String getString(String s) {\n" + " return super.getString(s);\n" + " }\n" + "}\n", }, customOptions, ""); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_parameter_specification_inheritance_011() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runNegativeTestWithLibs(/* w ww. j av a 2s . c o m*/ new String[] { "p1/X.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "@NonNullByDefault\n" + "public class X {\n" + " protected String getString(String s) {\n" + " if (Character.isLowerCase(s.charAt(0)))\n" + " return getString(s);\n" + " return s;\n" + " }\n" + "}\n", "p1/Y.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "@NonNullByDefault\n" + "public class Y extends X {\n" + " @Override\n" + " protected String getString(String s) {\n" + " return super.getString(null);\n" + " }\n" + "}\n", }, customOptions, "----------\n" + "1. ERROR in p1\\Y.java (at line 7)\n" + " return super.getString(null);\n" + " ^^^^\n" + "Type mismatch: required \'@NonNull String\' but the provided value is null\n" + "----------\n"); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_parameter_specification_inheritance_012() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runConformTestWithLibs(new String[] { "p1/X.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "public class X {\n" + " public @Nullable String getString(String s1, @Nullable String s2, @NonNull String s3) {\n" + " return s1;\n" + " }\n" + "}\n", "p1/IY.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "public interface IY {\n" + " @NonNull String getString(@NonNull String s1, @NonNull String s2, @Nullable String s3);\n" + "}\n", "p1/Y.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "public class Y extends X implements IY {\n" + " @Override\n" + " public @NonNull String getString(@Nullable String s1, @Nullable String s2, @Nullable String s3) {\n" + " return \"\";\n" + " }\n" + "}\n", }, customOptions, ""); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_parameter_specification_inheritance_013() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runNegativeTestWithLibs(new String[] { "p1/X.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "public class X {\n" + " public @Nullable String getString(String s1, @Nullable String s2, @NonNull String s3) {\n" + " return s1;\n" + " }\n" + "}\n", "p1/IY.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "public interface IY {\n" + " @NonNull String getString(@NonNull String s1, @NonNull String s2, @Nullable String s3);\n" + "}\n", "p1/Y.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "public class Y extends X implements IY {\n" + " @Override\n" + " public @Nullable String getString(String s1, @NonNull String s2, @NonNull String s3) {\n" + " return \"\";\n" + " }\n" + "}\n", }, customOptions,/*from w w w . j a va 2s . co m*/ "----------\n" + "1. ERROR in p1\\Y.java (at line 5)\n" + " public @Nullable String getString(String s1, @NonNull String s2, @NonNull String s3) {\n" + " ^^^^^^^^^^^^^^^^\n" + "The return type is incompatible with the @NonNull return from IY.getString(String, String, String)\n" + "----------\n" + "2. ERROR in p1\\Y.java (at line 5)\n" + " public @Nullable String getString(String s1, @NonNull String s2, @NonNull String s3) {\n" + " ^^^^^^\n" + "Missing null annotation: inherited method from IY declares this parameter as @NonNull\n" + "----------\n" + "3. ERROR in p1\\Y.java (at line 5)\n" + " public @Nullable String getString(String s1, @NonNull String s2, @NonNull String s3) {\n" + " ^^^^^^^^^^^^^^^\n" + "Illegal redefinition of parameter s2, inherited method from X declares this parameter as @Nullable\n" + "----------\n" + "4. ERROR in p1\\Y.java (at line 5)\n" + " public @Nullable String getString(String s1, @NonNull String s2, @NonNull String s3) {\n" + " ^^^^^^^^^^^^^^^\n" + "Illegal redefinition of parameter s3, inherited method from IY declares this parameter as @Nullable\n" + "----------\n"); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_parameter_specification_inheritance_014() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runNegativeTestWithLibs(new String[] { "p1/IY.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "public interface IY {\n" + " public @NonNull String getString1(String s);\n" + " public @NonNull String getString2(String s);\n" + " public String getString3(@Nullable String s);\n" + " public @NonNull String getString4(@Nullable String s);\n" + " public @NonNull String getString5(@Nullable String s);\n" + " public @Nullable String getString6(@NonNull String s);\n" + "}\n", "p1/X.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "public class X {\n" + " public @Nullable String getString1(String s) {\n" + // incomp. return " return s;\n" + " }\n" + " public String getString2(String s) {\n" + // incomp. return " return s;\n" + " }\n" + " public String getString3(String s) {\n" + // incomp. arg " return \"\";\n" + " }\n" + " public @NonNull String getString4(@Nullable String s) {\n" + " return \"\";\n" + " }\n" + " public @NonNull String getString5(@NonNull String s) {\n" + // incomp. arg " return s;\n" + " }\n" + " public @NonNull String getString6(@Nullable String s) {\n" + " return \"\";\n" + " }\n" + "}\n", "p1/Y.java", "package p1;\n" + "public class Y extends X implements IY {\n" + "}\n", }, customOptions,//from w w w.ja v a 2 s . c om "----------\n" + "1. ERROR in p1\\Y.java (at line 2)\n" + " public class Y extends X implements IY {\n" + " ^\n" + "The method getString1(String) from class X cannot implement the corresponding method from type IY due to incompatible nullness constraints\n" + "----------\n" + "2. ERROR in p1\\Y.java (at line 2)\n" + " public class Y extends X implements IY {\n" + " ^\n" + "The method getString2(String) from class X cannot implement the corresponding method from type IY due to incompatible nullness constraints\n" + "----------\n" + "3. ERROR in p1\\Y.java (at line 2)\n" + " public class Y extends X implements IY {\n" + " ^\n" + "The method getString5(String) from class X cannot implement the corresponding method from type IY due to incompatible nullness constraints\n" + "----------\n" + "4. ERROR in p1\\Y.java (at line 2)\n" + " public class Y extends X implements IY {\n" + " ^\n" + "The method getString3(String) from class X cannot implement the corresponding method from type IY due to incompatible nullness constraints\n" + "----------\n"); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_nonnull_return_005() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); runConformTestWithLibs(new String[] { "X.java", "import org.eclipse.jdt.annotation.*;\n" + "public class X {\n" + " @NonNull Object getObject(@NonNull Object o) {\n" + " return o;\n" + " }\n" + "}\n" }, customOptions, ""); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_annotation_import_001() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_NullableAnnotationName, "org.foo.Nullable"); customOptions.put(NullCompilerOptions.OPTION_NonNullAnnotationName, "org.foo.NonNull"); runConformTestWithLibs(new String[] { CUSTOM_NULLABLE_NAME, CUSTOM_NULLABLE_CONTENT, CUSTOM_NONNULL_NAME, CUSTOM_NONNULL_CONTENT, "Lib.java", "public class Lib {\n" + " @org.foo.NonNull Object getObject() { return new Object(); }\n" + // FQN "}\n", "X.java", "import org.foo.NonNull;\n" + // explicit import "public class X {\n" + " @NonNull Object getObject(@NonNull Lib l) {\n" + " return l.getObject();\n" + " }\n" + "}\n" }, customOptions, ""); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_annotation_import_002() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_NullableAnnotationName, "org.foo.Nullable"); customOptions.put(NullCompilerOptions.OPTION_NonNullAnnotationName, "org.foo.NonNull"); runConformTest(new String[] { CUSTOM_NULLABLE_NAME, CUSTOM_NULLABLE_CONTENT, CUSTOM_NONNULL_NAME, CUSTOM_NONNULL_CONTENT, "Lib.java", "import org.foo.NonNull;\n" + "public class Lib {\n" + " @NonNull Object getObject() { return new Object(); }\n" + "}\n", "X.java", "import org.foo.NonNull;\n" + "public class X {\n" + " @NonNull Object getObject(@org.foo.Nullable String dummy, @NonNull Lib l) {\n" + " Object o = l.getObject();" + " return o;\n" + " }\n" + "}\n" }, customOptions, ""); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_annotation_import_005() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_NullableAnnotationName, "org.foo.MayBeNull"); customOptions.put(NullCompilerOptions.OPTION_NonNullAnnotationName, "org.foo.MustNotBeNull"); runNegativeTest(true/*shouldFlushOutputDirectory*/, new String[] { "org/foo/MayBeNull.java", "package org.foo;\n" + "import java.lang.annotation.*;\n" + "@Retention(RetentionPolicy.CLASS)\n" + "public @interface MayBeNull {}\n", "org/foo/MustNotBeNull.java", "package org.foo;\n" + "import java.lang.annotation.*;\n" + "@Retention(RetentionPolicy.CLASS)\n" + "public @interface MustNotBeNull {}\n", "Lib.java", "public class Lib {\n" + " Object getObject() { return new Object(); }\n" + "}\n", "X.java", "import org.foo.*;\n" + "public class X {\n" + " @MustNotBeNull Object getObject(@MustNotBeNull Lib l) {\n" + " return l.getObject();\n" + " }\n" + "}\n", }, null /*no libs*/, customOptions, "----------\n" + "1. ERROR in X.java (at line 4)\n" + " return l.getObject();\n" + " ^^^^^^^^^^^^^\n" + "Potential type mismatch: required \'@MustNotBeNull Object\' but nullness of the provided value is unknown\n" + "----------\n", JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); }