Lines 7-13
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 bugs 319201 and 320170 |
10 |
* Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bugs 292478, 319201 and 320170 |
11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
12 |
package org.eclipse.jdt.core.tests.compiler.regression; |
12 |
package org.eclipse.jdt.core.tests.compiler.regression; |
13 |
|
13 |
|
Lines 13021-13024
Link Here
|
13021 |
"}"}, |
13021 |
"}"}, |
13022 |
"Compiler good Compiler good"); |
13022 |
"Compiler good Compiler good"); |
13023 |
} |
13023 |
} |
|
|
13024 |
|
13025 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment |
13026 |
// LocalDeclaration |
13027 |
public void testBug292478() { |
13028 |
this.runNegativeTest( |
13029 |
new String[] { |
13030 |
"X.java", |
13031 |
"public class X {\n" + |
13032 |
" void foo(Object o) {\n" + |
13033 |
" if (o != null) {/* */}\n" + |
13034 |
" Object p = o;\n" + |
13035 |
" p.toString();\n" + // complain here |
13036 |
" }\n" + |
13037 |
"}"}, |
13038 |
"----------\n" + |
13039 |
"1. ERROR in X.java (at line 5)\n" + |
13040 |
" p.toString();\n" + |
13041 |
" ^\n" + |
13042 |
"Potential null pointer access: The variable p may be null at this location\n" + |
13043 |
"----------\n", |
13044 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
13045 |
} |
13046 |
|
13047 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment |
13048 |
// Assignment |
13049 |
public void testBug292478a() { |
13050 |
this.runNegativeTest( |
13051 |
new String[] { |
13052 |
"X.java", |
13053 |
"public class X {\n" + |
13054 |
" void foo(Object o) {\n" + |
13055 |
" Object p;" + |
13056 |
" if (o != null) {/* */}\n" + |
13057 |
" p = o;\n" + |
13058 |
" p.toString();\n" + // complain here |
13059 |
" }\n" + |
13060 |
"}"}, |
13061 |
"----------\n" + |
13062 |
"1. ERROR in X.java (at line 5)\n" + |
13063 |
" p.toString();\n" + |
13064 |
" ^\n" + |
13065 |
"Potential null pointer access: The variable p may be null at this location\n" + |
13066 |
"----------\n", |
13067 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
13068 |
} |
13069 |
|
13070 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment |
13071 |
// Assignment after definite null |
13072 |
public void testBug292478b() { |
13073 |
this.runNegativeTest( |
13074 |
new String[] { |
13075 |
"X.java", |
13076 |
"public class X {\n" + |
13077 |
" void foo(Object o) {\n" + |
13078 |
" Object p = null;\n" + |
13079 |
" if (o != null) {/* */}\n" + |
13080 |
" p = o;\n" + |
13081 |
" p.toString();\n" + // complain here |
13082 |
" }\n" + |
13083 |
"}"}, |
13084 |
"----------\n" + |
13085 |
"1. ERROR in X.java (at line 6)\n" + |
13086 |
" p.toString();\n" + |
13087 |
" ^\n" + |
13088 |
"Potential null pointer access: The variable p may be null at this location\n" + |
13089 |
"----------\n", |
13090 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
13091 |
} |
13092 |
|
13093 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment |
13094 |
// Assignment after definite null - many locals |
13095 |
public void testBug292478c() { |
13096 |
this.runNegativeTest( |
13097 |
new String[] { |
13098 |
"X.java", |
13099 |
"public class X {\n" + |
13100 |
" void foo(Object o) {\n" + |
13101 |
" int i00, i01, i02, i03, i04, i05, i06, i07, i08, i09;\n" + |
13102 |
" int i10, i11, i12, i13, i14, i15, i16, i17, i18, i19;\n" + |
13103 |
" int i20, i21, i22, i23, i24, i25, i26, i27, i28, i29;\n" + |
13104 |
" int i30, i31, i32, i33, i34, i35, i36, i37, i38, i39;\n" + |
13105 |
" int i40, i41, i42, i43, i44, i45, i46, i47, i48, i49;\n" + |
13106 |
" int i50, i51, i52, i53, i54, i55, i56, i57, i58, i59;\n" + |
13107 |
" int i60, i61, i62, i63, i64, i65, i66, i67, i68, i69;\n" + |
13108 |
" Object p = null;\n" + |
13109 |
" if (o != null) {/* */}\n" + |
13110 |
" p = o;\n" + |
13111 |
" p.toString();\n" + // complain here |
13112 |
" }\n" + |
13113 |
"}"}, |
13114 |
"----------\n" + |
13115 |
"1. ERROR in X.java (at line 13)\n" + |
13116 |
" p.toString();\n" + |
13117 |
" ^\n" + |
13118 |
"Potential null pointer access: The variable p may be null at this location\n" + |
13119 |
"----------\n", |
13120 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
13121 |
} |
13122 |
|
13123 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment |
13124 |
// Assignment affects initsOnFinally |
13125 |
public void testBug292478d() { |
13126 |
this.runNegativeTest( |
13127 |
new String[] { |
13128 |
"X.java", |
13129 |
"public class X {\n" + |
13130 |
" X bar() {\n" + |
13131 |
" return null;\n" + |
13132 |
" }\n" + |
13133 |
" Object foo() {\n" + |
13134 |
" X x = null;\n" + |
13135 |
" X y = new X();\n" + |
13136 |
" X u = null;\n" + |
13137 |
" try {\n" + |
13138 |
" u = bar();\n" + |
13139 |
" x = bar();\n" + |
13140 |
" if (x==null) { }\n" + |
13141 |
" y = x;\n" + // this makes y potentially null |
13142 |
" if (x==null) { y=bar();} else { y=new X(); }\n" + |
13143 |
" return x;\n" + |
13144 |
" } finally {\n" + |
13145 |
" y.toString();\n" + // must complain against potentially null, although normal exist of tryBlock says differently (unknown or non-null) |
13146 |
" }\n" + |
13147 |
" }\n" + |
13148 |
"}\n"}, |
13149 |
"----------\n" + |
13150 |
"1. ERROR in X.java (at line 17)\n" + |
13151 |
" y.toString();\n" + |
13152 |
" ^\n" + |
13153 |
"Potential null pointer access: The variable y may be null at this location\n" + |
13154 |
"----------\n"); |
13155 |
} |
13024 |
} |
13156 |
} |