Lines 33-39
Link Here
|
33 |
// -Dcompliance=1.4 (for example) to lower it if needed |
33 |
// -Dcompliance=1.4 (for example) to lower it if needed |
34 |
static { |
34 |
static { |
35 |
// TESTS_NAMES = new String[] { "test011" }; |
35 |
// TESTS_NAMES = new String[] { "test011" }; |
36 |
// TESTS_NUMBERS = new int[] { 729 }; |
36 |
// TESTS_NUMBERS = new int[] { 333 }; |
37 |
// TESTS_NUMBERS = new int[] { 2999 }; |
37 |
// TESTS_NUMBERS = new int[] { 2999 }; |
38 |
// TESTS_RANGE = new int[] { 2050, -1 }; |
38 |
// TESTS_RANGE = new int[] { 2050, -1 }; |
39 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
39 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
Lines 1223-1233
Link Here
|
1223 |
" if (o == null && o == null) {\n" + |
1223 |
" if (o == null && o == null) {\n" + |
1224 |
" ^\n" + |
1224 |
" ^\n" + |
1225 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
1225 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
1226 |
"----------\n" + |
|
|
1227 |
"2. ERROR in X.java (at line 6)\n" + |
1228 |
" if (o == null) { /* */ }\n" + |
1229 |
" ^\n" + |
1230 |
"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" + |
1231 |
"----------\n"); |
1226 |
"----------\n"); |
1232 |
} |
1227 |
} |
1233 |
|
1228 |
|
Lines 1601-1615
Link Here
|
1601 |
} |
1596 |
} |
1602 |
|
1597 |
|
1603 |
// null analysis - if/else |
1598 |
// null analysis - if/else |
1604 |
// PMT: exactly the case we talked about; what happens is that the first |
1599 |
// rationale: erroneous tests no more change null status |
1605 |
// if shade doubts upon o; what we could do is to avoid marking in case |
|
|
1606 |
// of error? not sure this is appropriate though, because of inner code |
1607 |
// into the if itself; I believe I somewhat did that on purpose: the latest |
1608 |
// wins; completed with o.toString()... |
1609 |
// basically, the choice is about what we should do in case of error: |
1610 |
// neglect the effect of the error, or propagate this effect; the second |
1611 |
// tends to produce less repeated errors (I believe) than the first... |
1612 |
// PREMATURE could refine adding a null-dependent reachable mark... not urgent |
1613 |
public void test0312_if_else() { |
1600 |
public void test0312_if_else() { |
1614 |
this.runNegativeTest( |
1601 |
this.runNegativeTest( |
1615 |
new String[] { |
1602 |
new String[] { |
Lines 1619-1626
Link Here
|
1619 |
" void foo() {\n" + |
1606 |
" void foo() {\n" + |
1620 |
" Object o = new Object();\n" + |
1607 |
" Object o = new Object();\n" + |
1621 |
" if (o == null) { /* */ }\n" + // complain |
1608 |
" if (o == null) { /* */ }\n" + // complain |
1622 |
" if (o != null) { /* */ }\n" + // quiet |
1609 |
" if (o != null) { /* */ }\n" + // complain |
1623 |
" o.toString();\n" + // complain |
1610 |
" o.toString();\n" + // quiet |
1624 |
" }\n" + |
1611 |
" }\n" + |
1625 |
"}\n"}, |
1612 |
"}\n"}, |
1626 |
"----------\n" + |
1613 |
"----------\n" + |
Lines 1629-1638
Link Here
|
1629 |
" ^\n" + |
1616 |
" ^\n" + |
1630 |
"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" + |
1617 |
"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" + |
1631 |
"----------\n" + |
1618 |
"----------\n" + |
1632 |
"2. ERROR in X.java (at line 7)\n" + |
1619 |
"2. ERROR in X.java (at line 6)\n" + |
1633 |
" o.toString();\n" + |
1620 |
" if (o != null) { /* */ }\n" + |
1634 |
" ^\n" + |
1621 |
" ^\n" + |
1635 |
"The variable o may be null\n" + |
1622 |
"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" + |
1636 |
"----------\n"); |
1623 |
"----------\n"); |
1637 |
} |
1624 |
} |
1638 |
|
1625 |
|
Lines 2062-2067
Link Here
|
2062 |
"----------\n"); |
2049 |
"----------\n"); |
2063 |
} |
2050 |
} |
2064 |
|
2051 |
|
|
|
2052 |
// null analysis - if/else |
2053 |
// avoid double diagnostic (Frédéric) |
2054 |
public void test0333_if_else() { |
2055 |
this.runNegativeTest( |
2056 |
new String[] { |
2057 |
"X.java", |
2058 |
"public class X {\n" + |
2059 |
" void foo(Object[] o) {\n" + |
2060 |
" if (o != null) {\n" + |
2061 |
" int length = o == null ? 0 : o.length;\n" + // complain |
2062 |
" for (int i = 0; i < length; i++) {\n" + |
2063 |
" o[i].toString();\n" + // quiet, protected by if above |
2064 |
" }\n" + |
2065 |
" }\n" + |
2066 |
" }\n" + |
2067 |
"}"}, |
2068 |
"----------\n" + |
2069 |
"1. ERROR in X.java (at line 4)\n" + |
2070 |
" int length = o == null ? 0 : o.length;\n" + |
2071 |
" ^\n" + |
2072 |
"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" + |
2073 |
"----------\n"); |
2074 |
} |
2075 |
|
2065 |
// null analysis -- while |
2076 |
// null analysis -- while |
2066 |
public void test0401_while() { |
2077 |
public void test0401_while() { |
2067 |
this.runNegativeTest( |
2078 |
this.runNegativeTest( |
Lines 2551-2557
Link Here
|
2551 |
} |
2562 |
} |
2552 |
|
2563 |
|
2553 |
// null analysis -- while |
2564 |
// null analysis -- while |
2554 |
// REVIEW we get one extraneous message that looks a bit strange |
|
|
2555 |
public void test0423_while() { |
2565 |
public void test0423_while() { |
2556 |
this.runNegativeTest( |
2566 |
this.runNegativeTest( |
2557 |
new String[] { |
2567 |
new String[] { |
Lines 2572-2582
Link Here
|
2572 |
" if (o == null) { /* */ }\n" + |
2582 |
" if (o == null) { /* */ }\n" + |
2573 |
" ^\n" + |
2583 |
" ^\n" + |
2574 |
"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" + |
2584 |
"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" + |
2575 |
"----------\n" + |
|
|
2576 |
"2. ERROR in X.java (at line 8)\n" + |
2577 |
" o = null;\n" + |
2578 |
" ^\n" + |
2579 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
2580 |
"----------\n"); |
2585 |
"----------\n"); |
2581 |
} |
2586 |
} |
2582 |
|
2587 |
|
Lines 5230-5235
Link Here
|
5230 |
} |
5235 |
} |
5231 |
|
5236 |
|
5232 |
// moved from AssignmentTest |
5237 |
// moved from AssignmentTest |
|
|
5238 |
// new policy (do not modify null info in case of problem in comparison) |
5239 |
// removes errors on 8 - which is better, and 3 - which might be |
5240 |
// questionable |
5233 |
public void test1004() { |
5241 |
public void test1004() { |
5234 |
this.runNegativeTest( |
5242 |
this.runNegativeTest( |
5235 |
new String[] { |
5243 |
new String[] { |
Lines 5261-5280
Link Here
|
5261 |
" ^\n" + |
5269 |
" ^\n" + |
5262 |
"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" + |
5270 |
"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" + |
5263 |
"----------\n" + |
5271 |
"----------\n" + |
5264 |
"3. ERROR in X.java (at line 6)\n" + |
5272 |
"3. ERROR in X.java (at line 9)\n" + |
5265 |
" x.foo(null); // 3\n" + |
|
|
5266 |
" ^\n" + |
5267 |
"The variable x can only be null; it was either set to null or checked for null when last used\n" + |
5268 |
"----------\n" + |
5269 |
"4. ERROR in X.java (at line 9)\n" + |
5270 |
" } else if (x != null) { // 6\n" + |
5273 |
" } else if (x != null) { // 6\n" + |
5271 |
" ^\n" + |
5274 |
" ^\n" + |
5272 |
"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" + |
5275 |
"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" + |
5273 |
"----------\n" + |
|
|
5274 |
"5. ERROR in X.java (at line 12)\n" + |
5275 |
" x.foo(null); // 8\n" + |
5276 |
" ^\n" + |
5277 |
"The variable x may be null\n" + |
5278 |
"----------\n"); |
5276 |
"----------\n"); |
5279 |
} |
5277 |
} |
5280 |
|
5278 |
|
Lines 5428-5433
Link Here
|
5428 |
" if (other != null) {\n" + |
5426 |
" if (other != null) {\n" + |
5429 |
" ^^^^^\n" + |
5427 |
" ^^^^^\n" + |
5430 |
"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" + |
5428 |
"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" + |
|
|
5429 |
"----------\n" + |
5430 |
"2. ERROR in X.java (at line 11)\n" + |
5431 |
" if (other == null) {\n" + |
5432 |
" ^^^^^\n" + |
5433 |
"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" + |
5431 |
"----------\n"); |
5434 |
"----------\n"); |
5432 |
} |
5435 |
} |
5433 |
|
5436 |
|
Lines 5459-5465
Link Here
|
5459 |
); |
5462 |
); |
5460 |
} |
5463 |
} |
5461 |
|
5464 |
|
5462 |
// REVIEW here we do not catch the dead branch: x cannot equal this then null with no assignment in between |
|
|
5463 |
public void test1013() { |
5465 |
public void test1013() { |
5464 |
this.runNegativeTest( |
5466 |
this.runNegativeTest( |
5465 |
new String[] { |
5467 |
new String[] { |
Lines 5478-5488
Link Here
|
5478 |
" if (x == null) {\n" + |
5480 |
" if (x == null) {\n" + |
5479 |
" ^\n" + |
5481 |
" ^\n" + |
5480 |
"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" + |
5482 |
"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" + |
5481 |
"----------\n" + |
|
|
5482 |
"2. ERROR in X.java (at line 5)\n" + |
5483 |
" x.foo(this);\n" + |
5484 |
" ^\n" + |
5485 |
"The variable x can only be null; it was either set to null or checked for null when last used\n" + |
5486 |
"----------\n"); |
5483 |
"----------\n"); |
5487 |
} |
5484 |
} |
5488 |
|
5485 |
|
Lines 5988-5994
Link Here
|
5988 |
"2. ERROR in X.java (at line 8)\n" + |
5985 |
"2. ERROR in X.java (at line 8)\n" + |
5989 |
" if(a!=null)\n" + |
5986 |
" if(a!=null)\n" + |
5990 |
" ^\n" + |
5987 |
" ^\n" + |
5991 |
"The variable a can only be null; it was either set to null or checked for null when last used\n" + |
5988 |
"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" + |
5992 |
"----------\n"); |
5989 |
"----------\n"); |
5993 |
} |
5990 |
} |
5994 |
|
5991 |
|
Lines 6082-6088
Link Here
|
6082 |
" o60 = o0, o61 = o0, o62 = o0, o63 = o0, o64 = o0,\n" + |
6079 |
" o60 = o0, o61 = o0, o62 = o0, o63 = o0, o64 = o0,\n" + |
6083 |
" o65 = o0, o66 = o0, o67 = o0, o68 = o0, o69 = o0;\n" + |
6080 |
" o65 = o0, o66 = o0, o67 = o0, o68 = o0, o69 = o0;\n" + |
6084 |
" if (o65 == null) { /* */ }\n" + // complain |
6081 |
" if (o65 == null) { /* */ }\n" + // complain |
6085 |
" if (o65 != null) { /* */ }\n" + // quiet (already reported) |
6082 |
" if (o65 != null) { /* */ }\n" + // complain |
6086 |
" }\n" + |
6083 |
" }\n" + |
6087 |
"}\n"}, |
6084 |
"}\n"}, |
6088 |
"----------\n" + |
6085 |
"----------\n" + |
Lines 6090-6095
Link Here
|
6090 |
" if (o65 == null) { /* */ }\n" + |
6087 |
" if (o65 == null) { /* */ }\n" + |
6091 |
" ^^^\n" + |
6088 |
" ^^^\n" + |
6092 |
"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" + |
6089 |
"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" + |
|
|
6090 |
"----------\n" + |
6091 |
"2. ERROR in X.java (at line 19)\n" + |
6092 |
" if (o65 != null) { /* */ }\n" + |
6093 |
" ^^^\n" + |
6094 |
"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" + |
6093 |
"----------\n"); |
6095 |
"----------\n"); |
6094 |
} |
6096 |
} |
6095 |
|
6097 |
|