Example usage for org.eclipse.jdt.internal.compiler.impl CompilerOptions OPTION_ReportRedundantNullCheck

List of usage examples for org.eclipse.jdt.internal.compiler.impl CompilerOptions OPTION_ReportRedundantNullCheck

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.impl CompilerOptions OPTION_ReportRedundantNullCheck.

Prototype

String OPTION_ReportRedundantNullCheck

To view the source code for org.eclipse.jdt.internal.compiler.impl CompilerOptions OPTION_ReportRedundantNullCheck.

Click Source Link

Usage

From source file:org.eclipse.objectteams.internal.jdt.nullity.quickfix.NullAnnotationsCleanUp.java

License:Open Source License

private Map getRequiredOptions() {
    Map result = new Hashtable();
    // TODO(SH): might set depending on this.handledProblemID, not sure about the benefit
    result.put(NullCompilerOptions.OPTION_ReportNullSpecViolation, JavaCore.WARNING);
    result.put(CompilerOptions.OPTION_ReportRedundantNullCheck, JavaCore.WARNING);
    return result;
}

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 av  a  2  s .  c o  m*/
                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_nonnull_return_008() {
    Map customOptions = getCompilerOptions();
    customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR);
    runNegativeTestWithLibs(//w  w  w  .  j  a v a2  s  .c o  m
            new String[] { "X.java",
                    "import org.eclipse.jdt.annotation.*;\n" + "public class X {\n"
                            + "    @NonNull Object getObject() {\n" + "        return new Object();\n"
                            + "    }\n" + "    void test() {\n" + "        if (getObject() == null)\n"
                            + "           throw new RuntimeException();\n" + "    }\n" + "}\n" },
            customOptions,
            "----------\n" + "1. ERROR in X.java (at line 7)\n" + "   if (getObject() == null)\n"
                    + "       ^^^^^^^^^^^\n"
                    + "Redundant null check: The method getObject() cannot return null\n" + "----------\n");
}

From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java

License:Open Source License

public void test_nonnull_return_009() {
    Map customOptions = getCompilerOptions();
    customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR);
    runNegativeTestWithLibs(//from w w  w. ja va  2 s.  c o  m
            new String[] { "X.java",
                    "import org.eclipse.jdt.annotation.*;\n" + "public class X {\n"
                            + "    @NonNull Object getObject() {\n" + "        return new Object();\n"
                            + "    }\n" + "    void test() {\n" + "        Object left = null;\n"
                            + "        if (left != getObject())\n"
                            + "           throw new RuntimeException();\n" + "    }\n" + "}\n" },
            customOptions,
            "----------\n" + "1. ERROR in X.java (at line 8)\n" + "   if (left != getObject())\n"
                    + "       ^^^^\n"
                    + "Redundant null check: The variable left can only be null at this location\n"
                    + "----------\n" + "2. ERROR in X.java (at line 8)\n" + "   if (left != getObject())\n"
                    + "               ^^^^^^^^^^^\n"
                    + "Redundant null check: The method getObject() cannot return null\n" + "----------\n");
}

From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java

License:Open Source License

public void test_nonnull_return_010() {
    Map customOptions = getCompilerOptions();
    customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR);
    runNegativeTestWithLibs(new String[] { "X.java",
            "import org.eclipse.jdt.annotation.*;\n" + "public class X {\n" + "    @Nullable X getX() {\n"
                    + "        return new X();\n" + "    }\n" + "    void test() {\n"
                    + "        X left = this;\n" + "        do {\n" + "            if (left == null) \n"
                    + "                  throw new RuntimeException();\n"
                    + "        } while ((left = left.getX()) != null);\n" + // no warning/error here!
                    "    }\n" + "}\n" },
            customOptions,//from ww  w  . j a v  a2s.co m
            "----------\n" + "1. ERROR in X.java (at line 9)\n" + "   if (left == null) \n" + "       ^^^^\n"
                    + "Null comparison always yields false: The variable left cannot be null at this location\n"
                    + "----------\n");
}

From source file:org.eclipse.objectteams.otdt.tests.otjld.api.Reflection.java

License:Open Source License

public void test923_getRoleMethod3() {
    Map customOptions = getCompilerOptions();
    customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING);
    customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING);
    customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING);

    runConformTest(new String[] { "Team923grm3_2.java",
            "\n" + "public team class Team923grm3_2 extends Team923grm3_1 {\n"
                    + "    protected class R2 playedBy T923grm3 {\n"
                    + "        public String toString() { return \"NOK2\"; }\n" + "    }\n"
                    + "    Team923grm3_2(T923grm3 as R o1, T923grm3 as R2 o2) { \n" + "        super(o1);\n"
                    + "    }\n" + "    public static void main (String[] args0) {\n"
                    + "        T923grm3 o = new T923grm3();\n"
                    + "        Team923grm3_1 t = new Team923grm3_2(o, o);\n" + "        try {\n"
                    + "            System.out.print(t.getRole(o));\n"
                    + "        } catch (org.objectteams.DuplicateRoleException ex) {\n"
                    + "            System.out.print(ex.getMessage());\n" + "        }\n" + "    }\n" + "}    \n"
                    + "    \n",
            "T923grm3.java", "\n" + "public class T923grm3 {}\n" + "    \n", "Team923grm3_1.java",
            "\n" + "public team class Team923grm3_1 {\n" + "    protected class R playedBy T923grm3 {\n"
                    + "        public String toString() { return \"NOK\"; }\n" + "    }\n"
                    + "    Team923grm3_1(R o) {}\n" + "}\n" + "    \n" },
            "Ambiguous role instances: found a role in hierarchies R2 and R", null/*classLibraries*/,
            true/*shouldFlushOutputDirectory*/, null/*vmArguments*/, customOptions,
            null/*no custom requestor*/);
}

