### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java,v retrieving revision 1.35 diff -u -r1.35 AssignmentTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 26 Feb 2007 08:47:58 -0000 1.35 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 1 Mar 2007 12:04:14 -0000 @@ -185,12 +185,12 @@ "1. ERROR in X.java (at line 7)\n" + " }while(a!=null);\n" + " ^\n" + - "The variable a cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable a cannot be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 9)\n" + " if(a!=null)\n" + " ^\n" + - "The variable a can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable a can only be null at this location\n" + "----------\n" + "3. ERROR in X.java (at line 13)\n" + " System.out.println(a+b);\n" + @@ -641,12 +641,12 @@ "1. ERROR in X.java (at line 7)\n" + " } while (o != null);\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 8)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93588 Index: src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java,v retrieving revision 1.52 diff -u -r1.52 NullReferenceTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 26 Feb 2007 08:47:59 -0000 1.52 +++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 1 Mar 2007 12:04:16 -0000 @@ -72,7 +72,7 @@ "1. ERROR in X.java (at line 4)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -114,7 +114,7 @@ "1. ERROR in X.java (at line 4)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -133,7 +133,7 @@ "1. ERROR in X.java (at line 4)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -172,7 +172,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n"); } @@ -192,7 +192,7 @@ "1. ERROR in X.java (at line 5)\n" + " x.m.toString();\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable x can only be null at this location\n" + "----------\n"); } @@ -212,7 +212,7 @@ "1. ERROR in X.java (at line 5)\n" + " System.out.println(x.m);\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable x can only be null at this location\n" + "----------\n"); } @@ -578,7 +578,7 @@ "1. ERROR in X.java (at line 5)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -613,7 +613,7 @@ "1. ERROR in X.java (at line 5)\n" + " x.m = new Object();\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable x can only be null at this location\n" + "----------\n"); } @@ -632,7 +632,7 @@ "1. ERROR in X.java (at line 4)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -651,7 +651,7 @@ "1. ERROR in X.java (at line 4)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -684,7 +684,7 @@ "1. ERROR in X.java (at line 4)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -749,7 +749,7 @@ "1. ERROR in X.java (at line 5)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n"); } @@ -769,7 +769,7 @@ "1. ERROR in X.java (at line 4)\n" + " i += 1;\n" + " ^\n" + - "The variable i can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable i can only be null at this location\n" + "----------\n"); } } @@ -791,7 +791,7 @@ "1. ERROR in X.java (at line 4)\n" + " i++;\n" + " ^\n" + - "The variable i can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable i can only be null at this location\n" + "----------\n"); } } @@ -812,7 +812,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (i == null) {};\n" + " ^\n" + - "The variable i cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable i cannot be null at this location\n" + "----------\n"); } } @@ -833,7 +833,7 @@ "1. ERROR in X.java (at line 4)\n" + " System.out.println(i + 4);\n" + " ^\n" + - "The variable i can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable i can only be null at this location\n" + "----------\n"); } } @@ -872,7 +872,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (i == null) {}\n" + " ^\n" + - "The variable i cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable i cannot be null at this location\n" + "----------\n"); } } @@ -908,7 +908,7 @@ "1. ERROR in X.java (at line 4)\n" + " args[0].toString();\n" + " ^^^^\n" + - "The variable args can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable args can only be null at this location\n" + "----------\n"); } @@ -955,7 +955,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (o == null) {};\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -978,7 +978,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (o == null) {/* empty */}\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n"); } @@ -1019,7 +1019,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (o == null) {/* empty */}\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -1052,7 +1052,7 @@ "1. ERROR in X.java (at line 4)\n" + " (o = null).toString();\n" + " ^^^^^^^^^^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -1071,7 +1071,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -1107,7 +1107,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (c == null) {};\n" + " ^\n" + - "The variable c cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable c cannot be null at this location\n" + "----------\n"); } @@ -1124,7 +1124,7 @@ "1. ERROR in X.java (at line 3)\n" + " if (o1 != null && (o2 = o1) != null) { /* */ }\n" + " ^^^^^^^^^\n" + - "The variable o2 cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o2 cannot be null at this location\n" + "----------\n" ); } @@ -1142,7 +1142,7 @@ "1. ERROR in X.java (at line 3)\n" + " while (o1 != null && (o2 = o1) != null) { /* */ }\n" + " ^^^^^^^^^\n" + - "The variable o2 cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o2 cannot be null at this location\n" + "----------\n" ); } @@ -1164,12 +1164,12 @@ "1. ERROR in X.java (at line 3)\n" + " if (o == null || o == null) {\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 6)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -1190,12 +1190,12 @@ "1. ERROR in X.java (at line 3)\n" + " if (o == null && o == null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 6)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -1215,7 +1215,7 @@ "1. ERROR in X.java (at line 4)\n" + " || (i1.byteValue() == i2.byteValue());\n" + " ^^\n" + - "The variable i1 may be null\n" + + "Potential null pointer access: The variable i1 may be null at this location\n" + "----------\n"); } @@ -1235,12 +1235,12 @@ "1. ERROR in X.java (at line 4)\n" + " || (i1.byteValue() == i2.byteValue());\n" + " ^^\n" + - "The variable i1 may be null\n" + + "Potential null pointer access: The variable i1 may be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " || (i1.byteValue() == i2.byteValue());\n" + " ^^\n" + - "The variable i2 may be null\n" + + "Potential null pointer access: The variable i2 may be null at this location\n" + "----------\n"); } @@ -1297,7 +1297,7 @@ "1. ERROR in X.java (at line 5)\n" + " if (o instanceof X) { /* */ }\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "instanceof always yields false: The variable o can only be null at this location\n" + "----------\n"); } @@ -1317,7 +1317,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (x == null) { /* */ }\n" + " ^\n" + - "The variable x cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable x cannot be null at this location\n" + "----------\n"); } @@ -1356,7 +1356,7 @@ "1. ERROR in X.java (at line 4)\n" + " || x == null) {\n" + " ^\n" + - "The variable x cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable x cannot be null at this location\n" + "----------\n"); } @@ -1408,7 +1408,7 @@ "1. ERROR in X.java (at line 4)\n" + " return s1.toString();\n" + " ^^\n" + - "The variable s1 may be null\n" + + "Potential null pointer access: The variable s1 may be null at this location\n" + "----------\n"); } @@ -1528,7 +1528,7 @@ "1. ERROR in X.java (at line 13)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -1548,7 +1548,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (o != null) {\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -1570,7 +1570,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o != null) {\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -1592,7 +1592,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o != null) {\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -1612,7 +1612,7 @@ "1. ERROR in X.java (at line 4)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -1633,7 +1633,7 @@ "1. ERROR in X.java (at line 6)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -1655,7 +1655,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -1699,7 +1699,7 @@ "1. ERROR in X.java (at line 7)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -1724,7 +1724,7 @@ "1. ERROR in X.java (at line 10)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -1750,12 +1750,12 @@ "1. ERROR in X.java (at line 8)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 11)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -1792,12 +1792,12 @@ "1. ERROR in X.java (at line 5)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 7)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -1819,7 +1819,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -1840,7 +1840,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n"); } @@ -1861,7 +1861,7 @@ "1. ERROR in X.java (at line 6)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -1881,7 +1881,7 @@ "1. ERROR in X.java (at line 5)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -1953,7 +1953,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -1990,7 +1990,7 @@ "1. ERROR in X.java (at line 5)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -2069,7 +2069,7 @@ "1. ERROR in X.java (at line 20)\n" + " s.toString();\n" + " ^\n" + - "The variable s may be null\n" + + "Potential null pointer access: The variable s may be null at this location\n" + "----------\n"); } @@ -2093,7 +2093,7 @@ "1. ERROR in X.java (at line 7)\n" + " s1.toString();\n" + " ^^\n" + - "The variable s1 may be null\n" + + "Potential null pointer access: The variable s1 may be null at this location\n" + "----------\n"); } @@ -2119,7 +2119,7 @@ "1. ERROR in X.java (at line 9)\n" + " s2.toString();\n" + " ^^\n" + - "The variable s2 may be null\n" + + "Potential null pointer access: The variable s2 may be null at this location\n" + "----------\n"); } @@ -2143,7 +2143,7 @@ "1. ERROR in X.java (at line 9)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -2164,7 +2164,7 @@ "1. ERROR in X.java (at line 6)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -2222,7 +2222,7 @@ "1. ERROR in X.java (at line 7)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -2246,7 +2246,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (o != null) {\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -2273,12 +2273,12 @@ "1. ERROR in X.java (at line 4)\n" + " if (o != null) {\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 8)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -2304,7 +2304,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (o != null) {\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -2332,12 +2332,12 @@ "1. ERROR in X.java (at line 4)\n" + " if (o != null) {\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 8)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -2433,7 +2433,7 @@ "1. ERROR in X.java (at line 5)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -2458,7 +2458,7 @@ "1. ERROR in X.java (at line 5)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -2480,7 +2480,7 @@ "1. ERROR in X.java (at line 5)\n" + " o1.toString();\n" + " ^^\n" + - "The variable o1 may be null\n" + + "Potential null pointer access: The variable o1 may be null at this location\n" + "----------\n"); } @@ -2502,7 +2502,7 @@ "1. ERROR in X.java (at line 5)\n" + " o1.toString();\n" + " ^^\n" + - "The variable o1 may be null\n" + + "Potential null pointer access: The variable o1 may be null at this location\n" + "----------\n"); } @@ -2522,7 +2522,7 @@ "1. ERROR in X.java (at line 4)\n" + " while (o.toString() != null) {/* */}\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -2542,7 +2542,7 @@ "1. ERROR in X.java (at line 4)\n" + " while (o != null) {/* */}\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n"); } @@ -2604,7 +2604,7 @@ "1. ERROR in X.java (at line 7)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -2624,7 +2624,7 @@ "1. ERROR in X.java (at line 5)\n" + " while (dummy || o != null) { /* */ }\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n"); } @@ -2647,7 +2647,7 @@ "1. ERROR in X.java (at line 6)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -2702,7 +2702,7 @@ "1. ERROR in X.java (at line 6)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -2775,7 +2775,7 @@ "1. ERROR in X.java (at line 7)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -2814,7 +2814,7 @@ "1. ERROR in X.java (at line 7)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -2858,7 +2858,7 @@ "1. ERROR in X.java (at line 8)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -2879,7 +2879,7 @@ "1. ERROR in X.java (at line 6)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -2923,7 +2923,7 @@ "1. ERROR in X.java (at line 5)\n" + " o.toString(); o = null;\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -2948,7 +2948,7 @@ "1. ERROR in X.java (at line 10)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n"); } @@ -2990,7 +2990,7 @@ "1. ERROR in X.java (at line 7)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -3014,7 +3014,7 @@ "1. ERROR in X.java (at line 7)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -3060,7 +3060,7 @@ "1. ERROR in X.java (at line 8)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -3081,7 +3081,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -3105,7 +3105,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n"); } @@ -3239,7 +3239,7 @@ "1. ERROR in X.java (at line 6)\n" + " x.toString();\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable x can only be null at this location\n" + "----------\n"); } @@ -3347,7 +3347,7 @@ "1. ERROR in X.java (at line 5)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -3384,7 +3384,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -3408,7 +3408,7 @@ "1. ERROR in X.java (at line 9)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -3430,7 +3430,7 @@ "1. ERROR in X.java (at line 7)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -3511,7 +3511,7 @@ "1. ERROR in X.java (at line 5)\n" + " if (o != null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n"); } @@ -3532,7 +3532,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -3590,7 +3590,7 @@ "1. ERROR in X.java (at line 5)\n" + " if (o != null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n"); } @@ -3635,7 +3635,7 @@ "1. ERROR in X.java (at line 7)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -3660,7 +3660,7 @@ "1. ERROR in X.java (at line 9)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -3685,7 +3685,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n" ); } @@ -3759,7 +3759,7 @@ "1. ERROR in X.java (at line 7)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -3838,6 +3838,39 @@ ""); } +// null analysis -- while nested hits CAN_ONLY_NON_NULL +public void test0459_while_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " Object o = b ? null : new Object(),\n" + + " u = new Object(),\n" + + " v = new Object();\n" + + " while (o != null) {\n" + + " while (b) {\n" + + " if (v == null) {\n" + + " o = new Object();\n" + + " };\n" + + " while (o == null) {\n" + + " if (u == null) {\n" + + " v = null;\n" + + " };\n" + + " u = null;\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 11)\r\n" + + " while (o == null) {\r\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n"); +} + // null analysis -- try/finally public void test0500_try_finally() { this.runConformTest( @@ -3877,7 +3910,7 @@ "1. ERROR in X.java (at line 8)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n" // because finally assigns to null ); } @@ -3920,7 +3953,7 @@ "1. ERROR in X.java (at line 5)\n" + " x = null;\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Redundant assignment: The variable x can only be null at this location\n" + "----------\n"); } @@ -3942,7 +3975,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (x != null) { /* */ }\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable x can only be null at this location\n" + "----------\n"); } @@ -3988,7 +4021,7 @@ "1. ERROR in X.java (at line 7)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -4012,7 +4045,7 @@ "1. ERROR in X.java (at line 7)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -4036,7 +4069,7 @@ "1. ERROR in X.java (at line 5)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -4063,7 +4096,7 @@ "1. ERROR in X.java (at line 7)\n" + " o2.toString();\n" + " ^^\n" + - "The variable o2 can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o2 can only be null at this location\n" + "----------\n"); } @@ -4133,7 +4166,7 @@ "1. ERROR in X.java (at line 7)\n" + " x.toString();\n" + " ^\n" + - "The variable x may be null\n" + + "Potential null pointer access: The variable x may be null at this location\n" + "----------\n"); } @@ -4337,7 +4370,7 @@ "1. ERROR in X.java (at line 28)\n" + " x.toString();\n" + " ^\n" + - "The variable x may be null\n" + + "Potential null pointer access: The variable x may be null at this location\n" + "----------\n"); } @@ -4458,7 +4491,7 @@ "1. ERROR in X.java (at line 10)\n" + " if(t.bar()) {\n" + " ^\n" + - "The variable t can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable t can only be null at this location\n" + "----------\n"); } @@ -4491,7 +4524,7 @@ "1. ERROR in X.java (at line 10)\n" + " if(t == null ? false : (t == null ? false : t.bar())) {\n" + " ^\n" + - "The variable t cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable t cannot be null at this location\n" + "----------\n"); } @@ -4524,7 +4557,7 @@ "1. ERROR in X.java (at line 10)\n" + " if(t != null ? false : (t == null ? false : t.bar())) {\n" + " ^\n" + - "The variable t can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable t can only be null at this location\n" + "----------\n"); } @@ -4559,7 +4592,7 @@ "1. ERROR in X.java (at line 13)\r\n" + " o.toString();\r\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -4594,7 +4627,7 @@ "1. ERROR in X.java (at line 12)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -4626,7 +4659,7 @@ "1. ERROR in X.java (at line 12)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -4651,12 +4684,12 @@ "1. ERROR in X.java (at line 7)\n" + " if (x != null) { /* */ }\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable x can only be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 8)\n" + " if (y != null) { /* */ }\n" + " ^\n" + - "The variable y can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable y can only be null at this location\n" + "----------\n"); } @@ -4681,12 +4714,12 @@ "1. ERROR in X.java (at line 7)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 8)\n" + " o2.toString();\n" + " ^^\n" + - "The variable o2 can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o2 can only be null at this location\n" + "----------\n"); } @@ -4712,12 +4745,12 @@ "1. ERROR in X.java (at line 8)\n" + " x.toString();\n" + " ^\n" + - "The variable x may be null\n" + + "Potential null pointer access: The variable x may be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 9)\n" + " y.toString();\n" + " ^\n" + - "The variable y can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable y can only be null at this location\n" + "----------\n"); } @@ -4744,12 +4777,12 @@ "1. ERROR in X.java (at line 7)\n" + " if (x != null) {\n" + " ^\n" + - "The variable x cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable x cannot be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 10)\n" + " y.toString();\n" + " ^\n" + - "The variable y can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable y can only be null at this location\n" + "----------\n"); } @@ -4799,7 +4832,7 @@ "1. ERROR in X.java (at line 13)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -4859,7 +4892,7 @@ "1. ERROR in X.java (at line 15)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -4895,7 +4928,7 @@ // "1. ERROR in X.java (at line 10)\n" + // " if (o != null) {\n" + // " ^\n" + -// "The variable o can only be null; it was either set to null or checked for null when last used\n" + +// "Redundant null check: The variable o can only be null at this location\n" + // "----------\n" ); } @@ -4924,7 +4957,7 @@ "1. ERROR in X.java (at line 9)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -4952,7 +4985,7 @@ "1. ERROR in X.java (at line 9)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -4980,7 +5013,7 @@ "1. ERROR in X.java (at line 12)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -5012,8 +5045,8 @@ "1. ERROR in X.java (at line 13)\n" + " o.toString();\n" + " ^\n" + -// "The variable o can only be null; it was either set to null or checked for null when last used\n" + - "The variable o may be null\n" + +// "Null pointer access: The variable o can only be null at this location\n" + + "Potential null pointer access: The variable o may be null at this location\n" + // conservative flow analysis softens the error "----------\n"); } @@ -5048,8 +5081,8 @@ "1. ERROR in X.java (at line 12)\n" + " o.toString();\n" + " ^\n" + -// "The variable o can only be null; it was either set to null or checked for null when last used\n" + - "The variable o may be null\n" + +// "Null pointer access: The variable o can only be null at this location\n" + + "Potential null pointer access: The variable o may be null at this location\n" + // conservative flow analysis softens the error "----------\n"); } @@ -5086,7 +5119,7 @@ "1. ERROR in X.java (at line 19)\n" + " if (c == null) { // should complain: c can only be null\n" + " ^\n" + - "The variable c can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable c can only be null at this location\n" + "----------\n"); } @@ -5113,7 +5146,7 @@ "1. ERROR in X.java (at line 7)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -5140,7 +5173,7 @@ "1. ERROR in X.java (at line 8)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -5177,7 +5210,7 @@ "1. ERROR in X.java (at line 20)\n" + " if (ex == null) {\n" + " ^^\n" + - "The variable ex cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable ex cannot be null at this location\n" + "----------\n"); } @@ -5271,7 +5304,7 @@ "1. ERROR in X.java (at line 5)\n" + " while (o.toString() != null);\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -5292,7 +5325,7 @@ "1. ERROR in X.java (at line 5)\n" + " while (o != null);\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n"); } @@ -5315,7 +5348,7 @@ "1. ERROR in X.java (at line 7)\n" + " while (o == null);\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -5357,7 +5390,7 @@ "1. ERROR in X.java (at line 8)\n" + " while (dummy || o != null);\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n"); } @@ -5407,7 +5440,7 @@ "1. ERROR in X.java (at line 6)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -5448,7 +5481,7 @@ "1. ERROR in X.java (at line 7)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -5491,7 +5524,7 @@ "1. ERROR in X.java (at line 9)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -5519,7 +5552,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n" ); } @@ -5567,7 +5600,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n" ); } @@ -5593,7 +5626,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n" ); } @@ -5614,7 +5647,7 @@ "1. ERROR in X.java (at line 4)\n" + " for (;o.toString() != null;) {/* */}\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -5634,7 +5667,7 @@ "1. ERROR in X.java (at line 4)\n" + " for (;o != null;) {/* */}\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n"); } @@ -5696,7 +5729,7 @@ "1. ERROR in X.java (at line 7)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -5730,7 +5763,7 @@ "1. ERROR in X.java (at line 3)\n" + " for (;o == null; o.toString()) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -5748,7 +5781,7 @@ "1. ERROR in X.java (at line 3)\n" + " for (o.toString(); o == null;) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -5771,7 +5804,7 @@ "1. ERROR in X.java (at line 7)\n" + " for (o.toString(); bar();) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -5792,7 +5825,7 @@ "1. ERROR in X.java (at line 4)\n" + " for (Object o : t) {/* */}\n" + " ^\n" + - "The variable t can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable t can only be null at this location\n" + "----------\n"); } } @@ -5814,7 +5847,7 @@ "1. ERROR in X.java (at line 4)\n" + " for (Object o : i) {/* */}\n" + " ^\n" + - "The variable i can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable i can only be null at this location\n" + "----------\n"); } } @@ -5872,7 +5905,7 @@ "1. ERROR in X.java (at line 8)\n" + " flag.toString();\n" + " ^^^^\n" + - "The variable flag may be null\n" + + "Potential null pointer access: The variable flag may be null at this location\n" + "----------\n"); } } @@ -5895,7 +5928,7 @@ "1. ERROR in X.java (at line 6)\n" + " flag.toString();\n" + " ^^^^\n" + - "The variable flag can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable flag can only be null at this location\n" + "----------\n"); } } @@ -5919,7 +5952,7 @@ "1. ERROR in X.java (at line 7)\n" + " flag.toString();\n" + " ^^^^\n" + - "The variable flag may be null\n" + + "Potential null pointer access: The variable flag may be null at this location\n" + "----------\n"); } } @@ -5940,7 +5973,7 @@ "1. ERROR in X.java (at line 5)\n" + " flag.toString();\n" + " ^^^^\n" + - "The variable flag can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable flag can only be null at this location\n" + "----------\n"); } @@ -5992,7 +6025,7 @@ "1. ERROR in X.java (at line 5)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -6037,7 +6070,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n"); } @@ -6207,7 +6240,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -6231,7 +6264,7 @@ "1. ERROR in X.java (at line 9)\n" + " if (o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -6382,7 +6415,7 @@ "1. ERROR in X.java (at line 11)\n" + " if (b.booleanValue()) {\n" + " ^\n" + - "The variable b can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable b can only be null at this location\n" + "----------\n"); } @@ -6460,7 +6493,7 @@ "1. ERROR in X.java (at line 12)\n" + " if(o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -6484,7 +6517,7 @@ "1. ERROR in X.java (at line 7)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } @@ -6510,7 +6543,7 @@ "1. ERROR in X.java (at line 9)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -6540,7 +6573,7 @@ "1. ERROR in X.java (at line 15)\n" + " if(o != null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o cannot be null at this location\n" + "----------\n"); } @@ -6677,32 +6710,32 @@ "1. ERROR in X.java (at line 6)\n" + " o/*N N*/.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 10)\n" + " o/*NNa*/.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n" + "3. ERROR in X.java (at line 14)\n" + " o/*aNN */.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n" + "4. ERROR in X.java (at line 18)\n" + " o/*NON NULL*/.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n" + "5. ERROR in X.java (at line 22)\n" + " o/*Non-Null*/.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n" + "6. ERROR in X.java (at line 26)\n" + " o/*aNON-NULL */.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -6722,7 +6755,7 @@ "1. ERROR in X.java (at line 4)\n" + " o.toString();/*NN*/\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -6741,7 +6774,7 @@ "1. ERROR in X.java (at line 4)\n" + " /*NN*/o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -6780,7 +6813,7 @@ "1. ERROR in X.java (at line 4)\n" + " o.toString();\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n"); } } @@ -6802,7 +6835,7 @@ "1. ERROR in X.java (at line 4)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } } @@ -6821,17 +6854,17 @@ " if (o2 == null) { };\n" + // complain " }\n" + "}\n"}, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (o1 == null) { };\n" + - " ^^\n" + - "The variable o1 cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + - "----------\n" + - "2. ERROR in X.java (at line 5)\n" + - " if (o2 == null) { };\n" + - " ^^\n" + - "The variable o2 can only be null; it was either set to null or checked for null when last used\n" + - "----------\n"); + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o1 == null) { };\n" + + " ^^\n" + + "Null comparison always yields false: The variable o1 cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " if (o2 == null) { };\n" + + " ^^\n" + + "Redundant null check: The variable o2 can only be null at this location\n" + + "----------\n"); } } @@ -6869,7 +6902,7 @@ "1. ERROR in X.java (at line 4)\n" + " if (o == null) { };\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } } @@ -6892,12 +6925,12 @@ "1. ERROR in X.java (at line 4)\n" + " assert(o != null);\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " if (o == null) { };\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } } @@ -7058,27 +7091,27 @@ "1. ERROR in X.java (at line 4)\n" + " if (x != null) { // 1\n" + " ^\n" + - "The variable x cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable x cannot be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " if (x == null) { // 2\n" + " ^\n" + - "The variable x cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable x cannot be null at this location\n" + "----------\n" + "3. ERROR in X.java (at line 6)\n" + " x.foo(null); // 3\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable x can only be null at this location\n" + "----------\n" + "4. ERROR in X.java (at line 9)\n" + " } else if (x != null) { // 6\n" + " ^\n" + - "The variable x cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable x cannot be null at this location\n" + "----------\n" + "5. ERROR in X.java (at line 12)\n" + " x.foo(null); // 8\n" + " ^\n" + - "The variable x may be null\n" + + "Potential null pointer access: The variable x may be null at this location\n" + "----------\n"); } @@ -7182,7 +7215,7 @@ "1. ERROR in X.java (at line 22)\n" + " if (c == null) {// should complain: c can only be null\n" + " ^\n" + - "The variable c can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable c can only be null at this location\n" + "----------\n"); } @@ -7229,7 +7262,7 @@ "1. ERROR in X.java (at line 9)\n" + " if (other != null) {\n" + " ^^^^^\n" + - "The variable other cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable other cannot be null at this location\n" + "----------\n"); } @@ -7256,7 +7289,7 @@ "1. ERROR in X.java (at line 6)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n" ); } @@ -7280,12 +7313,12 @@ "1. ERROR in X.java (at line 4)\n" + " if (x == null) {\n" + " ^\n" + - "The variable x cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable x cannot be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " x.foo(this);\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable x can only be null at this location\n" + "----------\n"); } @@ -7307,7 +7340,7 @@ "1. ERROR in X.java (at line 7)\n" + " x.foo(null);\n" + " ^\n" + - "The variable x may be null\n" + + "Potential null pointer access: The variable x may be null at this location\n" + "----------\n"); } @@ -7351,12 +7384,12 @@ "1. ERROR in X.java (at line 5)\n" + " x = null;\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Redundant assignment: The variable x can only be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 7)\n" + " if (x != null) {\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable x can only be null at this location\n" + "----------\n"); } @@ -7380,7 +7413,7 @@ "1. ERROR in X.java (at line 8)\n" + " x.foo(null);\n" + " ^\n" + - "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable x can only be null at this location\n" + "----------\n"); } @@ -7405,12 +7438,12 @@ "1. ERROR in X.java (at line 6)\r\n" + " if (o != null) return;\r\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 7)\r\n" + " o = null;\r\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant assignment: The variable o can only be null at this location\n" + "----------\n"); } @@ -7528,7 +7561,7 @@ "1. ERROR in X.java (at line 13)\n" + " if (o == null) return;\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -7561,7 +7594,7 @@ "1. ERROR in X.java (at line 13)\n" + " if (progressJob == null) {\n" + " ^^^^^^^^^^^\n" + - "The variable progressJob can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable progressJob can only be null at this location\n" + "----------\n"); } @@ -7585,7 +7618,7 @@ "1. ERROR in X.java (at line 10)\n" + " if (o == null) return;\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -7700,7 +7733,7 @@ "1. ERROR in X.java (at line 7)\n" + " if (a == null) {\n" + " ^\n" + - "The variable a can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable a can only be null at this location\n" + "----------\n"); } @@ -7729,12 +7762,12 @@ "1. ERROR in X.java (at line 7)\n" + " if (a == null) {\n" + " ^\n" + - "The variable a can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable a can only be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 13)\n" + " if (a == null) {\n" + " ^\n" + - "The variable a cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable a cannot be null at this location\n" + "----------\n"); } @@ -7755,12 +7788,12 @@ "1. ERROR in X.java (at line 5)\n" + " while (o1 != null && (o3 = o1) != null) {\n" + " ^^\n" + - "The variable o1 cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o1 cannot be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " while (o1 != null && (o3 = o1) != null) {\n" + " ^^^^^^^^^\n" + - "The variable o3 cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable o3 cannot be null at this location\n" + "----------\n"); } @@ -7784,12 +7817,12 @@ "1. ERROR in X.java (at line 7)\n" + " }while(a!=null);\n" + " ^\n" + - "The variable a cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Redundant null check: The variable a cannot be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 8)\n" + " if(a!=null)\n" + " ^\n" + - "The variable a can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable a can only be null at this location\n" + "----------\n"); } @@ -7851,12 +7884,12 @@ "1. ERROR in X.java (at line 7)\n" + " } while (o != null);\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 8)\n" + " if (o == null) {\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Redundant null check: The variable o can only be null at this location\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 @@ -7936,17 +7969,17 @@ "1. ERROR in X.java (at line 4)\r\n" + " if (o != null) {\r\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 8)\r\n" + " o.toString();\r\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n" + "3. ERROR in X.java (at line 9)\r\n" + " p.toString();\r\n" + " ^\n" + - "The variable p may be null\n" + + "Potential null pointer access: The variable p may be null at this location\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 @@ -7975,7 +8008,7 @@ "1. ERROR in X.java (at line 8)\r\n" + " o.toString();\r\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n", null /* no extra class libraries */, true /* flush output directory */, @@ -8012,12 +8045,12 @@ "1. ERROR in X.java (at line 4)\r\n" + " if (o != null) {\r\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n" + "2. WARNING in X.java (at line 8)\r\n" + " o.toString();\r\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n", null /* no extra class libraries */, true /* flush output directory */, @@ -8054,12 +8087,12 @@ "1. ERROR in X.java (at line 4)\r\n" + " if (o != null) {\r\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + "----------\n" + "2. ERROR in X.java (at line 9)\r\n" + " p.toString();\r\n" + " ^\n" + - "The variable p may be null\n" + + "Potential null pointer access: The variable p may be null at this location\n" + "----------\n", null /* no extra class libraries */, true /* flush output directory */, @@ -8098,7 +8131,7 @@ "1. ERROR in X.java (at line 9)\r\n" + " o.toString();\r\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "Null pointer access: The variable o can only be null at this location\n" + "----------\n", null /* no extra class libraries */, true /* flush output directory */, @@ -8128,7 +8161,7 @@ "1. ERROR in X.java (at line 5)\n" + " if (o instanceof String) {};\n" + " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "instanceof always yields false: The variable o can only be null at this location\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 @@ -8310,7 +8343,7 @@ "1. ERROR in X.java (at line 18)\n" + " if (o65 == null) { /* */ }\n" + " ^^^\n" + - "The variable o65 cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o65 cannot be null at this location\n" + "----------\n"); } @@ -8566,7 +8599,7 @@ "1. ERROR in X.java (at line 20)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -8602,7 +8635,7 @@ "1. ERROR in X.java (at line 21)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -8641,7 +8674,7 @@ "1. ERROR in X.java (at line 24)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -8680,7 +8713,7 @@ "1. ERROR in X.java (at line 24)\n" + " if (o == null) { /* */ }\n" + " ^\n" + - "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + "----------\n"); } @@ -8710,7 +8743,7 @@ "1. ERROR in X.java (at line 15)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -8942,7 +8975,7 @@ "2. ERROR in X.java (at line 18)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -8979,7 +9012,7 @@ "2. ERROR in X.java (at line 18)\n" + " o.toString();\n" + " ^\n" + - "The variable o may be null\n" + + "Potential null pointer access: The variable o may be null at this location\n" + "----------\n"); } @@ -9024,7 +9057,7 @@ "2. ERROR in X.java (at line 26)\n" + " o1.toString();\n" + " ^^\n" + - "The variable o1 may be null\n" + + "Potential null pointer access: The variable o1 may be null at this location\n" + "----------\n"); } } \ No newline at end of file #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/core/compiler/IProblem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java,v retrieving revision 1.187 diff -u -r1.187 IProblem.java --- compiler/org/eclipse/jdt/core/compiler/IProblem.java 26 Feb 2007 08:48:59 -0000 1.187 +++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 1 Mar 2007 12:04:20 -0000 @@ -99,6 +99,15 @@ * TypeHidingTypeParameterFromType * TypeHidingTypeParameterFromMethod * TypeHidingType + * IBM Corporation - added the following constants + * NullLocalVariableReference + * PotentialNullLocalVariableReference + * RedundantNullCheckOnNullLocalVariable + * NullLocalVariableComparisonYieldsFalse + * RedundantLocalVariableNullAssignment + * NullLocalVariableInstanceofYieldsFalse + * RedundantNullCheckOnNonNullLocalVariable + * NonNullLocalVariableComparisonYieldsFalse *******************************************************************************/ package org.eclipse.jdt.core.compiler; @@ -718,15 +727,12 @@ // local variable related problems int DuplicateModifierForVariable = MethodRelated + 395; int IllegalModifierForVariable = MethodRelated + 396; - /** @since 3.1 */ + /** @deprecated - problem is no longer generated, use {@link #RedundantNullCheckOnNonNullLocalVariable} instead */ int LocalVariableCannotBeNull = Internal + 397; // since 3.3: semantics are LocalVariableRedundantCheckOnNonNull - /** @since 3.1 */ + /** @deprecated - problem is no longer generated, use {@link #NullLocalVariableReference}, {@link #RedundantNullCheckOnNullLocalVariable} or {@link #RedundantLocalVariableNullAssignment} instead */ int LocalVariableCanOnlyBeNull = Internal + 398; // since 3.3: split with LocalVariableRedundantCheckOnNull depending on context - // this id shares the null dereference errors with LocalVariableMayBeNull - /** @since 3.2 */ + /** @deprecated - problem is no longer generated, use {@link #PotentialNullLocalVariableReference} instead */ int LocalVariableMayBeNull = Internal + 399; - /** @since 3.3 */ - int LocalVariableRedundantCheckOnNull = Internal + 392; // method verifier problems int AbstractMethodMustBeImplemented = MethodRelated + 400; @@ -775,11 +781,29 @@ int UseEnumAsAnIdentifier = Internal + 441; /** @since 3.2 */ int EnumConstantsCannotBeSurroundedByParenthesis = Syntax + Internal + 442; - + // detected task /** @since 2.1 */ int Task = Internal + 450; + // local variables related problems, cont'd + /** @since 3.3 */ + int NullLocalVariableReference = Internal + 451; + /** @since 3.3 */ + int PotentialNullLocalVariableReference = Internal + 452; + /** @since 3.3 */ + int RedundantNullCheckOnNullLocalVariable = Internal + 453; + /** @since 3.3 */ + int NullLocalVariableComparisonYieldsFalse = Internal + 454; + /** @since 3.3 */ + int RedundantLocalVariableNullAssignment = Internal + 455; + /** @since 3.3 */ + int NullLocalVariableInstanceofYieldsFalse = Internal + 456; + /** @since 3.3 */ + int RedundantNullCheckOnNonNullLocalVariable = Internal + 457; + /** @since 3.3 */ + int NonNullLocalVariableComparisonYieldsFalse = Internal + 458; + // block /** @since 3.0 */ int UndocumentedEmptyBlock = Internal + 460; Index: compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java,v retrieving revision 1.65 diff -u -r1.65 EqualExpression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java 26 Apr 2006 09:17:30 -0000 1.65 +++ compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java 1 Mar 2007 12:04:20 -0000 @@ -36,21 +36,26 @@ private void checkVariableComparison(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo, FlowInfo initsWhenTrue, FlowInfo initsWhenFalse, LocalVariableBinding local, int nullStatus, Expression reference) { switch (nullStatus) { case FlowInfo.NULL : - flowContext.recordUsingNullReference(scope, local, reference, - FlowContext.CAN_ONLY_NULL_NON_NULL, flowInfo); if (((this.bits & OperatorMASK) >> OperatorSHIFT) == EQUAL_EQUAL) { + flowContext.recordUsingNullReference(scope, local, reference, + FlowContext.CAN_ONLY_NULL_NON_NULL | FlowContext.IN_COMPARISON_NULL, flowInfo); initsWhenTrue.markAsComparedEqualToNull(local); // from thereon it is set initsWhenFalse.markAsComparedEqualToNonNull(local); // from thereon it is set } else { + flowContext.recordUsingNullReference(scope, local, reference, + FlowContext.CAN_ONLY_NULL_NON_NULL | FlowContext.IN_COMPARISON_NON_NULL, flowInfo); initsWhenTrue.markAsComparedEqualToNonNull(local); // from thereon it is set initsWhenFalse.markAsComparedEqualToNull(local); // from thereon it is set } break; case FlowInfo.NON_NULL : - flowContext.recordUsingNullReference(scope, local, reference, - FlowContext.CAN_ONLY_NULL, flowInfo); if (((this.bits & OperatorMASK) >> OperatorSHIFT) == EQUAL_EQUAL) { + flowContext.recordUsingNullReference(scope, local, reference, + FlowContext.CAN_ONLY_NULL | FlowContext.IN_COMPARISON_NON_NULL, flowInfo); initsWhenTrue.markAsComparedEqualToNonNull(local); // from thereon it is set + } else { + flowContext.recordUsingNullReference(scope, local, reference, + FlowContext.CAN_ONLY_NULL | FlowContext.IN_COMPARISON_NULL, flowInfo); } break; } Index: compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java,v retrieving revision 1.53 diff -u -r1.53 InstanceOfExpression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java 28 Oct 2006 04:11:27 -0000 1.53 +++ compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java 1 Mar 2007 12:04:21 -0000 @@ -38,7 +38,7 @@ LocalVariableBinding local = this.expression.localVariableBinding(); if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) { flowContext.recordUsingNullReference(currentScope, local, - this.expression, FlowContext.CAN_ONLY_NULL, flowInfo); + this.expression, FlowContext.CAN_ONLY_NULL | FlowContext.IN_INSTANCEOF, flowInfo); flowInfo = expression.analyseCode(currentScope, flowContext, flowInfo). unconditionalInits(); FlowInfo initsWhenTrue = flowInfo.copy(); Index: compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java,v retrieving revision 1.76 diff -u -r1.76 Assignment.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 11 Jan 2007 15:34:31 -0000 1.76 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 1 Mar 2007 12:04:20 -0000 @@ -42,7 +42,7 @@ if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) { if (nullStatus == FlowInfo.NULL) { flowContext.recordUsingNullReference(currentScope, local, this.lhs, - FlowContext.CAN_ONLY_NULL, flowInfo); + FlowContext.CAN_ONLY_NULL | FlowContext.IN_ASSIGNMENT, flowInfo); } } flowInfo = ((Reference) lhs) Index: compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties,v retrieving revision 1.217 diff -u -r1.217 messages.properties --- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 26 Feb 2007 08:48:59 -0000 1.217 +++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 1 Mar 2007 12:04:23 -0000 @@ -320,13 +320,12 @@ ###[obsolete] 394 = The imported type {0} is defined in an inherited type and an enclosing scope 391 = The static import {0} must be a field or member type -392 = The variable {0} can only be null; it was either set to null or checked for null when last used 395 = Duplicate modifier for the variable {0} 396 = Illegal modifier for the variable {0}; only final is permitted -397 = The variable {0} cannot be null; it was either set to a non-null value or assumed to be non-null when last used -398 = The variable {0} can only be null; it was either set to null or checked for null when last used -399 = The variable {0} may be null +###[obsolete] 397 = Redundant null check: The variable {0} cannot be null at this location +###[obsolete] 398 = Null pointer access: The variable {0} can only be null at this location +###[obsolete] 399 = Potential null pointer access: The variable {0} may be null at this location 400 = The type {3} must implement the inherited abstract method {2}.{0}({1}) 401 = Cannot override the final method from {0} @@ -362,6 +361,15 @@ 450 = {0} {1} +451 = Null pointer access: The variable {0} can only be null at this location +452 = Potential null pointer access: The variable {0} may be null at this location +453 = Redundant null check: The variable {0} can only be null at this location +454 = Null comparison always yields false: The variable {0} can only be null at this location +455 = Redundant assignment: The variable {0} can only be null at this location +456 = instanceof always yields false: The variable {0} can only be null at this location +457 = Redundant null check: The variable {0} cannot be null at this location +458 = Null comparison always yields false: The variable {0} cannot be null at this location + 460 = Empty block should be documented ### DOC Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v retrieving revision 1.342 diff -u -r1.342 ProblemReporter.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 26 Feb 2007 08:48:59 -0000 1.342 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 1 Mar 2007 12:04:23 -0000 @@ -184,14 +184,18 @@ case IProblem.ConstructorVarargsArgumentNeedCast : return CompilerOptions.VarargsArgumentNeedCast; - case IProblem.LocalVariableCanOnlyBeNull: + case IProblem.NullLocalVariableReference: return CompilerOptions.NullReference; - case IProblem.LocalVariableMayBeNull: + case IProblem.PotentialNullLocalVariableReference: return CompilerOptions.PotentialNullReference; - case IProblem.LocalVariableCannotBeNull: - case IProblem.LocalVariableRedundantCheckOnNull: + case IProblem.RedundantLocalVariableNullAssignment: + case IProblem.RedundantNullCheckOnNonNullLocalVariable: + case IProblem.RedundantNullCheckOnNullLocalVariable: + case IProblem.NonNullLocalVariableComparisonYieldsFalse: + case IProblem.NullLocalVariableComparisonYieldsFalse: + case IProblem.NullLocalVariableInstanceofYieldsFalse: return CompilerOptions.RedundantNullCheck; case IProblem.BoxingConversion : @@ -4385,30 +4389,6 @@ } return argument; } -public void localVariableCannotBeNull(LocalVariableBinding local, ASTNode location) { - int severity = computeSeverity(IProblem.LocalVariableCannotBeNull); - if (severity == ProblemSeverities.Ignore) return; - String[] arguments = new String[] {new String(local.name) }; - this.handle( - IProblem.LocalVariableCannotBeNull, - arguments, - arguments, - severity, - nodeSourceStart(local, location), - nodeSourceEnd(local, location)); -} -public void localVariableCanOnlyBeNull(LocalVariableBinding local, ASTNode location) { - int severity = computeSeverity(IProblem.LocalVariableCanOnlyBeNull); - if (severity == ProblemSeverities.Ignore) return; - String[] arguments = new String[] {new String(local.name) }; - this.handle( - IProblem.LocalVariableCanOnlyBeNull, - arguments, - arguments, - severity, - nodeSourceStart(local, location), - nodeSourceEnd(local, location)); -} public void localVariableHiding(LocalDeclaration local, Binding hiddenVariable, boolean isSpecialArgHidingField) { if (hiddenVariable instanceof LocalVariableBinding) { int id = (local instanceof Argument) @@ -4443,12 +4423,72 @@ local.sourceEnd); } } -public void localVariableMayBeNull(LocalVariableBinding local, ASTNode location) { - int severity = computeSeverity(IProblem.LocalVariableMayBeNull); +public void localVariableNonNullComparedToNull(LocalVariableBinding local, ASTNode location) { + int severity = computeSeverity(IProblem.NonNullLocalVariableComparisonYieldsFalse); + if (severity == ProblemSeverities.Ignore) return; + String[] arguments = new String[] {new String(local.name) }; + this.handle( + IProblem.NonNullLocalVariableComparisonYieldsFalse, + arguments, + arguments, + severity, + nodeSourceStart(local, location), + nodeSourceEnd(local, location)); +} +public void localVariableNullComparedToNonNull(LocalVariableBinding local, ASTNode location) { + int severity = computeSeverity(IProblem.NullLocalVariableComparisonYieldsFalse); + if (severity == ProblemSeverities.Ignore) return; + String[] arguments = new String[] {new String(local.name) }; + this.handle( + IProblem.NullLocalVariableComparisonYieldsFalse, + arguments, + arguments, + severity, + nodeSourceStart(local, location), + nodeSourceEnd(local, location)); +} +public void localVariableNullInstanceof(LocalVariableBinding local, ASTNode location) { + int severity = computeSeverity(IProblem.NullLocalVariableInstanceofYieldsFalse); + if (severity == ProblemSeverities.Ignore) return; + String[] arguments = new String[] {new String(local.name) }; + this.handle( + IProblem.NullLocalVariableInstanceofYieldsFalse, + arguments, + arguments, + severity, + nodeSourceStart(local, location), + nodeSourceEnd(local, location)); +} +public void localVariableNullReference(LocalVariableBinding local, ASTNode location) { + int severity = computeSeverity(IProblem.NullLocalVariableReference); + if (severity == ProblemSeverities.Ignore) return; + String[] arguments = new String[] {new String(local.name) }; + this.handle( + IProblem.NullLocalVariableReference, + arguments, + arguments, + severity, + nodeSourceStart(local, location), + nodeSourceEnd(local, location)); +} +public void localVariablePotentialNullReference(LocalVariableBinding local, ASTNode location) { + int severity = computeSeverity(IProblem.PotentialNullLocalVariableReference); if (severity == ProblemSeverities.Ignore) return; String[] arguments = new String[] {new String(local.name)}; this.handle( - IProblem.LocalVariableMayBeNull, + IProblem.PotentialNullLocalVariableReference, + arguments, + arguments, + severity, + nodeSourceStart(local, location), + nodeSourceEnd(local, location)); +} +public void localVariableRedundantCheckOnNonNull(LocalVariableBinding local, ASTNode location) { + int severity = computeSeverity(IProblem.RedundantNullCheckOnNonNullLocalVariable); + if (severity == ProblemSeverities.Ignore) return; + String[] arguments = new String[] {new String(local.name) }; + this.handle( + IProblem.RedundantNullCheckOnNonNullLocalVariable, arguments, arguments, severity, @@ -4456,11 +4496,23 @@ nodeSourceEnd(local, location)); } public void localVariableRedundantCheckOnNull(LocalVariableBinding local, ASTNode location) { - int severity = computeSeverity(IProblem.LocalVariableRedundantCheckOnNull); + int severity = computeSeverity(IProblem.RedundantNullCheckOnNullLocalVariable); + if (severity == ProblemSeverities.Ignore) return; + String[] arguments = new String[] {new String(local.name) }; + this.handle( + IProblem.RedundantNullCheckOnNullLocalVariable, + arguments, + arguments, + severity, + nodeSourceStart(local, location), + nodeSourceEnd(local, location)); +} +public void localVariableRedundantNullAssignment(LocalVariableBinding local, ASTNode location) { + int severity = computeSeverity(IProblem.RedundantLocalVariableNullAssignment); if (severity == ProblemSeverities.Ignore) return; String[] arguments = new String[] {new String(local.name) }; this.handle( - IProblem.LocalVariableRedundantCheckOnNull, + IProblem.RedundantLocalVariableNullAssignment, arguments, arguments, severity, Index: compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java,v retrieving revision 1.22 diff -u -r1.22 FinallyFlowContext.java --- compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 26 Feb 2007 08:48:59 -0000 1.22 +++ compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 1 Mar 2007 12:04:21 -0000 @@ -92,23 +92,44 @@ // final local variable LocalVariableBinding local = this.nullLocals[i]; switch (this.nullCheckTypes[i]) { - case CAN_ONLY_NULL_NON_NULL : + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL: if (flowInfo.isDefinitelyNonNull(local)) { - scope.problemReporter().localVariableCannotBeNull(local, expression); + if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { + scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression); + } else { + scope.problemReporter().localVariableNonNullComparedToNull(local, expression); + } continue; } - case CAN_ONLY_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NON_NULL: + case CAN_ONLY_NULL | IN_ASSIGNMENT: + case CAN_ONLY_NULL | IN_INSTANCEOF: if (flowInfo.isDefinitelyNull(local)) { - scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); + switch(this.nullCheckTypes[i] & CONTEXT_MASK) { + case FlowContext.IN_COMPARISON_NULL: + scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); + continue; + case FlowContext.IN_COMPARISON_NON_NULL: + scope.problemReporter().localVariableNullComparedToNonNull(local, expression); + continue; + case FlowContext.IN_ASSIGNMENT: + scope.problemReporter().localVariableRedundantNullAssignment(local, expression); + continue; + case FlowContext.IN_INSTANCEOF: + scope.problemReporter().localVariableNullInstanceof(local, expression); + continue; + } } break; - case MAY_NULL : + case MAY_NULL: if (flowInfo.isDefinitelyNull(local)) { - scope.problemReporter().localVariableCanOnlyBeNull(local, expression); + scope.problemReporter().localVariableNullReference(local, expression); continue; } if (flowInfo.isPotentiallyNull(local)) { - scope.problemReporter().localVariableMayBeNull(local, expression); + scope.problemReporter().localVariablePotentialNullReference(local, expression); } break; default: @@ -161,17 +182,35 @@ if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { if (deferNullDiagnostic) { // within an enclosing loop, be conservative switch (checkType) { - case CAN_ONLY_NULL_NON_NULL : - case CAN_ONLY_NULL: + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NON_NULL: + case CAN_ONLY_NULL | IN_ASSIGNMENT: + case CAN_ONLY_NULL | IN_INSTANCEOF: if (flowInfo.cannotBeNull(local)) { - if (checkType == CAN_ONLY_NULL_NON_NULL) { - scope.problemReporter().localVariableCannotBeNull(local, reference); + if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { + scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); + } else { + scope.problemReporter().localVariableNonNullComparedToNull(local, reference); } return; } if (flowInfo.canOnlyBeNull(local)) { - scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); - return; + switch(checkType & CONTEXT_MASK) { + case FlowContext.IN_COMPARISON_NULL: + scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); + return; + case FlowContext.IN_COMPARISON_NON_NULL: + scope.problemReporter().localVariableNullComparedToNonNull(local, reference); + return; + case FlowContext.IN_ASSIGNMENT: + scope.problemReporter().localVariableRedundantNullAssignment(local, reference); + return; + case FlowContext.IN_INSTANCEOF: + scope.problemReporter().localVariableNullInstanceof(local, reference); + return; + } } break; case MAY_NULL : @@ -179,7 +218,7 @@ return; } if (flowInfo.canOnlyBeNull(local)) { - scope.problemReporter().localVariableCanOnlyBeNull(local, reference); + scope.problemReporter().localVariableNullReference(local, reference); return; } break; @@ -189,24 +228,44 @@ } else { // no enclosing loop, be as precise as possible right now switch (checkType) { - case CAN_ONLY_NULL_NON_NULL : + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL: if (flowInfo.isDefinitelyNonNull(local)) { - scope.problemReporter().localVariableCannotBeNull(local, reference); + if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { + scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); + } else { + scope.problemReporter().localVariableNonNullComparedToNull(local, reference); + } return; } - case CAN_ONLY_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NON_NULL: + case CAN_ONLY_NULL | IN_ASSIGNMENT: + case CAN_ONLY_NULL | IN_INSTANCEOF: if (flowInfo.isDefinitelyNull(local)) { - scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); - return; + switch(checkType & CONTEXT_MASK) { + case FlowContext.IN_COMPARISON_NULL: + scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); + return; + case FlowContext.IN_COMPARISON_NON_NULL: + scope.problemReporter().localVariableNullComparedToNonNull(local, reference); + return; + case FlowContext.IN_ASSIGNMENT: + scope.problemReporter().localVariableRedundantNullAssignment(local, reference); + return; + case FlowContext.IN_INSTANCEOF: + scope.problemReporter().localVariableNullInstanceof(local, reference); + return; + } } break; case MAY_NULL : if (flowInfo.isDefinitelyNull(local)) { - scope.problemReporter().localVariableCanOnlyBeNull(local, reference); + scope.problemReporter().localVariableNullReference(local, reference); return; } if (flowInfo.isPotentiallyNull(local)) { - scope.problemReporter().localVariableMayBeNull(local, reference); + scope.problemReporter().localVariablePotentialNullReference(local, reference); return; } if (flowInfo.isDefinitelyNonNull(local)) { Index: compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java,v retrieving revision 1.36 diff -u -r1.36 LoopingFlowContext.java --- compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 26 Feb 2007 08:48:59 -0000 1.36 +++ compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 1 Mar 2007 12:04:21 -0000 @@ -121,36 +121,65 @@ Expression expression = this.nullReferences[i]; // final local variable switch (this.nullCheckTypes[i]) { - case CAN_ONLY_NON_NULL : + case CAN_ONLY_NON_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NON_NULL | IN_COMPARISON_NON_NULL: if (flowInfo.isDefinitelyNonNull(local)) { this.nullReferences[i] = null; - scope.problemReporter().localVariableCannotBeNull(local, expression); + if (this.nullCheckTypes[i] == (CAN_ONLY_NON_NULL | IN_COMPARISON_NON_NULL)) { + scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression); + } else { + scope.problemReporter().localVariableNonNullComparedToNull(local, expression); + } continue; } break; - case CAN_ONLY_NULL_NON_NULL : + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL: if (flowInfo.isDefinitelyNonNull(local)) { this.nullReferences[i] = null; - scope.problemReporter().localVariableCannotBeNull(local, expression); + if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { + scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression); + } else { + scope.problemReporter().localVariableNonNullComparedToNull(local, expression); + } continue; } if (flowInfo.isDefinitelyNull(local)) { this.nullReferences[i] = null; - scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); + if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) { + scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); + } else { + scope.problemReporter().localVariableNullComparedToNonNull(local, expression); + } continue; } break; - case CAN_ONLY_NULL : + case CAN_ONLY_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NON_NULL: + case CAN_ONLY_NULL | IN_ASSIGNMENT: + case CAN_ONLY_NULL | IN_INSTANCEOF: if (flowInfo.isDefinitelyNull(local)) { this.nullReferences[i] = null; - scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); - continue; + switch(this.nullCheckTypes[i] & CONTEXT_MASK) { + case FlowContext.IN_COMPARISON_NULL: + scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); + continue; + case FlowContext.IN_COMPARISON_NON_NULL: + scope.problemReporter().localVariableNullComparedToNonNull(local, expression); + continue; + case FlowContext.IN_ASSIGNMENT: + scope.problemReporter().localVariableRedundantNullAssignment(local, expression); + continue; + case FlowContext.IN_INSTANCEOF: + scope.problemReporter().localVariableNullInstanceof(local, expression); + continue; + } } break; case MAY_NULL: if (flowInfo.isDefinitelyNull(local)) { this.nullReferences[i] = null; - scope.problemReporter().localVariableCanOnlyBeNull(local, expression); + scope.problemReporter().localVariableNullReference(local, expression); continue; } break; @@ -168,28 +197,48 @@ // final local variable LocalVariableBinding local = this.nullLocals[i]; switch (this.nullCheckTypes[i]) { - case CAN_ONLY_NULL_NON_NULL : + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL: if (flowInfo.isDefinitelyNonNull(local)) { this.nullReferences[i] = null; - scope.problemReporter().localVariableCannotBeNull(local, expression); + if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { + scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression); + } else { + scope.problemReporter().localVariableNonNullComparedToNull(local, expression); + } continue; } - case CAN_ONLY_NULL : + case CAN_ONLY_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NON_NULL: + case CAN_ONLY_NULL | IN_ASSIGNMENT: + case CAN_ONLY_NULL | IN_INSTANCEOF: if (flowInfo.isDefinitelyNull(local)) { this.nullReferences[i] = null; - scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); - continue; + switch(this.nullCheckTypes[i] & CONTEXT_MASK) { + case FlowContext.IN_COMPARISON_NULL: + scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); + continue; + case FlowContext.IN_COMPARISON_NON_NULL: + scope.problemReporter().localVariableNullComparedToNonNull(local, expression); + continue; + case FlowContext.IN_ASSIGNMENT: + scope.problemReporter().localVariableRedundantNullAssignment(local, expression); + continue; + case FlowContext.IN_INSTANCEOF: + scope.problemReporter().localVariableNullInstanceof(local, expression); + continue; + } } break; case MAY_NULL: if (flowInfo.isDefinitelyNull(local)) { this.nullReferences[i] = null; - scope.problemReporter().localVariableCanOnlyBeNull(local, expression); + scope.problemReporter().localVariableNullReference(local, expression); continue; } if (flowInfo.isPotentiallyNull(local)) { this.nullReferences[i] = null; - scope.problemReporter().localVariableMayBeNull(local, expression); + scope.problemReporter().localVariablePotentialNullReference(local, expression); continue; } break; @@ -323,32 +372,51 @@ return; } switch (checkType) { - case CAN_ONLY_NULL_NON_NULL : + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL: if (flowInfo.isDefinitelyNonNull(local)) { - scope.problemReporter().localVariableCannotBeNull(local, reference); - return; - } - if (flowInfo.isDefinitelyNull(local)) { - scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); - return; - } - if (flowInfo.cannotBeDefinitelyNullOrNonNull(local)) { - return; - } - if (flowInfo.isPotentiallyNonNull(local)) { - recordNullReference(local, reference,CAN_ONLY_NON_NULL); - } else { - recordNullReference(local, reference, checkType); + if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { + scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); + } else { + scope.problemReporter().localVariableNonNullComparedToNull(local, reference); + } + } else if (flowInfo.isDefinitelyNull(local)) { + if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) { + scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); + } else { + scope.problemReporter().localVariableNullComparedToNonNull(local, reference); + } + } else if (! flowInfo.cannotBeDefinitelyNullOrNonNull(local)) { + if (flowInfo.isPotentiallyNonNull(local)) { + recordNullReference(local, reference, CAN_ONLY_NON_NULL | checkType & CONTEXT_MASK); + } else { + recordNullReference(local, reference, checkType); + } } return; - case CAN_ONLY_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NON_NULL: + case CAN_ONLY_NULL | IN_ASSIGNMENT: + case CAN_ONLY_NULL | IN_INSTANCEOF: if (flowInfo.isPotentiallyNonNull(local) || flowInfo.isPotentiallyUnknown(local)) { return; } if (flowInfo.isDefinitelyNull(local)) { - scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); - return; + switch(checkType & CONTEXT_MASK) { + case FlowContext.IN_COMPARISON_NULL: + scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); + return; + case FlowContext.IN_COMPARISON_NON_NULL: + scope.problemReporter().localVariableNullComparedToNonNull(local, reference); + return; + case FlowContext.IN_ASSIGNMENT: + scope.problemReporter().localVariableRedundantNullAssignment(local, reference); + return; + case FlowContext.IN_INSTANCEOF: + scope.problemReporter().localVariableNullInstanceof(local, reference); + return; + } } recordNullReference(local, reference, checkType); return; @@ -357,11 +425,11 @@ return; } if (flowInfo.isDefinitelyNull(local)) { - scope.problemReporter().localVariableCanOnlyBeNull(local, reference); + scope.problemReporter().localVariableNullReference(local, reference); return; } if (flowInfo.isPotentiallyNull(local)) { - scope.problemReporter().localVariableMayBeNull(local, reference); + scope.problemReporter().localVariablePotentialNullReference(local, reference); return; } recordNullReference(local, reference, checkType); Index: compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java,v retrieving revision 1.54 diff -u -r1.54 FlowContext.java --- compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 26 Feb 2007 08:48:59 -0000 1.54 +++ compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 1 Mar 2007 12:04:21 -0000 @@ -437,7 +437,10 @@ * @param expression the expression within which local lays * @param status the status against which the check must be performed; one of * {@link #CAN_ONLY_NULL CAN_ONLY_NULL}, {@link #CAN_ONLY_NULL_NON_NULL - * CAN_ONLY_NULL_NON_NULL}, {@link #MAY_NULL MAY_NULL} + * CAN_ONLY_NULL_NON_NULL}, {@link #MAY_NULL MAY_NULL}, + * {@link #CAN_ONLY_NON_NULL CAN_ONLY_NON_NULL}, potentially + * combined with a context indicator (one of {@link #IN_COMPARISON_NULL}, + * {@link #IN_COMPARISON_NON_NULL}, {@link #IN_ASSIGNMENT} or {@link #IN_INSTANCEOF}) */ protected void recordNullReference(LocalVariableBinding local, Expression expression, int status) { @@ -462,15 +465,23 @@ } public static final int - CAN_ONLY_NULL_NON_NULL = 20, + CAN_ONLY_NULL_NON_NULL = 0x0000, // check against null and non null, with definite values -- comparisons - CAN_ONLY_NULL = 21, - // check against null, with definite values -- assignment to null - MAY_NULL = 22, + CAN_ONLY_NULL = 0x0001, + // check against null, with definite values -- comparisons + CAN_ONLY_NON_NULL = 0x0002, + // check against non null, with definite values -- comparisons + MAY_NULL = 0x0003, // check against null, with potential values -- NPE guard - CAN_ONLY_NON_NULL = 23; - // subcase of CAN_ONLY_NULL_NON_NULL, in which we know that the local - // may be non null + CHECK_MASK = 0x00FF, + IN_COMPARISON_NULL = 0x0100, + IN_COMPARISON_NON_NULL = 0x0200, + // check happened in a comparison + IN_ASSIGNMENT = 0x0300, + // check happened in an assignment + IN_INSTANCEOF = 0x0400, + // check happened in an instanceof expression + CONTEXT_MASK = ~CHECK_MASK; /** * Record a null reference for use by deferred checks. Only looping or @@ -485,7 +496,9 @@ * @param reference the expression within which local lies * @param checkType the status against which the check must be performed; one * of {@link #CAN_ONLY_NULL CAN_ONLY_NULL}, {@link #CAN_ONLY_NULL_NON_NULL - * CAN_ONLY_NULL_NON_NULL}, {@link #MAY_NULL MAY_NULL} + * CAN_ONLY_NULL_NON_NULL}, {@link #MAY_NULL MAY_NULL}, potentially + * combined with a context indicator (one of {@link #IN_COMPARISON_NULL}, + * {@link #IN_COMPARISON_NON_NULL}, {@link #IN_ASSIGNMENT} or {@link #IN_INSTANCEOF}) * @param flowInfo the flow info at the check point; deferring contexts will * perform supplementary checks against flow info instances that cannot * be known at the time of calling this method (they are influenced by @@ -498,30 +511,49 @@ return; } switch (checkType) { - case CAN_ONLY_NULL_NON_NULL : + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL: if (flowInfo.isDefinitelyNonNull(local)) { - scope.problemReporter().localVariableCannotBeNull(local, reference); + if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { + scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); + } else { + scope.problemReporter().localVariableNonNullComparedToNull(local, reference); + } return; } else if (flowInfo.cannotBeDefinitelyNullOrNonNull(local)) { return; } - case CAN_ONLY_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NULL: + case CAN_ONLY_NULL | IN_COMPARISON_NON_NULL: + case CAN_ONLY_NULL | IN_ASSIGNMENT: + case CAN_ONLY_NULL | IN_INSTANCEOF: if (flowInfo.isDefinitelyNull(local)) { - scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); - return; - } - else if (flowInfo.cannotBeDefinitelyNullOrNonNull(local)) { + switch(checkType & CONTEXT_MASK) { + case FlowContext.IN_COMPARISON_NULL: + scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); + return; + case FlowContext.IN_COMPARISON_NON_NULL: + scope.problemReporter().localVariableNullComparedToNonNull(local, reference); + return; + case FlowContext.IN_ASSIGNMENT: + scope.problemReporter().localVariableRedundantNullAssignment(local, reference); + return; + case FlowContext.IN_INSTANCEOF: + scope.problemReporter().localVariableNullInstanceof(local, reference); + return; + } + } else if (flowInfo.cannotBeDefinitelyNullOrNonNull(local)) { return; } break; case MAY_NULL : if (flowInfo.isDefinitelyNull(local)) { - scope.problemReporter().localVariableCanOnlyBeNull(local, reference); + scope.problemReporter().localVariableNullReference(local, reference); return; } if (flowInfo.isPotentiallyNull(local)) { - scope.problemReporter().localVariableMayBeNull(local, reference); + scope.problemReporter().localVariablePotentialNullReference(local, reference); return; } break;