Lines 5093-5098
Link Here
|
5093 |
"----------\n"); |
5093 |
"----------\n"); |
5094 |
} |
5094 |
} |
5095 |
|
5095 |
|
|
|
5096 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 |
5097 |
// [compiler] Null reference analysis doesn't understand assertions |
5098 |
public void test0950_assert() { |
5099 |
if (COMPLIANCE_1_3.compareTo(this.complianceLevel) < 0) { |
5100 |
this.runConformTest( |
5101 |
new String[] { |
5102 |
"X.java", |
5103 |
"public class X {\n" + |
5104 |
" void foo(Object o) {\n" + |
5105 |
" boolean b = o != null;\n" + // shades doubts upon o |
5106 |
" assert(o != null);\n" + // protection |
5107 |
" o.toString();\n" + // quiet |
5108 |
" }\n" + |
5109 |
"}\n"}, |
5110 |
""); |
5111 |
} |
5112 |
} |
5113 |
|
5114 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 |
5115 |
// [compiler] Null reference analysis doesn't understand assertions |
5116 |
public void test0951_assert() { |
5117 |
if (COMPLIANCE_1_3.compareTo(this.complianceLevel) < 0) { |
5118 |
this.runNegativeTest( |
5119 |
new String[] { |
5120 |
"X.java", |
5121 |
"public class X {\n" + |
5122 |
" void foo(Object o) {\n" + |
5123 |
" assert(o == null);\n" + // forces null |
5124 |
" o.toString();\n" + // can only be null |
5125 |
" }\n" + |
5126 |
"}\n"}, |
5127 |
"----------\n" + |
5128 |
"1. ERROR in X.java (at line 4)\n" + |
5129 |
" o.toString();\n" + |
5130 |
" ^\n" + |
5131 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
5132 |
"----------\n"); |
5133 |
} |
5134 |
} |
5135 |
|
5136 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 |
5137 |
// [compiler] Null reference analysis doesn't understand assertions |
5138 |
public void test0952_assert() { |
5139 |
if (COMPLIANCE_1_3.compareTo(this.complianceLevel) < 0) { |
5140 |
this.runNegativeTest( |
5141 |
new String[] { |
5142 |
"X.java", |
5143 |
"public class X {\n" + |
5144 |
" void foo(Object o, boolean b) {\n" + |
5145 |
" assert(o != null || b);\n" + // shade doubts |
5146 |
" o.toString();\n" + // complain |
5147 |
" }\n" + |
5148 |
"}\n"}, |
5149 |
"----------\n" + |
5150 |
"1. ERROR in X.java (at line 4)\n" + |
5151 |
" o.toString();\n" + |
5152 |
" ^\n" + |
5153 |
"The variable o may be null\n" + |
5154 |
"----------\n"); |
5155 |
} |
5156 |
} |
5157 |
|
5158 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 |
5159 |
// [compiler] Null reference analysis doesn't understand assertions |
5160 |
public void test0953_assert_combined() { |
5161 |
if (COMPLIANCE_1_3.compareTo(this.complianceLevel) < 0) { |
5162 |
this.runNegativeTest( |
5163 |
new String[] { |
5164 |
"X.java", |
5165 |
"public class X {\n" + |
5166 |
" void foo(Object o1, Object o2) {\n" + |
5167 |
" assert(o1 != null && o2 == null);\n" + |
5168 |
" if (o1 == null) { };\n" + // complain |
5169 |
" if (o2 == null) { };\n" + // complain |
5170 |
" }\n" + |
5171 |
"}\n"}, |
5172 |
"----------\n" + |
5173 |
"1. ERROR in X.java (at line 4)\n" + |
5174 |
" if (o1 == null) { };\n" + |
5175 |
" ^^\n" + |
5176 |
"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" + |
5177 |
"----------\n" + |
5178 |
"2. ERROR in X.java (at line 5)\n" + |
5179 |
" if (o2 == null) { };\n" + |
5180 |
" ^^\n" + |
5181 |
"The variable o2 can only be null; it was either set to null or checked for null when last used\n" + |
5182 |
"----------\n"); |
5183 |
} |
5184 |
} |
5185 |
|
5186 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 |
5187 |
// [compiler] Null reference analysis doesn't understand assertions |
5188 |
public void test0954_assert_fake_reachable() { |
5189 |
if (COMPLIANCE_1_3.compareTo(this.complianceLevel) < 0) { |
5190 |
this.runNegativeTest( |
5191 |
new String[] { |
5192 |
"X.java", |
5193 |
"public class X {\n" + |
5194 |
" void foo(Object o) {\n" + |
5195 |
" assert(false && o != null);\n" + |
5196 |
" if (o == null) { };\n" + // quiet |
5197 |
" }\n" + |
5198 |
"}\n"}, |
5199 |
""); |
5200 |
} |
5201 |
} |
5202 |
|
5203 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 |
5204 |
// [compiler] Null reference analysis doesn't understand assertions |
5205 |
public void test0955_assert_combined() { |
5206 |
if (COMPLIANCE_1_3.compareTo(this.complianceLevel) < 0) { |
5207 |
this.runNegativeTest( |
5208 |
new String[] { |
5209 |
"X.java", |
5210 |
"public class X {\n" + |
5211 |
" void foo(Object o) {\n" + |
5212 |
" assert(false || o != null);\n" + |
5213 |
" if (o == null) { };\n" + // complain |
5214 |
" }\n" + |
5215 |
"}\n"}, |
5216 |
"----------\n" + |
5217 |
"1. ERROR in X.java (at line 4)\n" + |
5218 |
" if (o == null) { };\n" + |
5219 |
" ^\n" + |
5220 |
"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" + |
5221 |
"----------\n"); |
5222 |
} |
5223 |
} |
5224 |
|
5225 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 |
5226 |
// [compiler] Null reference analysis doesn't understand assertions |
5227 |
public void test0956_assert_combined() { |
5228 |
if (COMPLIANCE_1_3.compareTo(this.complianceLevel) < 0) { |
5229 |
this.runNegativeTest( |
5230 |
new String[] { |
5231 |
"X.java", |
5232 |
"public class X {\n" + |
5233 |
" void foo() {\n" + |
5234 |
" Object o = null;\n" + |
5235 |
" assert(o != null);\n" + // complain |
5236 |
" if (o == null) { };\n" + // complain |
5237 |
" }\n" + |
5238 |
"}\n"}, |
5239 |
"----------\n" + |
5240 |
"1. ERROR in X.java (at line 4)\n" + |
5241 |
" assert(o != null);\n" + |
5242 |
" ^\n" + |
5243 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
5244 |
"----------\n" + |
5245 |
"2. ERROR in X.java (at line 5)\n" + |
5246 |
" if (o == null) { };\n" + |
5247 |
" ^\n" + |
5248 |
"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" + |
5249 |
"----------\n"); |
5250 |
} |
5251 |
} |
5252 |
|
5096 |
// null analysis -- notNull protection tag |
5253 |
// null analysis -- notNull protection tag |
5097 |
public void _test0900_notNull_protection_tag() { |
5254 |
public void _test0900_notNull_protection_tag() { |
5098 |
this.runNegativeTest( |
5255 |
this.runNegativeTest( |