Lines 47-53
Link Here
|
47 |
// Only the highest compliance level is run; add the VM argument |
47 |
// Only the highest compliance level is run; add the VM argument |
48 |
// -Dcompliance=1.4 (for example) to lower it if needed |
48 |
// -Dcompliance=1.4 (for example) to lower it if needed |
49 |
static { |
49 |
static { |
50 |
// TESTS_NAMES = new String[] { "test358827" }; |
50 |
// TESTS_NAMES = new String[] { "testBug360328" }; |
51 |
// TESTS_NUMBERS = new int[] { 561 }; |
51 |
// TESTS_NUMBERS = new int[] { 561 }; |
52 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
52 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
53 |
} |
53 |
} |
Lines 15124-15127
Link Here
|
15124 |
true, |
15124 |
true, |
15125 |
compilerOptions); |
15125 |
compilerOptions); |
15126 |
} |
15126 |
} |
|
|
15127 |
// Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) |
15128 |
public void testBug360328() { |
15129 |
Map customOptions = getCompilerOptions(); |
15130 |
customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); |
15131 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); |
15132 |
runNegativeTest( |
15133 |
true, /* flushOutputDir */ |
15134 |
new String[] { |
15135 |
"X.java", |
15136 |
"public class X {\n" + |
15137 |
" void print4() {\n" + |
15138 |
" final String s1 = \"\";\n" + |
15139 |
" for (int i=0; i<4; i++)\n" + |
15140 |
" new Runnable() {\n" + |
15141 |
" public void run() {\n" + |
15142 |
" if (s1 != null)\n" + |
15143 |
" s1.toString();\n" + |
15144 |
" }\n" + |
15145 |
" }.run();\n" + |
15146 |
" }\n" + |
15147 |
" void print16(boolean b) {\n" + |
15148 |
" final String s3 = b ? null : \"\";\n" + |
15149 |
" for (int i=0; i<16; i++)\n" + |
15150 |
" new Runnable() {\n" + |
15151 |
" public void run() {\n" + |
15152 |
" s3.toString();\n" + |
15153 |
" }\n" + |
15154 |
" }.run();\n" + |
15155 |
" }\n" + |
15156 |
" void print23() {\n" + |
15157 |
" final String s23 = null;\n" + |
15158 |
" for (int i=0; i<23; i++)\n" + |
15159 |
" new Runnable() {\n" + |
15160 |
" public void run() {\n" + |
15161 |
" s23.toString();\n" + |
15162 |
" }\n" + |
15163 |
" }.run();\n" + |
15164 |
" }\n" + |
15165 |
"}\n", |
15166 |
|
15167 |
}, |
15168 |
null, /* classLibs */ |
15169 |
customOptions, |
15170 |
"----------\n" + |
15171 |
"1. ERROR in X.java (at line 7)\n" + |
15172 |
" if (s1 != null)\n" + |
15173 |
" ^^\n" + |
15174 |
"Redundant null check: The variable s1 cannot be null at this location\n" + |
15175 |
"----------\n" + |
15176 |
"2. ERROR in X.java (at line 17)\n" + |
15177 |
" s3.toString();\n" + |
15178 |
" ^^\n" + |
15179 |
"Potential null pointer access: The variable s3 may be null at this location\n" + |
15180 |
"----------\n" + |
15181 |
"3. ERROR in X.java (at line 26)\n" + |
15182 |
" s23.toString();\n" + |
15183 |
" ^^^\n" + |
15184 |
"Null pointer access: The variable s23 can only be null at this location\n" + |
15185 |
"----------\n", |
15186 |
"",/* expected output */ |
15187 |
"",/* expected error */ |
15188 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
15189 |
} |
15190 |
// Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) |
15191 |
// constructors |
15192 |
public void testBug360328b() { |
15193 |
Map customOptions = getCompilerOptions(); |
15194 |
customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); |
15195 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); |
15196 |
runNegativeTest( |
15197 |
true, /* flushOutputDir */ |
15198 |
new String[] { |
15199 |
"X.java", |
15200 |
"public class X {\n" + |
15201 |
" void print4() {\n" + |
15202 |
" final String s1 = \"\";\n" + |
15203 |
" for (int i=0; i<4; i++) {\n" + |
15204 |
" class R {\n" + |
15205 |
" public R() {\n" + |
15206 |
" if (s1 != null)\n" + |
15207 |
" s1.toString();\n" + |
15208 |
" }\n" + |
15209 |
" };\n" + |
15210 |
" new R();\n" + |
15211 |
" }\n" + |
15212 |
" }\n" + |
15213 |
" void print16(boolean b) {\n" + |
15214 |
" final String s3 = b ? null : \"\";\n" + |
15215 |
" int i=0; while (i++<16) {\n" + |
15216 |
" class R {\n" + |
15217 |
" public R() {\n" + |
15218 |
" s3.toString();\n" + |
15219 |
" }\n" + |
15220 |
" };\n" + |
15221 |
" new R();\n" + |
15222 |
" };\n" + |
15223 |
" }\n" + |
15224 |
" void print23() {\n" + |
15225 |
" final String s23 = null;\n" + |
15226 |
" for (int i=0; i<23; i++) {\n" + |
15227 |
" class R {\n" + |
15228 |
" public R() {\n" + |
15229 |
" s23.toString();\n" + |
15230 |
" }\n" + |
15231 |
" };\n" + |
15232 |
" new R();\n" + |
15233 |
" };\n" + |
15234 |
" }\n" + |
15235 |
"}\n", |
15236 |
|
15237 |
}, |
15238 |
null, /* classLibs */ |
15239 |
customOptions, |
15240 |
"----------\n" + |
15241 |
"1. ERROR in X.java (at line 7)\n" + |
15242 |
" if (s1 != null)\n" + |
15243 |
" ^^\n" + |
15244 |
"Redundant null check: The variable s1 cannot be null at this location\n" + |
15245 |
"----------\n" + |
15246 |
"2. ERROR in X.java (at line 19)\n" + |
15247 |
" s3.toString();\n" + |
15248 |
" ^^\n" + |
15249 |
"Potential null pointer access: The variable s3 may be null at this location\n" + |
15250 |
"----------\n" + |
15251 |
"3. ERROR in X.java (at line 30)\n" + |
15252 |
" s23.toString();\n" + |
15253 |
" ^^^\n" + |
15254 |
"Null pointer access: The variable s23 can only be null at this location\n" + |
15255 |
"----------\n", |
15256 |
"",/* expected output */ |
15257 |
"",/* expected error */ |
15258 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
15259 |
} |
15260 |
// Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) |
15261 |
// initializers |
15262 |
public void testBug360328c() { |
15263 |
Map customOptions = getCompilerOptions(); |
15264 |
customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); |
15265 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); |
15266 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
15267 |
runNegativeTest( |
15268 |
true, /* flushOutputDir */ |
15269 |
new String[] { |
15270 |
"X.java", |
15271 |
"public class X {\n" + |
15272 |
" void print4() {\n" + |
15273 |
" final String s1 = \"\";\n" + |
15274 |
" for (int i=0; i<4; i++) {\n" + |
15275 |
" class R {\n" + |
15276 |
" String s1R;\n" + |
15277 |
" {\n" + |
15278 |
" if (s1 != null)\n" + |
15279 |
" s1R = s1;\n" + |
15280 |
" }\n" + |
15281 |
" };\n" + |
15282 |
" new R();\n" + |
15283 |
" }\n" + |
15284 |
" }\n" + |
15285 |
" void print16(boolean b) {\n" + |
15286 |
" final String s3 = b ? null : \"\";\n" + |
15287 |
" for (int i=0; i<16; i++) {\n" + |
15288 |
" class R {\n" + |
15289 |
" String s3R = s3.toString();\n" + |
15290 |
" };\n" + |
15291 |
" new R();\n" + |
15292 |
" };\n" + |
15293 |
" }\n" + |
15294 |
" void print23() {\n" + |
15295 |
" final String s23 = null;\n" + |
15296 |
" for (int i=0; i<23; i++) {\n" + |
15297 |
" class R {\n" + |
15298 |
" String s23R;\n" + |
15299 |
" {\n" + |
15300 |
" s23R = s23.toString();\n" + |
15301 |
" }\n" + |
15302 |
" };\n" + |
15303 |
" new R();\n" + |
15304 |
" };\n" + |
15305 |
" }\n" + |
15306 |
"}\n", |
15307 |
|
15308 |
}, |
15309 |
null, /* classLibs */ |
15310 |
customOptions, |
15311 |
"----------\n" + |
15312 |
"1. ERROR in X.java (at line 8)\n" + |
15313 |
" if (s1 != null)\n" + |
15314 |
" ^^\n" + |
15315 |
"Redundant null check: The variable s1 cannot be null at this location\n" + |
15316 |
"----------\n" + |
15317 |
"2. ERROR in X.java (at line 19)\n" + |
15318 |
" String s3R = s3.toString();\n" + |
15319 |
" ^^\n" + |
15320 |
"Potential null pointer access: The variable s3 may be null at this location\n" + |
15321 |
"----------\n" + |
15322 |
"3. ERROR in X.java (at line 30)\n" + |
15323 |
" s23R = s23.toString();\n" + |
15324 |
" ^^^\n" + |
15325 |
"Null pointer access: The variable s23 can only be null at this location\n" + |
15326 |
"----------\n", |
15327 |
"",/* expected output */ |
15328 |
"",/* expected error */ |
15329 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
15330 |
} |
15331 |
// Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) |
15332 |
// try-finally instead of loop |
15333 |
public void testBug360328d() { |
15334 |
Map customOptions = getCompilerOptions(); |
15335 |
customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); |
15336 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); |
15337 |
runNegativeTest( |
15338 |
true, /* flushOutputDir */ |
15339 |
new String[] { |
15340 |
"X.java", |
15341 |
"public class X {\n" + |
15342 |
" void print4() {\n" + |
15343 |
" final String s1 = \"\";\n" + |
15344 |
" try { } finally {\n" + |
15345 |
" new Runnable() {\n" + |
15346 |
" public void run() {\n" + |
15347 |
" if (s1 != null)\n" + |
15348 |
" s1.toString();\n" + |
15349 |
" }\n" + |
15350 |
" }.run();\n" + |
15351 |
" }\n" + |
15352 |
" }\n" + |
15353 |
" void print16(boolean b) {\n" + |
15354 |
" final String s3 = b ? null : \"\";\n" + |
15355 |
" try { } finally {\n" + |
15356 |
" new Runnable() {\n" + |
15357 |
" public void run() {\n" + |
15358 |
" s3.toString();\n" + |
15359 |
" }\n" + |
15360 |
" }.run();\n" + |
15361 |
" }\n" + |
15362 |
" }\n" + |
15363 |
" void print23() {\n" + |
15364 |
" final String s23 = null;\n" + |
15365 |
" try { } finally {\n" + |
15366 |
" new Runnable() {\n" + |
15367 |
" public void run() {\n" + |
15368 |
" s23.toString();\n" + |
15369 |
" }\n" + |
15370 |
" }.run();\n" + |
15371 |
" }\n" + |
15372 |
" }\n" + |
15373 |
"}\n", |
15374 |
|
15375 |
}, |
15376 |
null, /* classLibs */ |
15377 |
customOptions, |
15378 |
"----------\n" + |
15379 |
"1. ERROR in X.java (at line 7)\n" + |
15380 |
" if (s1 != null)\n" + |
15381 |
" ^^\n" + |
15382 |
"Redundant null check: The variable s1 cannot be null at this location\n" + |
15383 |
"----------\n" + |
15384 |
"2. ERROR in X.java (at line 18)\n" + |
15385 |
" s3.toString();\n" + |
15386 |
" ^^\n" + |
15387 |
"Potential null pointer access: The variable s3 may be null at this location\n" + |
15388 |
"----------\n" + |
15389 |
"3. ERROR in X.java (at line 28)\n" + |
15390 |
" s23.toString();\n" + |
15391 |
" ^^^\n" + |
15392 |
"Null pointer access: The variable s23 can only be null at this location\n" + |
15393 |
"----------\n", |
15394 |
"",/* expected output */ |
15395 |
"",/* expected error */ |
15396 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
15397 |
} |
15127 |
} |
15398 |
} |