Lines 8-14
Link Here
|
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> - Contributions for |
10 |
* Stephan Herrmann <stephan@cs.tu-berlin.de> - Contributions for |
11 |
* bugs 325755, 133125, 292478, 319201, 320170 and 332637 |
11 |
* bug 325755 - [compiler] wrong initialization state after conditional expression |
|
|
12 |
* bug 133125 - [compiler][null] need to report the null status of expressions and analyze them simultaneously |
13 |
* bug 292478 - Report potentially null across variable assignment |
14 |
* bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE |
15 |
* bug 320170 - [compiler] [null] Whitebox issues in null analysis |
16 |
* bug 332637 - Dead Code detection removing code that isn't dead |
17 |
* bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop |
12 |
*******************************************************************************/ |
18 |
*******************************************************************************/ |
13 |
package org.eclipse.jdt.core.tests.compiler.regression; |
19 |
package org.eclipse.jdt.core.tests.compiler.regression; |
14 |
|
20 |
|
Lines 36-42
Link Here
|
36 |
// Only the highest compliance level is run; add the VM argument |
42 |
// Only the highest compliance level is run; add the VM argument |
37 |
// -Dcompliance=1.4 (for example) to lower it if needed |
43 |
// -Dcompliance=1.4 (for example) to lower it if needed |
38 |
static { |
44 |
static { |
39 |
// TESTS_NAMES = new String[] { "testBug325229" }; |
45 |
// TESTS_NAMES = new String[] { "testBug336428e" }; |
40 |
// TESTS_NUMBERS = new int[] { 561 }; |
46 |
// TESTS_NUMBERS = new int[] { 561 }; |
41 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
47 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
42 |
} |
48 |
} |
Lines 13833-13838
Link Here
|
13833 |
""); |
13839 |
""); |
13834 |
} |
13840 |
} |
13835 |
|
13841 |
|
|
|
13842 |
// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop |
13843 |
// original issue |
13844 |
public void testBug336428() { |
13845 |
this.runConformTest( |
13846 |
new String[] { |
13847 |
"DoWhileBug.java", |
13848 |
"public class DoWhileBug {\n" + |
13849 |
" void test(boolean b1, Object o1) {\n" + |
13850 |
" Object o2 = new Object();\n" + |
13851 |
" do {\n" + |
13852 |
" if (b1)\n" + |
13853 |
" o1 = null;\n" + |
13854 |
" } while ((o2 = o1) != null);\n" + |
13855 |
" }\n" + |
13856 |
"}" |
13857 |
}, |
13858 |
""); |
13859 |
} |
13860 |
// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop |
13861 |
// hitting the same implementation branch from within the loop |
13862 |
// information from unknown o1 is not propagated into the loop, analysis currently believes o2 is def null. |
13863 |
public void _testBug336428a() { |
13864 |
this.runConformTest( |
13865 |
new String[] { |
13866 |
"DoWhileBug.java", |
13867 |
"public class DoWhileBug {\n" + |
13868 |
" void test(boolean b1, Object o1) {\n" + |
13869 |
" Object o2 = null;\n" + |
13870 |
" do {\n" + |
13871 |
" if (b1)\n" + |
13872 |
" o1 = null;\n" + |
13873 |
" if ((o2 = o1) != null)\n" + |
13874 |
" break;\n" + |
13875 |
" } while (true);\n" + |
13876 |
" }\n" + |
13877 |
"}" |
13878 |
}, |
13879 |
""); |
13880 |
} |
13881 |
|
13882 |
// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop |
13883 |
// in this variant the analysis believes o2 is def unknown and doesn't even consider raising a warning. |
13884 |
public void _testBug336428b() { |
13885 |
this.runNegativeTest( |
13886 |
new String[] { |
13887 |
"DoWhileBug.java", |
13888 |
"public class DoWhileBug {\n" + |
13889 |
" void test(boolean b1) {\n" + |
13890 |
" Object o1 = null;\n" + |
13891 |
" Object o2 = null;\n" + |
13892 |
" do {\n" + |
13893 |
" if ((o2 = o1) == null) break;\n" + |
13894 |
" } while (true);\n" + |
13895 |
" }\n" + |
13896 |
"}" |
13897 |
}, |
13898 |
"----------\n" + |
13899 |
"1. ERROR in DoWhileBug.java (at line 6)\n" + |
13900 |
" if ((o2 = o1) == null) break;\n" + |
13901 |
" ^^^^^^^^^\n" + |
13902 |
"Redundant null check: The variable o2 can only be null at this location\n" + |
13903 |
"----------\n"); |
13904 |
} |
13905 |
|
13906 |
// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop |
13907 |
// in this case considering o1 as unknown is correct |
13908 |
public void testBug336428c() { |
13909 |
if (this.complianceLevel >= ClassFileConstants.JDK1_5) { |
13910 |
this.runConformTest( |
13911 |
new String[] { |
13912 |
"DoWhileBug.java", |
13913 |
"public class DoWhileBug {\n" + |
13914 |
" void test(boolean b1, Object o1) {\n" + |
13915 |
" Object o2 = null;\n" + |
13916 |
" do {\n" + |
13917 |
" if ((o2 = o1) == null) break;\n" + |
13918 |
" } while (true);\n" + |
13919 |
" }\n" + |
13920 |
"}" |
13921 |
}, |
13922 |
""); |
13923 |
} |
13924 |
} |
13925 |
|
13926 |
// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop |
13927 |
// one more if-statement triggers the expected warnings |
13928 |
public void testBug336428d() { |
13929 |
this.runNegativeTest( |
13930 |
new String[] { |
13931 |
"DoWhileBug.java", |
13932 |
"public class DoWhileBug {\n" + |
13933 |
" void test(boolean b1) {\n" + |
13934 |
" Object o1 = null;\n" + |
13935 |
" Object o2 = null;\n" + |
13936 |
" do {\n" + |
13937 |
" if (b1)\n" + |
13938 |
" o1 = null;\n" + |
13939 |
" if ((o2 = o1) == null) break;\n" + |
13940 |
" } while (true);\n" + |
13941 |
" }\n" + |
13942 |
"}" |
13943 |
}, |
13944 |
"----------\n" + |
13945 |
"1. ERROR in DoWhileBug.java (at line 7)\n" + |
13946 |
" o1 = null;\n" + |
13947 |
" ^^\n" + |
13948 |
"Redundant assignment: The variable o1 can only be null at this location\n" + |
13949 |
"----------\n" + |
13950 |
"2. ERROR in DoWhileBug.java (at line 8)\n" + |
13951 |
" if ((o2 = o1) == null) break;\n" + |
13952 |
" ^^^^^^^^^\n" + |
13953 |
"Redundant null check: The variable o2 can only be null at this location\n" + |
13954 |
"----------\n"); |
13955 |
} |
13956 |
|
13957 |
// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop |
13958 |
// same analysis, but assert instead of if suppresses the warning |
13959 |
public void testBug336428e() { |
13960 |
if (this.complianceLevel >= ClassFileConstants.JDK1_5) { |
13961 |
this.runNegativeTest( |
13962 |
new String[] { |
13963 |
"DoWhileBug.java", |
13964 |
"public class DoWhileBug {\n" + |
13965 |
" void test(boolean b1) {\n" + |
13966 |
" Object o1 = null;\n" + |
13967 |
" Object o2 = null;\n" + |
13968 |
" do {\n" + |
13969 |
" if (b1)\n" + |
13970 |
" o1 = null;\n" + |
13971 |
" assert (o2 = o1) == null : \"bug\";\n" + |
13972 |
" } while (true);\n" + |
13973 |
" }\n" + |
13974 |
"}" |
13975 |
}, |
13976 |
"----------\n" + |
13977 |
"1. ERROR in DoWhileBug.java (at line 7)\n" + |
13978 |
" o1 = null;\n" + |
13979 |
" ^^\n" + |
13980 |
"Redundant assignment: The variable o1 can only be null at this location\n" + |
13981 |
"----------\n"); |
13982 |
} |
13983 |
} |
13984 |
|
13836 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332838 |
13985 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332838 |
13837 |
// Null info of assert statements should not affect flow info |
13986 |
// Null info of assert statements should not affect flow info |
13838 |
// when CompilerOptions.OPTION_IncludeNullInfoFromAsserts is disabled. |
13987 |
// when CompilerOptions.OPTION_IncludeNullInfoFromAsserts is disabled. |