Lines 28-45
Link Here
|
28 |
public class ProgrammingProblemsTest extends AbstractRegressionTest { |
28 |
public class ProgrammingProblemsTest extends AbstractRegressionTest { |
29 |
|
29 |
|
30 |
public ProgrammingProblemsTest(String name) { |
30 |
public ProgrammingProblemsTest(String name) { |
31 |
super(name); |
31 |
super(name); |
32 |
} |
32 |
} |
33 |
|
33 |
|
34 |
// Static initializer to specify tests subset using TESTS_* static variables |
34 |
// Static initializer to specify tests subset using TESTS_* static variables |
35 |
// All specified tests which does not belong to the class are skipped... |
35 |
// All specified tests which does not belong to the class are skipped... |
36 |
// Only the highest compliance level is run; add the VM argument |
36 |
// Only the highest compliance level is run; add the VM argument |
37 |
// -Dcompliance=1.4 (for example) to lower it if needed |
37 |
// -Dcompliance=1.4 (for example) to lower it if needed |
38 |
static { |
38 |
static { |
39 |
// TESTS_NAMES = new String[] { "test0055" }; |
39 |
// TESTS_NAMES = new String[] { "test0055" }; |
40 |
// TESTS_NUMBERS = new int[] { 56 }; |
40 |
// TESTS_NUMBERS = new int[] { 73 }; |
41 |
// TESTS_RANGE = new int[] { 1, -1 }; |
41 |
// TESTS_RANGE = new int[] { 66, -1 }; |
42 |
} |
42 |
} |
43 |
|
43 |
|
44 |
public static Test suite() { |
44 |
public static Test suite() { |
45 |
return buildAllCompliancesTestSuite(testClass()); |
45 |
return buildAllCompliancesTestSuite(testClass()); |
Lines 2279-2282
Link Here
|
2279 |
customOptions, |
2279 |
customOptions, |
2280 |
null); |
2280 |
null); |
2281 |
} |
2281 |
} |
|
|
2282 |
// https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2283 |
// SingleNameReference, local, postIncr, emptyThen |
2284 |
public void test0058() throws Exception { |
2285 |
Map customOptions = getCompilerOptions(); |
2286 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); |
2287 |
this.runNegativeTest( |
2288 |
new String[] { |
2289 |
"X.java", |
2290 |
"public class X {\n" + |
2291 |
" public void method() {\n" + |
2292 |
" int a=10;\n" + |
2293 |
" if(a++ > 10) {\n" + // not counted as relevant use since bug 185682 |
2294 |
" }\n" + |
2295 |
" }\n" + |
2296 |
"}\n" |
2297 |
}, |
2298 |
"----------\n" + |
2299 |
"1. ERROR in X.java (at line 3)\n" + |
2300 |
" int a=10;\n" + |
2301 |
" ^\n" + |
2302 |
"The value of the local variable a is not used\n" + |
2303 |
"----------\n", |
2304 |
null/*classLibraries*/, |
2305 |
true/*shouldFlushOutputDirectory*/, |
2306 |
customOptions); |
2307 |
} |
2308 |
// https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2309 |
// SingleNameReference, field, postIncr, emptyThenWithElse |
2310 |
public void test0059() throws Exception { |
2311 |
Map customOptions = getCompilerOptions(); |
2312 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
2313 |
customOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); |
2314 |
this.runNegativeTest( |
2315 |
new String[] { |
2316 |
"X.java", |
2317 |
"public class X {\n" + |
2318 |
" private int a=10;\n" + |
2319 |
" public void method() {\n" + |
2320 |
" if(a++ > 10 && false) {\n" + // not counted as relevant use since bug 185682 |
2321 |
" } else {\n" + |
2322 |
" System.out.println(\"OK\");\n" + |
2323 |
" }\n" + |
2324 |
" }\n" + |
2325 |
"}\n" |
2326 |
}, |
2327 |
"----------\n" + |
2328 |
"1. ERROR in X.java (at line 2)\n" + |
2329 |
" private int a=10;\n" + |
2330 |
" ^\n" + |
2331 |
"The value of the field X.a is not used\n" + |
2332 |
"----------\n", |
2333 |
null/*classLibraries*/, |
2334 |
true/*shouldFlushOutputDirectory*/, |
2335 |
customOptions); |
2336 |
} |
2337 |
// https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2338 |
// FieldReference, field, postIncr, optimizableCondition |
2339 |
public void test0060() throws Exception { |
2340 |
Map customOptions = getCompilerOptions(); |
2341 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
2342 |
customOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); |
2343 |
this.runNegativeTest( |
2344 |
new String[] { |
2345 |
"X.java", |
2346 |
"public class X {\n" + |
2347 |
" private int a=10;\n" + |
2348 |
" public void method() {\n" + |
2349 |
" if(this.a++ > 10 || true) {\n" + // not counted as relevant use since bug 185682 |
2350 |
" System.out.println(\"OK\");\n" + |
2351 |
" }\n" + |
2352 |
" }\n" + |
2353 |
"}\n" |
2354 |
}, |
2355 |
"----------\n" + |
2356 |
"1. ERROR in X.java (at line 2)\n" + |
2357 |
" private int a=10;\n" + |
2358 |
" ^\n" + |
2359 |
"The value of the field X.a is not used\n" + |
2360 |
"----------\n", |
2361 |
null/*classLibraries*/, |
2362 |
true/*shouldFlushOutputDirectory*/, |
2363 |
customOptions); |
2364 |
} |
2365 |
|
2366 |
// https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2367 |
// SingleNameReference, local, simpleRead, emptyThen |
2368 |
public void test0061() throws Exception { |
2369 |
Map customOptions = getCompilerOptions(); |
2370 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); |
2371 |
this.runNegativeTest( |
2372 |
new String[] { |
2373 |
"X.java", |
2374 |
"public class X {\n" + |
2375 |
" public void method() {\n" + |
2376 |
" int a=10;\n" + |
2377 |
" if(a > 10) {\n" + |
2378 |
" }\n" + |
2379 |
" }\n" + |
2380 |
"}\n" |
2381 |
}, |
2382 |
"----------\n" + |
2383 |
"1. ERROR in X.java (at line 3)\n" + |
2384 |
" int a=10;\n" + |
2385 |
" ^\n" + |
2386 |
"The value of the local variable a is not used\n" + |
2387 |
"----------\n", |
2388 |
null/*classLibraries*/, |
2389 |
true/*shouldFlushOutputDirectory*/, |
2390 |
customOptions); |
2391 |
} |
2392 |
// https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2393 |
// SingleNameReference, field, simpleRead, emptyThenWithElse |
2394 |
public void test0062() throws Exception { |
2395 |
Map customOptions = getCompilerOptions(); |
2396 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
2397 |
customOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); |
2398 |
this.runNegativeTest( |
2399 |
new String[] { |
2400 |
"X.java", |
2401 |
"public class X {\n" + |
2402 |
" private int a=10;\n" + |
2403 |
" public void method() {\n" + |
2404 |
" if(a > 10 && false) {\n" + |
2405 |
" } else {\n" + |
2406 |
" System.out.println(\"OK\");\n" + |
2407 |
" }\n" + |
2408 |
" }\n" + |
2409 |
"}\n" |
2410 |
}, |
2411 |
"----------\n" + |
2412 |
"1. ERROR in X.java (at line 2)\n" + |
2413 |
" private int a=10;\n" + |
2414 |
" ^\n" + |
2415 |
"The value of the field X.a is not used\n" + |
2416 |
"----------\n", |
2417 |
null/*classLibraries*/, |
2418 |
true/*shouldFlushOutputDirectory*/, |
2419 |
customOptions); |
2420 |
} |
2421 |
// https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2422 |
// FieldReference+QualifiedNameReference, field, simpleRead, optimizableCondition |
2423 |
public void test0063() throws Exception { |
2424 |
Map customOptions = getCompilerOptions(); |
2425 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
2426 |
customOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); |
2427 |
this.runNegativeTest( |
2428 |
new String[] { |
2429 |
"X.java", |
2430 |
"public class X {\n" + |
2431 |
" private int a=10;\n" + |
2432 |
" public void method(X other) {\n" + |
2433 |
" if(this.a < 3 || true) {\n" + |
2434 |
" System.out.println(\"OK\");\n" + |
2435 |
" }\n" + |
2436 |
" if(other.a > 10 || true) {\n" + |
2437 |
" System.out.println(\"OK\");\n" + |
2438 |
" }\n" + |
2439 |
" }\n" + |
2440 |
"}\n" |
2441 |
}, |
2442 |
"----------\n" + |
2443 |
"1. ERROR in X.java (at line 2)\n" + |
2444 |
" private int a=10;\n" + |
2445 |
" ^\n" + |
2446 |
"The value of the field X.a is not used\n" + |
2447 |
"----------\n", |
2448 |
null/*classLibraries*/, |
2449 |
true/*shouldFlushOutputDirectory*/, |
2450 |
customOptions); |
2451 |
} |
2452 |
// https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2453 |
// FieldReference+QualifiedNameReference, field, postIncr, optimizableCondition, exprOfForWhileSwitch |
2454 |
public void test0064() throws Exception { |
2455 |
Map customOptions = getCompilerOptions(); |
2456 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
2457 |
customOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); |
2458 |
this.runNegativeTest( |
2459 |
new String[] { |
2460 |
"X.java", |
2461 |
"public class X {\n" + |
2462 |
" private int a=10;\n" + |
2463 |
" public void method(X other) {\n" + |
2464 |
" for(;other.a++ > 10 && false;) {\n" + |
2465 |
" }\n" + |
2466 |
" while (this.a++>10 && false) {\n" + |
2467 |
" }\n" + |
2468 |
" switch(a++) {\n" + |
2469 |
" }\n" + |
2470 |
" }\n" + |
2471 |
"}\n" |
2472 |
}, |
2473 |
"----------\n" + |
2474 |
"1. ERROR in X.java (at line 2)\n" + |
2475 |
" private int a=10;\n" + |
2476 |
" ^\n" + |
2477 |
"The value of the field X.a is not used\n" + |
2478 |
"----------\n", |
2479 |
null/*classLibraries*/, |
2480 |
true/*shouldFlushOutputDirectory*/, |
2481 |
customOptions); |
2482 |
} |
2483 |
// https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2484 |
// SingleNameReference, argument, simpleRead, optimizableCondition, exprOfForWhileSwitch |
2485 |
public void test0065() throws Exception { |
2486 |
Map customOptions = getCompilerOptions(); |
2487 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.ERROR); |
2488 |
customOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); |
2489 |
this.runNegativeTest( |
2490 |
new String[] { |
2491 |
"X.java", |
2492 |
"public class X {\n" + |
2493 |
" public void method(int a) {\n" + |
2494 |
" for(;a > 10 && false;) {\n" + |
2495 |
" }\n" + |
2496 |
" while (a>10 && false) {\n" + |
2497 |
" }\n" + |
2498 |
" switch(a) {\n" + |
2499 |
" }\n" + |
2500 |
" }\n" + |
2501 |
"}\n" |
2502 |
}, |
2503 |
"----------\n" + |
2504 |
"1. ERROR in X.java (at line 2)\n" + |
2505 |
" public void method(int a) {\n" + |
2506 |
" ^\n" + |
2507 |
"The value of the parameter a is not used\n" + |
2508 |
"----------\n", |
2509 |
null/*classLibraries*/, |
2510 |
true/*shouldFlushOutputDirectory*/, |
2511 |
customOptions); |
2512 |
} |
2513 |
// https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2514 |
// SimpleNameReference, localOfEnclosing, simpleRead, valueNeeded signaled by AbortMethod |
2515 |
public void test0066() throws Exception { |
2516 |
Map customOptions = getCompilerOptions(); |
2517 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); |
2518 |
this.runConformTest( |
2519 |
new String[] { |
2520 |
"X.java", |
2521 |
"public class X {\n" + |
2522 |
" int bar() { return 23; }\n" + |
2523 |
" void foo() {\n" + |
2524 |
" final int i=bar();\n" + |
2525 |
" new Runnable() {\n" + |
2526 |
" public void run() {\n" + |
2527 |
" if (i>3) { System.out.print(4); }\n" + // value is used |
2528 |
" }\n" + |
2529 |
" }.run();\n" + |
2530 |
" }\n" + |
2531 |
" public static void main(String[] args) {\n" + |
2532 |
" new X().foo();\n" + |
2533 |
" }\n" + |
2534 |
"}" |
2535 |
}, |
2536 |
"4", |
2537 |
null/*classLibraries*/, |
2538 |
true/*shouldFlushOutputDirectory*/, |
2539 |
null, |
2540 |
customOptions, |
2541 |
null); |
2542 |
String expectedOutput = |
2543 |
" // Method descriptor #6 ()V\n" + |
2544 |
" // Stack: 4, Locals: 2\n" + |
2545 |
" void foo();\n" + |
2546 |
" 0 aload_0 [this]\n" + |
2547 |
" 1 invokevirtual X.bar() : int [17]\n" + |
2548 |
" 4 istore_1 [i]\n" + |
2549 |
" 5 new X$1 [19]\n" + |
2550 |
" 8 dup\n" + |
2551 |
" 9 aload_0 [this]\n" + |
2552 |
" 10 iload_1 [i]\n" + |
2553 |
" 11 invokespecial X$1(X, int) [21]\n" + |
2554 |
" 14 invokevirtual X$1.run() : void [24]\n" + |
2555 |
" 17 return\n" + |
2556 |
" Line numbers:\n" + |
2557 |
" [pc: 0, line: 4]\n" + |
2558 |
" [pc: 5, line: 5]\n" + |
2559 |
" [pc: 14, line: 9]\n" + |
2560 |
" [pc: 17, line: 10]\n" + |
2561 |
" Local variable table:\n" + |
2562 |
" [pc: 0, pc: 18] local: this index: 0 type: X\n" + |
2563 |
" [pc: 5, pc: 18] local: i index: 1 type: int\n"; |
2564 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
2565 |
if (this.complianceLevel < ClassFileConstants.JDK1_4) { |
2566 |
expectedOutput = |
2567 |
" // Method descriptor #13 (LX;I)V\n" + |
2568 |
" // Stack: 2, Locals: 3\n" + |
2569 |
" X$1(X arg0, int arg1);\n" + |
2570 |
" 0 aload_0 [this]\n" + |
2571 |
" 1 invokespecial java.lang.Object() [15]\n" + |
2572 |
" 4 aload_0 [this]\n" + |
2573 |
" 5 aload_1 [arg0]\n" + |
2574 |
" 6 putfield X$1.this$0 : X [18]\n" + |
2575 |
" 9 aload_0 [this]\n" + |
2576 |
" 10 iload_2 [arg1]\n" + |
2577 |
" 11 putfield X$1.val$i : int [20]\n" + |
2578 |
" 14 return\n" + |
2579 |
" Line numbers:\n" + |
2580 |
" [pc: 0, line: 5]\n" + |
2581 |
" [pc: 4, line: 1]\n" + |
2582 |
" Local variable table:\n" + |
2583 |
" [pc: 0, pc: 15] local: this index: 0 type: new X(){}\n"; |
2584 |
} else if (this.complianceLevel < ClassFileConstants.JDK1_5) { |
2585 |
expectedOutput = |
2586 |
" // Method descriptor #13 (LX;I)V\n" + |
2587 |
" // Stack: 2, Locals: 3\n" + |
2588 |
" X$1(X arg0, int arg1);\n" + |
2589 |
" 0 aload_0 [this]\n" + |
2590 |
" 1 aload_1 [arg0]\n" + |
2591 |
" 2 putfield X$1.this$0 : X [15]\n" + |
2592 |
" 5 aload_0 [this]\n" + |
2593 |
" 6 iload_2 [arg1]\n" + |
2594 |
" 7 putfield X$1.val$i : int [17]\n" + |
2595 |
" 10 aload_0 [this]\n" + |
2596 |
" 11 invokespecial java.lang.Object() [19]\n" + |
2597 |
" 14 return\n" + |
2598 |
" Line numbers:\n" + |
2599 |
" [pc: 0, line: 1]\n" + |
2600 |
" [pc: 10, line: 5]\n" + |
2601 |
" Local variable table:\n" + |
2602 |
" [pc: 0, pc: 15] local: this index: 0 type: new X(){}\n"; |
2603 |
} else { |
2604 |
expectedOutput = |
2605 |
" // Method descriptor #12 (LX;I)V\n" + |
2606 |
" // Stack: 2, Locals: 3\n" + |
2607 |
" X$1(X arg0, int arg1);\n" + |
2608 |
" 0 aload_0 [this]\n" + |
2609 |
" 1 aload_1 [arg0]\n" + |
2610 |
" 2 putfield X$1.this$0 : X [14]\n" + |
2611 |
" 5 aload_0 [this]\n" + |
2612 |
" 6 iload_2 [arg1]\n" + |
2613 |
" 7 putfield X$1.val$i : int [16]\n" + |
2614 |
" 10 aload_0 [this]\n" + |
2615 |
" 11 invokespecial java.lang.Object() [18]\n" + |
2616 |
" 14 return\n" + |
2617 |
" Line numbers:\n" + |
2618 |
" [pc: 0, line: 1]\n" + |
2619 |
" [pc: 10, line: 5]\n" + |
2620 |
" Local variable table:\n" + |
2621 |
" [pc: 0, pc: 15] local: this index: 0 type: new X(){}\n"; |
2622 |
} |
2623 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X$1.class", "X$1", expectedOutput); |
2624 |
} |
2625 |
// https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2626 |
// SimpleNameReference, localOfEnclosing, simpleRead, emptyThen |
2627 |
public void test0067() throws Exception { |
2628 |
Map customOptions = getCompilerOptions(); |
2629 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
2630 |
this.runNegativeTest( |
2631 |
new String[] { |
2632 |
"X.java", |
2633 |
"class X {\n" + |
2634 |
" int bar() { return 23; }\n" + |
2635 |
" void foo() {\n" + |
2636 |
" final int i=bar();\n" + |
2637 |
" new Runnable() {\n" + |
2638 |
" public void run() {\n" + |
2639 |
" if (i>3) { }\n" + // value is optimized out |
2640 |
" }\n" + |
2641 |
" }.run();\n" + |
2642 |
" }\n" + |
2643 |
"}" |
2644 |
}, |
2645 |
"----------\n" + |
2646 |
"1. WARNING in X.java (at line 4)\n" + |
2647 |
" final int i=bar();\n" + |
2648 |
" ^\n" + |
2649 |
"The value of the local variable i is not used\n" + |
2650 |
"----------\n", |
2651 |
null/*classLibraries*/, |
2652 |
true/*shouldFlushOutputDirectory*/, |
2653 |
customOptions); |
2654 |
String expectedOutput = |
2655 |
" // Method descriptor #6 ()V\n" + |
2656 |
" // Stack: 3, Locals: 1\n" + |
2657 |
" void foo();\n" + |
2658 |
" 0 aload_0 [this]\n" + |
2659 |
" 1 invokevirtual X.bar() : int [17]\n" + |
2660 |
" 4 pop\n" + |
2661 |
" 5 new X$1 [19]\n" + |
2662 |
" 8 dup\n" + |
2663 |
" 9 aload_0 [this]\n" + |
2664 |
" 10 invokespecial X$1(X) [21]\n" + |
2665 |
" 13 invokevirtual X$1.run() : void [24]\n" + |
2666 |
" 16 return\n" + |
2667 |
" Line numbers:\n" + |
2668 |
" [pc: 0, line: 4]\n" + |
2669 |
" [pc: 5, line: 5]\n" + |
2670 |
" [pc: 13, line: 9]\n" + |
2671 |
" [pc: 16, line: 10]\n" + |
2672 |
" Local variable table:\n" + |
2673 |
" [pc: 0, pc: 17] local: this index: 0 type: X\n"; |
2674 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
2675 |
} |
2676 |
// https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2677 |
// SingleNameReference, local, assignmentAsExpression, emptyThen |
2678 |
public void test0068() throws Exception { |
2679 |
Map customOptions = getCompilerOptions(); |
2680 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
2681 |
this.runNegativeTest( |
2682 |
new String[] { |
2683 |
"X.java", |
2684 |
"public class X {\n" + |
2685 |
" public void method() {\n" + |
2686 |
" int a=10;\n" + |
2687 |
" int b;\n" + |
2688 |
" if((b=a) > 10) {\n" + |
2689 |
" }\n" + |
2690 |
" }\n" + |
2691 |
"}\n" |
2692 |
}, |
2693 |
"----------\n" + |
2694 |
"1. WARNING in X.java (at line 4)\n" + |
2695 |
" int b;\n" + |
2696 |
" ^\n" + |
2697 |
"The value of the local variable b is not used\n" + |
2698 |
"----------\n" + |
2699 |
"2. WARNING in X.java (at line 4)\n" + // FIXME(SH): duplicate report due to restart (AbortMethod) |
2700 |
" int b;\n" + |
2701 |
" ^\n" + |
2702 |
"The value of the local variable b is not used\n" + |
2703 |
"----------\n", |
2704 |
null/*classLibraries*/, |
2705 |
true/*shouldFlushOutputDirectory*/, |
2706 |
customOptions); |
2707 |
String expectedOutput = |
2708 |
" // Method descriptor #6 ()V\n" + |
2709 |
" // Stack: 1, Locals: 2\n" + |
2710 |
" public void method();\n" + |
2711 |
" 0 bipush 10\n" + |
2712 |
" 2 istore_1 [a]\n" + |
2713 |
" 3 iload_1 [a]\n" + |
2714 |
" 4 pop\n" + |
2715 |
" 5 return\n" + |
2716 |
" Line numbers:\n" + |
2717 |
" [pc: 0, line: 3]\n" + |
2718 |
" [pc: 3, line: 5]\n" + |
2719 |
" [pc: 5, line: 7]\n" + |
2720 |
" Local variable table:\n" + |
2721 |
" [pc: 0, pc: 6] local: this index: 0 type: X\n" + |
2722 |
" [pc: 3, pc: 6] local: a index: 1 type: int\n"; // b has been optimized out |
2723 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
2724 |
} |
2725 |
//https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2726 |
//SimpleNameReference, localOfEnclosing, simpleRead, valueNeeded signaled by AbortMethod |
2727 |
public void test0069() throws Exception { |
2728 |
Map customOptions = getCompilerOptions(); |
2729 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); |
2730 |
this.runConformTest( |
2731 |
new String[] { |
2732 |
"X.java", |
2733 |
"public class X {\n" + |
2734 |
" int bar() { return 23; }\n" + |
2735 |
" void foo() {\n" + |
2736 |
" final int i=bar();\n" + |
2737 |
" new Runnable() {\n" + |
2738 |
" public void run() {\n" + |
2739 |
" if (i>3) {}\n" + // value is not used |
2740 |
" System.out.print(4);\n" + |
2741 |
" }\n" + |
2742 |
" }.run();\n" + |
2743 |
" }\n" + |
2744 |
" public static void main(String[] args) {\n" + |
2745 |
" new X().foo();\n" + |
2746 |
" }\n" + |
2747 |
"}" |
2748 |
}, |
2749 |
"4", |
2750 |
null/*classLibraries*/, |
2751 |
true/*shouldFlushOutputDirectory*/, |
2752 |
null, |
2753 |
customOptions, |
2754 |
null); |
2755 |
String expectedOutput = |
2756 |
" // Method descriptor #6 ()V\n" + |
2757 |
" // Stack: 3, Locals: 1\n" + |
2758 |
" void foo();\n" + |
2759 |
" 0 aload_0 [this]\n" + |
2760 |
" 1 invokevirtual X.bar() : int [17]\n" + |
2761 |
" 4 pop\n" + |
2762 |
" 5 new X$1 [19]\n" + |
2763 |
" 8 dup\n" + |
2764 |
" 9 aload_0 [this]\n" + |
2765 |
" 10 invokespecial X$1(X) [21]\n" + |
2766 |
" 13 invokevirtual X$1.run() : void [24]\n" + |
2767 |
" 16 return\n" + |
2768 |
" Line numbers:\n" + |
2769 |
" [pc: 0, line: 4]\n" + |
2770 |
" [pc: 5, line: 5]\n" + |
2771 |
" [pc: 13, line: 10]\n" + |
2772 |
" [pc: 16, line: 11]\n" + |
2773 |
" Local variable table:\n" + |
2774 |
" [pc: 0, pc: 17] local: this index: 0 type: X\n"; |
2775 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
2776 |
if (this.complianceLevel < ClassFileConstants.JDK1_4) { |
2777 |
expectedOutput = |
2778 |
" // Method descriptor #13 (LX;)V\n" + |
2779 |
" // Stack: 2, Locals: 2\n" + |
2780 |
" X$1(X arg0);\n" + |
2781 |
" 0 aload_0 [this]\n" + |
2782 |
" 1 invokespecial java.lang.Object() [15]\n" + |
2783 |
" 4 aload_0 [this]\n" + |
2784 |
" 5 aload_1 [arg0]\n" + |
2785 |
" 6 putfield X$1.this$0 : X [18]\n" + |
2786 |
" 9 return\n" + |
2787 |
" Line numbers:\n" + |
2788 |
" [pc: 0, line: 5]\n" + |
2789 |
" [pc: 4, line: 1]\n" + |
2790 |
" Local variable table:\n" + |
2791 |
" [pc: 0, pc: 10] local: this index: 0 type: new X(){}\n"; |
2792 |
} else if (this.complianceLevel < ClassFileConstants.JDK1_5) { |
2793 |
expectedOutput = |
2794 |
" // Method descriptor #13 (LX;)V\n" + |
2795 |
" // Stack: 2, Locals: 2\n" + |
2796 |
" X$1(X arg0);\n" + |
2797 |
" 0 aload_0 [this]\n" + |
2798 |
" 1 aload_1 [arg0]\n" + |
2799 |
" 2 putfield X$1.this$0 : X [15]\n" + |
2800 |
" 5 aload_0 [this]\n" + |
2801 |
" 6 invokespecial java.lang.Object() [17]\n" + |
2802 |
" 9 return\n" + |
2803 |
" Line numbers:\n" + |
2804 |
" [pc: 0, line: 1]\n" + |
2805 |
" [pc: 5, line: 5]\n" + |
2806 |
" Local variable table:\n" + |
2807 |
" [pc: 0, pc: 10] local: this index: 0 type: new X(){}\n"; |
2808 |
} else { |
2809 |
expectedOutput = |
2810 |
" // Method descriptor #12 (LX;)V\n" + |
2811 |
" // Stack: 2, Locals: 2\n" + |
2812 |
" X$1(X arg0);\n" + |
2813 |
" 0 aload_0 [this]\n" + |
2814 |
" 1 aload_1 [arg0]\n" + |
2815 |
" 2 putfield X$1.this$0 : X [14]\n" + |
2816 |
" 5 aload_0 [this]\n" + |
2817 |
" 6 invokespecial java.lang.Object() [16]\n" + |
2818 |
" 9 return\n" + |
2819 |
" Line numbers:\n" + |
2820 |
" [pc: 0, line: 1]\n" + |
2821 |
" [pc: 5, line: 5]\n" + |
2822 |
" Local variable table:\n" + |
2823 |
" [pc: 0, pc: 10] local: this index: 0 type: new X(){}\n"; |
2824 |
} |
2825 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X$1.class", "X$1", expectedOutput); |
2826 |
} |
2827 |
//https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2828 |
//SimpleNameReference, localOfEnclosing, simpleRead, valueNeeded signaled by AbortMethod |
2829 |
public void test0070() throws Exception { |
2830 |
Map customOptions = getCompilerOptions(); |
2831 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); |
2832 |
this.runConformTest( |
2833 |
new String[] { |
2834 |
"X.java", |
2835 |
"public class X {\n" + |
2836 |
" int bar() { return 23; }\n" + |
2837 |
" public X() {\n" + |
2838 |
" final int i=bar();\n" + |
2839 |
" new Runnable() {\n" + |
2840 |
" public void run() {\n" + |
2841 |
" if (i>3) {}\n" + // value is not used |
2842 |
" System.out.print(4);\n" + |
2843 |
" }\n" + |
2844 |
" }.run();\n" + |
2845 |
" }\n" + |
2846 |
" public static void main(String[] args) {\n" + |
2847 |
" new X();\n" + |
2848 |
" }\n" + |
2849 |
"}" |
2850 |
}, |
2851 |
"4", |
2852 |
null/*classLibraries*/, |
2853 |
true/*shouldFlushOutputDirectory*/, |
2854 |
null, |
2855 |
customOptions, |
2856 |
null); |
2857 |
String expectedOutput = |
2858 |
" // Method descriptor #13 ()V\n" + |
2859 |
" // Stack: 3, Locals: 1\n" + |
2860 |
" public X();\n" + |
2861 |
" 0 aload_0 [this]\n" + |
2862 |
" 1 invokespecial java.lang.Object() [14]\n" + |
2863 |
" 4 aload_0 [this]\n" + |
2864 |
" 5 invokevirtual X.bar() : int [16]\n" + |
2865 |
" 8 pop\n" + |
2866 |
" 9 new X$1 [18]\n" + |
2867 |
" 12 dup\n" + |
2868 |
" 13 aload_0 [this]\n" + |
2869 |
" 14 invokespecial X$1(X) [20]\n" + |
2870 |
" 17 invokevirtual X$1.run() : void [23]\n" + |
2871 |
" 20 return\n" + |
2872 |
" Line numbers:\n" + |
2873 |
" [pc: 0, line: 3]\n" + |
2874 |
" [pc: 4, line: 4]\n" + |
2875 |
" [pc: 9, line: 5]\n" + |
2876 |
" [pc: 17, line: 10]\n" + |
2877 |
" [pc: 20, line: 11]\n" + |
2878 |
" Local variable table:\n" + |
2879 |
" [pc: 0, pc: 21] local: this index: 0 type: X\n"; |
2880 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
2881 |
if (this.complianceLevel < ClassFileConstants.JDK1_4) { |
2882 |
expectedOutput = |
2883 |
" // Method descriptor #13 (LX;)V\n" + |
2884 |
" // Stack: 2, Locals: 2\n" + |
2885 |
" X$1(X arg0);\n" + |
2886 |
" 0 aload_0 [this]\n" + |
2887 |
" 1 invokespecial java.lang.Object() [15]\n" + |
2888 |
" 4 aload_0 [this]\n" + |
2889 |
" 5 aload_1 [arg0]\n" + |
2890 |
" 6 putfield X$1.this$0 : X [18]\n" + |
2891 |
" 9 return\n" + |
2892 |
" Line numbers:\n" + |
2893 |
" [pc: 0, line: 5]\n" + |
2894 |
" [pc: 4, line: 1]\n" + |
2895 |
" Local variable table:\n" + |
2896 |
" [pc: 0, pc: 10] local: this index: 0 type: new X(){}\n"; |
2897 |
} else if (this.complianceLevel < ClassFileConstants.JDK1_5) { |
2898 |
expectedOutput = |
2899 |
" // Method descriptor #13 (LX;)V\n" + |
2900 |
" // Stack: 2, Locals: 2\n" + |
2901 |
" X$1(X arg0);\n" + |
2902 |
" 0 aload_0 [this]\n" + |
2903 |
" 1 aload_1 [arg0]\n" + |
2904 |
" 2 putfield X$1.this$0 : X [15]\n" + |
2905 |
" 5 aload_0 [this]\n" + |
2906 |
" 6 invokespecial java.lang.Object() [17]\n" + |
2907 |
" 9 return\n" + |
2908 |
" Line numbers:\n" + |
2909 |
" [pc: 0, line: 1]\n" + |
2910 |
" [pc: 5, line: 5]\n" + |
2911 |
" Local variable table:\n" + |
2912 |
" [pc: 0, pc: 10] local: this index: 0 type: new X(){}\n"; |
2913 |
} else { |
2914 |
expectedOutput = |
2915 |
" // Method descriptor #12 (LX;)V\n" + |
2916 |
" // Stack: 2, Locals: 2\n" + |
2917 |
" X$1(X arg0);\n" + |
2918 |
" 0 aload_0 [this]\n" + |
2919 |
" 1 aload_1 [arg0]\n" + |
2920 |
" 2 putfield X$1.this$0 : X [14]\n" + |
2921 |
" 5 aload_0 [this]\n" + |
2922 |
" 6 invokespecial java.lang.Object() [16]\n" + |
2923 |
" 9 return\n" + |
2924 |
" Line numbers:\n" + |
2925 |
" [pc: 0, line: 1]\n" + |
2926 |
" [pc: 5, line: 5]\n" + |
2927 |
" Local variable table:\n" + |
2928 |
" [pc: 0, pc: 10] local: this index: 0 type: new X(){}\n"; |
2929 |
} |
2930 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X$1.class", "X$1", expectedOutput); |
2931 |
} |
2932 |
//https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
2933 |
//SimpleNameReference, localOfEnclosing, simpleRead, valueNeeded signaled by AbortMethod |
2934 |
public void test0071() throws Exception { |
2935 |
Map customOptions = getCompilerOptions(); |
2936 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); |
2937 |
this.runConformTest( |
2938 |
new String[] { |
2939 |
"X.java", |
2940 |
"public class X {\n" + |
2941 |
" int bar() { return 23; }\n" + |
2942 |
" X() {\n" + |
2943 |
" final int i=bar();\n" + |
2944 |
" new Runnable() {\n" + |
2945 |
" public void run() {\n" + |
2946 |
" if (i>3) { System.out.print(4); }\n" + // value is used |
2947 |
" }\n" + |
2948 |
" }.run();\n" + |
2949 |
" }\n" + |
2950 |
" public static void main(String[] args) {\n" + |
2951 |
" new X();\n" + |
2952 |
" }\n" + |
2953 |
"}" |
2954 |
}, |
2955 |
"4", |
2956 |
null/*classLibraries*/, |
2957 |
true/*shouldFlushOutputDirectory*/, |
2958 |
null, |
2959 |
customOptions, |
2960 |
null); |
2961 |
String expectedOutput = |
2962 |
" // Method descriptor #13 ()V\n" + |
2963 |
" // Stack: 4, Locals: 2\n" + |
2964 |
" X();\n" + |
2965 |
" 0 aload_0 [this]\n" + |
2966 |
" 1 invokespecial java.lang.Object() [14]\n" + |
2967 |
" 4 aload_0 [this]\n" + |
2968 |
" 5 invokevirtual X.bar() : int [16]\n" + |
2969 |
" 8 istore_1 [i]\n" + |
2970 |
" 9 new X$1 [18]\n" + |
2971 |
" 12 dup\n" + |
2972 |
" 13 aload_0 [this]\n" + |
2973 |
" 14 iload_1 [i]\n" + |
2974 |
" 15 invokespecial X$1(X, int) [20]\n" + |
2975 |
" 18 invokevirtual X$1.run() : void [23]\n" + |
2976 |
" 21 return\n" + |
2977 |
" Line numbers:\n" + |
2978 |
" [pc: 0, line: 3]\n" + |
2979 |
" [pc: 4, line: 4]\n" + |
2980 |
" [pc: 9, line: 5]\n" + |
2981 |
" [pc: 18, line: 9]\n" + |
2982 |
" [pc: 21, line: 10]\n" + |
2983 |
" Local variable table:\n" + |
2984 |
" [pc: 0, pc: 22] local: this index: 0 type: X\n" + |
2985 |
" [pc: 9, pc: 22] local: i index: 1 type: int\n"; |
2986 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
2987 |
if (this.complianceLevel < ClassFileConstants.JDK1_4) { |
2988 |
expectedOutput = |
2989 |
" // Method descriptor #13 (LX;I)V\n" + |
2990 |
" // Stack: 2, Locals: 3\n" + |
2991 |
" X$1(X arg0, int arg1);\n" + |
2992 |
" 0 aload_0 [this]\n" + |
2993 |
" 1 invokespecial java.lang.Object() [15]\n" + |
2994 |
" 4 aload_0 [this]\n" + |
2995 |
" 5 aload_1 [arg0]\n" + |
2996 |
" 6 putfield X$1.this$0 : X [18]\n" + |
2997 |
" 9 aload_0 [this]\n" + |
2998 |
" 10 iload_2 [arg1]\n" + |
2999 |
" 11 putfield X$1.val$i : int [20]\n" + |
3000 |
" 14 return\n" + |
3001 |
" Line numbers:\n" + |
3002 |
" [pc: 0, line: 5]\n" + |
3003 |
" [pc: 4, line: 1]\n" + |
3004 |
" Local variable table:\n" + |
3005 |
" [pc: 0, pc: 15] local: this index: 0 type: new X(){}\n"; |
3006 |
} else if (this.complianceLevel < ClassFileConstants.JDK1_5) { |
3007 |
expectedOutput = |
3008 |
" // Method descriptor #13 (LX;I)V\n" + |
3009 |
" // Stack: 2, Locals: 3\n" + |
3010 |
" X$1(X arg0, int arg1);\n" + |
3011 |
" 0 aload_0 [this]\n" + |
3012 |
" 1 aload_1 [arg0]\n" + |
3013 |
" 2 putfield X$1.this$0 : X [15]\n" + |
3014 |
" 5 aload_0 [this]\n" + |
3015 |
" 6 iload_2 [arg1]\n" + |
3016 |
" 7 putfield X$1.val$i : int [17]\n" + |
3017 |
" 10 aload_0 [this]\n" + |
3018 |
" 11 invokespecial java.lang.Object() [19]\n" + |
3019 |
" 14 return\n" + |
3020 |
" Line numbers:\n" + |
3021 |
" [pc: 0, line: 1]\n" + |
3022 |
" [pc: 10, line: 5]\n" + |
3023 |
" Local variable table:\n" + |
3024 |
" [pc: 0, pc: 15] local: this index: 0 type: new X(){}\n"; |
3025 |
} else { |
3026 |
expectedOutput = |
3027 |
" // Method descriptor #12 (LX;I)V\n" + |
3028 |
" // Stack: 2, Locals: 3\n" + |
3029 |
" X$1(X arg0, int arg1);\n" + |
3030 |
" 0 aload_0 [this]\n" + |
3031 |
" 1 aload_1 [arg0]\n" + |
3032 |
" 2 putfield X$1.this$0 : X [14]\n" + |
3033 |
" 5 aload_0 [this]\n" + |
3034 |
" 6 iload_2 [arg1]\n" + |
3035 |
" 7 putfield X$1.val$i : int [16]\n" + |
3036 |
" 10 aload_0 [this]\n" + |
3037 |
" 11 invokespecial java.lang.Object() [18]\n" + |
3038 |
" 14 return\n" + |
3039 |
" Line numbers:\n" + |
3040 |
" [pc: 0, line: 1]\n" + |
3041 |
" [pc: 10, line: 5]\n" + |
3042 |
" Local variable table:\n" + |
3043 |
" [pc: 0, pc: 15] local: this index: 0 type: new X(){}\n"; |
3044 |
} |
3045 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X$1.class", "X$1", expectedOutput); |
3046 |
} |
3047 |
//https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
3048 |
//SimpleNameReference, localOfEnclosing, simpleRead, valueNeeded signaled by AbortMethod |
3049 |
public void test0072() throws Exception { |
3050 |
Map customOptions = getCompilerOptions(); |
3051 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); |
3052 |
this.runConformTest( |
3053 |
new String[] { |
3054 |
"X.java", |
3055 |
"public class X {\n" + |
3056 |
" int bar() { return 23; }\n" + |
3057 |
" X() {\n" + |
3058 |
" final int i=bar();\n" + |
3059 |
" new Runnable() {\n" + |
3060 |
" {\n" + |
3061 |
" if (i>3) { System.out.print(4); }\n" + // value is used |
3062 |
" }\n" + |
3063 |
" public void run() {\n" + |
3064 |
" }\n" + |
3065 |
" }.run();\n" + |
3066 |
" }\n" + |
3067 |
" public static void main(String[] args) {\n" + |
3068 |
" new X();\n" + |
3069 |
" }\n" + |
3070 |
"}" |
3071 |
}, |
3072 |
"4", |
3073 |
null/*classLibraries*/, |
3074 |
true/*shouldFlushOutputDirectory*/, |
3075 |
null, |
3076 |
customOptions, |
3077 |
null); |
3078 |
String expectedOutput = |
3079 |
" // Method descriptor #13 ()V\n" + |
3080 |
" // Stack: 4, Locals: 2\n" + |
3081 |
" X();\n" + |
3082 |
" 0 aload_0 [this]\n" + |
3083 |
" 1 invokespecial java.lang.Object() [14]\n" + |
3084 |
" 4 aload_0 [this]\n" + |
3085 |
" 5 invokevirtual X.bar() : int [16]\n" + |
3086 |
" 8 istore_1 [i]\n" + |
3087 |
" 9 new X$1 [18]\n" + |
3088 |
" 12 dup\n" + |
3089 |
" 13 aload_0 [this]\n" + |
3090 |
" 14 iload_1 [i]\n" + |
3091 |
" 15 invokespecial X$1(X, int) [20]\n" + |
3092 |
" 18 invokevirtual X$1.run() : void [23]\n" + |
3093 |
" 21 return\n" + |
3094 |
" Line numbers:\n" + |
3095 |
" [pc: 0, line: 3]\n" + |
3096 |
" [pc: 4, line: 4]\n" + |
3097 |
" [pc: 9, line: 5]\n" + |
3098 |
" [pc: 18, line: 11]\n" + |
3099 |
" [pc: 21, line: 12]\n" + |
3100 |
" Local variable table:\n" + |
3101 |
" [pc: 0, pc: 22] local: this index: 0 type: X\n" + |
3102 |
" [pc: 9, pc: 22] local: i index: 1 type: int\n"; |
3103 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
3104 |
if (this.complianceLevel < ClassFileConstants.JDK1_4) { |
3105 |
expectedOutput = |
3106 |
" // Method descriptor #11 (LX;I)V\n" + |
3107 |
" // Stack: 2, Locals: 3\n" + |
3108 |
" X$1(X arg0, int arg1);\n" + |
3109 |
" 0 aload_0 [this]\n" + |
3110 |
" 1 invokespecial java.lang.Object() [13]\n" + |
3111 |
" 4 aload_0 [this]\n" + |
3112 |
" 5 aload_1 [arg0]\n" + |
3113 |
" 6 putfield X$1.this$0 : X [16]\n" + |
3114 |
" 9 iload_2 [arg1]\n" + |
3115 |
" 10 iconst_3\n" + |
3116 |
" 11 if_icmple 21\n" + |
3117 |
" 14 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + |
3118 |
" 17 iconst_4\n" + |
3119 |
" 18 invokevirtual java.io.PrintStream.print(int) : void [24]\n" + |
3120 |
" 21 return\n" + |
3121 |
" Line numbers:\n" + |
3122 |
" [pc: 0, line: 5]\n" + |
3123 |
" [pc: 9, line: 7]\n" + |
3124 |
" [pc: 21, line: 1]\n" + |
3125 |
" Local variable table:\n" + |
3126 |
" [pc: 0, pc: 22] local: this index: 0 type: new X(){}\n"; |
3127 |
} else if (this.complianceLevel < ClassFileConstants.JDK1_5) { |
3128 |
expectedOutput = |
3129 |
" // Method descriptor #11 (LX;I)V\n" + |
3130 |
" // Stack: 2, Locals: 3\n" + |
3131 |
" X$1(X arg0, int arg1);\n" + |
3132 |
" 0 aload_0 [this]\n" + |
3133 |
" 1 aload_1 [arg0]\n" + |
3134 |
" 2 putfield X$1.this$0 : X [13]\n" + |
3135 |
" 5 aload_0 [this]\n" + |
3136 |
" 6 invokespecial java.lang.Object() [15]\n" + |
3137 |
" 9 iload_2 [arg1]\n" + |
3138 |
" 10 iconst_3\n" + |
3139 |
" 11 if_icmple 21\n" + |
3140 |
" 14 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + |
3141 |
" 17 iconst_4\n" + |
3142 |
" 18 invokevirtual java.io.PrintStream.print(int) : void [24]\n" + |
3143 |
" 21 return\n" + |
3144 |
" Line numbers:\n" + |
3145 |
" [pc: 0, line: 1]\n" + |
3146 |
" [pc: 5, line: 5]\n" + |
3147 |
" [pc: 9, line: 7]\n" + |
3148 |
" Local variable table:\n" + |
3149 |
" [pc: 0, pc: 22] local: this index: 0 type: new X(){}\n"; |
3150 |
} else { |
3151 |
expectedOutput = |
3152 |
" // Method descriptor #10 (LX;I)V\n" + |
3153 |
" // Stack: 2, Locals: 3\n" + |
3154 |
" X$1(X arg0, int arg1);\n" + |
3155 |
" 0 aload_0 [this]\n" + |
3156 |
" 1 aload_1 [arg0]\n" + |
3157 |
" 2 putfield X$1.this$0 : X [12]\n" + |
3158 |
" 5 aload_0 [this]\n" + |
3159 |
" 6 invokespecial java.lang.Object() [14]\n" + |
3160 |
" 9 iload_2 [arg1]\n" + |
3161 |
" 10 iconst_3\n" + |
3162 |
" 11 if_icmple 21\n" + |
3163 |
" 14 getstatic java.lang.System.out : java.io.PrintStream [17]\n" + |
3164 |
" 17 iconst_4\n" + |
3165 |
" 18 invokevirtual java.io.PrintStream.print(int) : void [23]\n" + |
3166 |
" 21 return\n" + |
3167 |
" Line numbers:\n" + |
3168 |
" [pc: 0, line: 1]\n" + |
3169 |
" [pc: 5, line: 5]\n" + |
3170 |
" [pc: 9, line: 7]\n" + |
3171 |
" Local variable table:\n" + |
3172 |
" [pc: 0, pc: 22] local: this index: 0 type: new X(){}\n"; |
3173 |
} |
3174 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X$1.class", "X$1", expectedOutput); |
3175 |
} |
3176 |
//https://bugs.eclipse.org/328830 - Variable should be marked unused when it can be optimized out |
3177 |
//SimpleNameReference, localOfEnclosing, simpleRead, valueNeeded signaled by AbortMethod |
3178 |
public void test0073() throws Exception { |
3179 |
Map customOptions = getCompilerOptions(); |
3180 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); |
3181 |
this.runConformTest( |
3182 |
new String[] { |
3183 |
"X.java", |
3184 |
"public class X {\n" + |
3185 |
" int bar() { return 23; }\n" + |
3186 |
" X() {\n" + |
3187 |
" final int i=bar();\n" + |
3188 |
" new Runnable() {\n" + |
3189 |
" {\n" + |
3190 |
" if (i>3) {}\n" + // value is not used |
3191 |
" System.out.print(4);\n" + |
3192 |
" }\n" + |
3193 |
" public void run() {\n" + |
3194 |
" }\n" + |
3195 |
" }.run();\n" + |
3196 |
" }\n" + |
3197 |
" public static void main(String[] args) {\n" + |
3198 |
" new X();\n" + |
3199 |
" }\n" + |
3200 |
"}" |
3201 |
}, |
3202 |
"4", |
3203 |
null/*classLibraries*/, |
3204 |
true/*shouldFlushOutputDirectory*/, |
3205 |
null, |
3206 |
customOptions, |
3207 |
null); |
3208 |
String expectedOutput = |
3209 |
" // Method descriptor #13 ()V\n" + |
3210 |
" // Stack: 3, Locals: 1\n" + |
3211 |
" X();\n" + |
3212 |
" 0 aload_0 [this]\n" + |
3213 |
" 1 invokespecial java.lang.Object() [14]\n" + |
3214 |
" 4 aload_0 [this]\n" + |
3215 |
" 5 invokevirtual X.bar() : int [16]\n" + |
3216 |
" 8 pop\n" + |
3217 |
" 9 new X$1 [18]\n" + |
3218 |
" 12 dup\n" + |
3219 |
" 13 aload_0 [this]\n" + |
3220 |
" 14 invokespecial X$1(X) [20]\n" + |
3221 |
" 17 invokevirtual X$1.run() : void [23]\n" + |
3222 |
" 20 return\n" + |
3223 |
" Line numbers:\n" + |
3224 |
" [pc: 0, line: 3]\n" + |
3225 |
" [pc: 4, line: 4]\n" + |
3226 |
" [pc: 9, line: 5]\n" + |
3227 |
" [pc: 17, line: 12]\n" + |
3228 |
" [pc: 20, line: 13]\n" + |
3229 |
" Local variable table:\n" + |
3230 |
" [pc: 0, pc: 21] local: this index: 0 type: X\n"; |
3231 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
3232 |
if (this.complianceLevel < ClassFileConstants.JDK1_4) { |
3233 |
expectedOutput = |
3234 |
" // Method descriptor #11 (LX;)V\n" + |
3235 |
" // Stack: 2, Locals: 2\n" + |
3236 |
" X$1(X arg0);\n" + |
3237 |
" 0 aload_0 [this]\n" + |
3238 |
" 1 invokespecial java.lang.Object() [13]\n" + |
3239 |
" 4 aload_0 [this]\n" + |
3240 |
" 5 aload_1 [arg0]\n" + |
3241 |
" 6 putfield X$1.this$0 : X [16]\n" + |
3242 |
" 9 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + |
3243 |
" 12 iconst_4\n" + |
3244 |
" 13 invokevirtual java.io.PrintStream.print(int) : void [24]\n" + |
3245 |
" 16 return\n" + |
3246 |
" Line numbers:\n" + |
3247 |
" [pc: 0, line: 5]\n" + |
3248 |
" [pc: 9, line: 8]\n" + |
3249 |
" [pc: 16, line: 1]\n" + |
3250 |
" Local variable table:\n" + |
3251 |
" [pc: 0, pc: 17] local: this index: 0 type: new X(){}\n"; |
3252 |
} else if (this.complianceLevel < ClassFileConstants.JDK1_5) { |
3253 |
expectedOutput = |
3254 |
" // Method descriptor #11 (LX;)V\n" + |
3255 |
" // Stack: 2, Locals: 2\n" + |
3256 |
" X$1(X arg0);\n" + |
3257 |
" 0 aload_0 [this]\n" + |
3258 |
" 1 aload_1 [arg0]\n" + |
3259 |
" 2 putfield X$1.this$0 : X [13]\n" + |
3260 |
" 5 aload_0 [this]\n" + |
3261 |
" 6 invokespecial java.lang.Object() [15]\n" + |
3262 |
" 9 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + |
3263 |
" 12 iconst_4\n" + |
3264 |
" 13 invokevirtual java.io.PrintStream.print(int) : void [24]\n" + |
3265 |
" 16 return\n" + |
3266 |
" Line numbers:\n" + |
3267 |
" [pc: 0, line: 1]\n" + |
3268 |
" [pc: 5, line: 5]\n" + |
3269 |
" [pc: 9, line: 8]\n" + |
3270 |
" Local variable table:\n" + |
3271 |
" [pc: 0, pc: 17] local: this index: 0 type: new X(){}\n"; |
3272 |
} else { |
3273 |
expectedOutput = |
3274 |
" // Method descriptor #10 (LX;)V\n" + |
3275 |
" // Stack: 2, Locals: 2\n" + |
3276 |
" X$1(X arg0);\n" + |
3277 |
" 0 aload_0 [this]\n" + |
3278 |
" 1 aload_1 [arg0]\n" + |
3279 |
" 2 putfield X$1.this$0 : X [12]\n" + |
3280 |
" 5 aload_0 [this]\n" + |
3281 |
" 6 invokespecial java.lang.Object() [14]\n" + |
3282 |
" 9 getstatic java.lang.System.out : java.io.PrintStream [17]\n" + |
3283 |
" 12 iconst_4\n" + |
3284 |
" 13 invokevirtual java.io.PrintStream.print(int) : void [23]\n" + |
3285 |
" 16 return\n" + |
3286 |
" Line numbers:\n" + |
3287 |
" [pc: 0, line: 1]\n" + |
3288 |
" [pc: 5, line: 5]\n" + |
3289 |
" [pc: 9, line: 8]\n" + |
3290 |
" Local variable table:\n" + |
3291 |
" [pc: 0, pc: 17] local: this index: 0 type: new X(){}\n"; |
3292 |
} |
3293 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X$1.class", "X$1", expectedOutput); |
3294 |
} |
2282 |
} |
3295 |
} |