Lines 7-12
Link Here
|
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 332637 |
10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.tests.compiler.regression; |
12 |
package org.eclipse.jdt.core.tests.compiler.regression; |
12 |
|
13 |
|
Lines 749-760
Link Here
|
749 |
" o.toString();\n" + |
750 |
" o.toString();\n" + |
750 |
" }\n" + |
751 |
" }\n" + |
751 |
"}\n"}, |
752 |
"}\n"}, |
752 |
"----------\n" + |
753 |
"----------\n" + |
753 |
"1. ERROR in X.java (at line 4)\n" + |
754 |
"1. ERROR in X.java (at line 4)\n" + |
754 |
" o.toString();\n" + |
755 |
" o.toString();\n" + |
755 |
" ^\n" + |
756 |
" ^\n" + |
756 |
"The variable o may be null\n" + |
757 |
"The variable o may be null\n" + |
757 |
"----------\n"); |
758 |
"----------\n"); |
758 |
} |
759 |
} |
759 |
|
760 |
|
760 |
// null analysis -- conditional expression |
761 |
// null analysis -- conditional expression |
Lines 5598-5604
Link Here
|
5598 |
|
5599 |
|
5599 |
// null analysis - try/catch |
5600 |
// null analysis - try/catch |
5600 |
public void test0554_try_catch() { |
5601 |
public void test0554_try_catch() { |
5601 |
this.runConformTest( |
5602 |
this.runNegativeTest( |
5602 |
new String[] { |
5603 |
new String[] { |
5603 |
"X.java", |
5604 |
"X.java", |
5604 |
"public class X {\n" + |
5605 |
"public class X {\n" + |
Lines 5622-5635
Link Here
|
5622 |
" throw new LocalException();\n" + |
5623 |
" throw new LocalException();\n" + |
5623 |
" }\n" + |
5624 |
" }\n" + |
5624 |
"}\n"}, |
5625 |
"}\n"}, |
5625 |
"" |
5626 |
"----------\n" + |
5626 |
// conservative flow analysis suppresses the warning |
5627 |
"1. ERROR in X.java (at line 10)\n" + |
5627 |
// "----------\n" + |
5628 |
" if (o != null) {\n" + |
5628 |
// "1. ERROR in X.java (at line 10)\n" + |
5629 |
" ^\n" + |
5629 |
// " if (o != null) {\n" + |
5630 |
"Null comparison always yields false: The variable o can only be null at this location\n" + |
5630 |
// " ^\n" + |
5631 |
"----------\n" + |
5631 |
// "Redundant null check: The variable o can only be null at this location\n" + |
5632 |
"2. WARNING in X.java (at line 10)\n" + |
5632 |
// "----------\n" |
5633 |
" if (o != null) {\n" + |
|
|
5634 |
" }\n" + |
5635 |
" ^^^^^^^\n" + |
5636 |
"Dead code\n" + |
5637 |
"----------\n" |
5633 |
); |
5638 |
); |
5634 |
} |
5639 |
} |
5635 |
|
5640 |
|
Lines 5748-5756
Link Here
|
5748 |
"1. ERROR in X.java (at line 13)\n" + |
5753 |
"1. ERROR in X.java (at line 13)\n" + |
5749 |
" o.toString();\n" + |
5754 |
" o.toString();\n" + |
5750 |
" ^\n" + |
5755 |
" ^\n" + |
5751 |
// "Null pointer access: The variable o can only be null at this location\n" + |
5756 |
"Null pointer access: The variable o can only be null at this location\n" + |
5752 |
"Potential null pointer access: The variable o may be null at this location\n" + |
|
|
5753 |
// conservative flow analysis softens the error |
5754 |
"----------\n", |
5757 |
"----------\n", |
5755 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
5758 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
5756 |
} |
5759 |
} |
Lines 5785-5793
Link Here
|
5785 |
"1. ERROR in X.java (at line 12)\n" + |
5788 |
"1. ERROR in X.java (at line 12)\n" + |
5786 |
" o.toString();\n" + |
5789 |
" o.toString();\n" + |
5787 |
" ^\n" + |
5790 |
" ^\n" + |
5788 |
// "Null pointer access: The variable o can only be null at this location\n" + |
5791 |
"Null pointer access: The variable o can only be null at this location\n" + |
5789 |
"Potential null pointer access: The variable o may be null at this location\n" + |
|
|
5790 |
// conservative flow analysis softens the error |
5791 |
"----------\n", |
5792 |
"----------\n", |
5792 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
5793 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
5793 |
} |
5794 |
} |
Lines 12664-12667
Link Here
|
12664 |
"}"}, |
12665 |
"}"}, |
12665 |
"Compiler good Compiler good"); |
12666 |
"Compiler good Compiler good"); |
12666 |
} |
12667 |
} |
|
|
12668 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332637 |
12669 |
// Dead Code detection removing code that isn't dead |
12670 |
public void testBug332637() { |
12671 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
12672 |
return; |
12673 |
this.runConformTest( |
12674 |
new String[] { |
12675 |
"DeadCodeExample.java", |
12676 |
"public class DeadCodeExample {\n" + |
12677 |
"\n" + |
12678 |
" private class CanceledException extends Exception {\n" + |
12679 |
" }\n" + |
12680 |
"\n" + |
12681 |
" private interface ProgressMonitor {\n" + |
12682 |
" boolean isCanceled();\n" + |
12683 |
" }\n" + |
12684 |
"\n" + |
12685 |
" private void checkForCancellation(ProgressMonitor monitor)\n" + |
12686 |
" throws CanceledException {\n" + |
12687 |
" if (monitor.isCanceled()) {\n" + |
12688 |
" throw new CanceledException();\n" + |
12689 |
" }\n" + |
12690 |
" }\n" + |
12691 |
"\n" + |
12692 |
" private int run() {\n" + |
12693 |
"\n" + |
12694 |
" ProgressMonitor monitor = new ProgressMonitor() {\n" + |
12695 |
" private int i = 0;\n" + |
12696 |
"\n" + |
12697 |
" public boolean isCanceled() {\n" + |
12698 |
" return (++i == 5);\n" + |
12699 |
" }\n" + |
12700 |
" };\n" + |
12701 |
"\n" + |
12702 |
" Integer number = null;\n" + |
12703 |
"\n" + |
12704 |
" try {\n" + |
12705 |
" checkForCancellation(monitor);\n" + |
12706 |
"\n" + |
12707 |
" number = Integer.valueOf(0);\n" + |
12708 |
"\n" + |
12709 |
" for (String s : new String[10]) {\n" + |
12710 |
" checkForCancellation(monitor);\n" + |
12711 |
" number++;\n" + |
12712 |
" }\n" + |
12713 |
" return 0;\n" + |
12714 |
" } catch (CanceledException e) {\n" + |
12715 |
" System.out.println(\"Canceled after \" + number\n" + |
12716 |
" + \" times through the loop\");\n" + |
12717 |
" if (number != null) {\n" + |
12718 |
" System.out.println(\"number = \" + number);\n" + |
12719 |
" }\n" + |
12720 |
" return -1;\n" + |
12721 |
" }\n" + |
12722 |
" }\n" + |
12723 |
"\n" + |
12724 |
" public static void main(String[] args) {\n" + |
12725 |
" System.out.println(new DeadCodeExample().run());\n" + |
12726 |
" }\n" + |
12727 |
"}\n" |
12728 |
}); |
12729 |
} |
12667 |
} |
12730 |
} |