From source file:org.eclipse.objectteams.otdt.tests.otjld.api.Reflection.java

License:Open Source License

public void test923_getRoleMethod3n() {
    Map customOptions = getCompilerOptions();
    customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING);
    customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING);
    customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING);

    runConformTest(new String[] { "Team923grm3n_2.java", "\n" + "@SuppressWarnings(\"null\")\n"
            + "public team class Team923grm3n_2 extends Team923grm3n_1 {\n"
            + "    void nullCheck(int i, int j) {\n" + "        Object o = null;\n"
            + "        if (i == 3) o = new Object();\n" + "        if (j == 3) o.toString();\n" + "    }\n"
            + "    protected class R2 playedBy T923grm3n {\n"
            + "        public String toString() { return \"NOK2\"; }\n" + "    }\n"
            + "    Team923grm3n_2(T923grm3n as R o1, T923grm3n as R2 o2) {\n" + "        super(o1);\n"
            + "    }\n" + "    public static void main (String[] args0) {\n"
            + "        T923grm3n o = new T923grm3n();\n"
            + "        Team923grm3n_1 t = new Team923grm3n_2(o, o);\n" + "        try {\n"
            + "            System.out.print(t.getRole(o));\n"
            + "        } catch (org.objectteams.DuplicateRoleException ex) {\n"
            + "            System.out.print(ex.getMessage());\n" + "        }\n" + "    }\n" + "}\n" + "    \n",
            "T923grm3n.java", "\n" + "public class T923grm3n {}\n" + "    \n", "Team923grm3n_1.java",
            "\n" + "public team class Team923grm3n_1 {\n" + "    protected class R playedBy T923grm3n {\n"
                    + "        public String toString() { return \"NOK\"; }\n" + "    }\n"
                    + "    Team923grm3n_1(R o) {}\n" + "}\n" + "    \n" },
            "Ambiguous role instances: found a role in hierarchies R2 and R", null/*classLibraries*/,
            true/*shouldFlushOutputDirectory*/, null/*vmArguments*/, customOptions,
            null/*no custom requestor*/);
}

From source file:org.eclipse.objectteams.otdt.tests.otjld.roleplaying.LiftingAndLowering.java

License:Open Source License

public void test221_loweringToBaseclass19() {
    Map options = getCompilerOptions();
    options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR);
    runConformTest(true /* flushOutputDir*/,
            new String[] { "Team221ltb19.java",
                    "public team class Team221ltb19 {\n" + "   protected class R playedBy T221ltb19 {\n"
                            + "      protected R() { base(); }\n" + "       protected void test() {\n"
                            + "           T221ltb19.accept(this);\n" + "       }\n" + "   }\n"
                            + "   T221ltb19 aBase;\n" + "   void test() {\n" + "      new R().test();\n"
                            + "   }\n" + "   public static void main(String[] args) {\n"
                            + "      new Team221ltb19().test();\n" + "   }\n" + "}\n",
                    "T221ltb19.java",
                    "public class T221ltb19 {\n" + "   public static void accept(T221ltb19 inst) {\n"
                            + "      System.out.println(\"OK\");\n" + "   }\n" + "}\n" },
            null, // libs
            options, "", // compiler log
            "OK", "", JavacTestOptions.EclipseJustification.EclipseWarningConfiguredAsError);
}

From source file:org.eclipse.objectteams.otdt.tests.otjld.roleplaying.LiftingAndLowering.java

License:Open Source License

public void test221_loweringToBaseclass20() {
    Map options = getCompilerOptions();
    options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR);
    runConformTest(true /* flushOutputDir*/, new String[] { "Team221ltb20.java",
            "public team class Team221ltb20 {\n" + "   protected class R playedBy T221ltb20 {\n"
                    + "      protected R() { base(); }\n" + "       protected void test() {\n"
                    + "           R r = this;" + "           T221ltb20.accept(r);\n" + "       }\n" + "   }\n"
                    + "   T221ltb20 aBase;\n" + "   void test() {\n" + "      new R().test();\n" + "   }\n"
                    + "   public static void main(String[] args) {\n" + "      new Team221ltb20().test();\n"
                    + "   }\n" + "}\n",
            "T221ltb20.java",
            "public class T221ltb20 {\n" + "   public static void accept(T221ltb20 inst) {\n"
                    + "      System.out.println(\"OK\");\n" + "   }\n" + "}\n" },
            null, // libs
            options, "", // compiler log
            "OK", "", JavacTestOptions.EclipseJustification.EclipseWarningConfiguredAsError);
}

From source file:org.eclipse.objectteams.otdt.tests.otjld.teamactivation.ExplicitTeamActivation.java

License:Open Source License

public void _disabled_test525_illegalWithinStatement7() {
    Map customOptions = getCompilerOptions();
    customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING);
    customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING);
    customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING);
    runTestExpectingWarnings(/*ww w .  j  av a  2  s  . co m*/
            new String[] { "T525iws7.java",
                    "\n" + "public class T525iws7 {\n" + "    void foo(org.objectteams.Team nullTeam) {\n"
                            + "        if (nullTeam == null) { }\n" + "        within (nullTeam) {\n"
                            + "            System.out.println(\"OUCH\");\n" + "        }\n" + "    }\n" + "}\n"
                            + "    \n" },
            "Potential null pointer access: The variable nullTeam may be null at this location");
}