View | Details | Raw Unified | Return to bug 292478 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java (-1 / +8 lines)
Lines 8-14 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Genady Beriozkin - added support for reporting assignment with no effect
10
 *     Genady Beriozkin - added support for reporting assignment with no effect
11
 *     Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
11
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
12
 *     												and bug 292478 - Report potentially null across variable assignment
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.jdt.internal.compiler.ast;
14
package org.eclipse.jdt.internal.compiler.ast;
14
15
Lines 59-64 Link Here
59
			case FlowInfo.NON_NULL :
60
			case FlowInfo.NON_NULL :
60
				flowInfo.markAsDefinitelyNonNull(local);
61
				flowInfo.markAsDefinitelyNonNull(local);
61
				break;
62
				break;
63
			case FlowInfo.POTENTIALLY_NULL :
64
				flowInfo.markAsPotentiallyNull(local);
65
				break;
62
			default:
66
			default:
63
				flowInfo.markAsDefinitelyUnknown(local);
67
				flowInfo.markAsDefinitelyUnknown(local);
64
		}
68
		}
Lines 70-75 Link Here
70
				case FlowInfo.NON_NULL :
74
				case FlowInfo.NON_NULL :
71
					flowContext.initsOnFinally.markAsDefinitelyNonNull(local);
75
					flowContext.initsOnFinally.markAsDefinitelyNonNull(local);
72
					break;
76
					break;
77
				case FlowInfo.POTENTIALLY_NULL :
78
					flowContext.initsOnFinally.markAsPotentiallyNull(local);
79
					break;
73
				default:
80
				default:
74
					flowContext.initsOnFinally.markAsDefinitelyUnknown(local);
81
					flowContext.initsOnFinally.markAsDefinitelyUnknown(local);
75
			}
82
			}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java (-4 / +7 lines)
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 292478 - Report potentially null across variable assignment
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
12
package org.eclipse.jdt.internal.compiler.ast;
12
13
Lines 829-839 Link Here
829
	this.bits |= ASTNode.IsNonNull;
830
	this.bits |= ASTNode.IsNonNull;
830
}
831
}
831
832
832
	public int nullStatus(FlowInfo flowInfo) {
833
public int nullStatus(FlowInfo flowInfo) {
833
834
834
		if (/* (this.bits & IsNonNull) != 0 || */
835
	if (/* (this.bits & IsNonNull) != 0 || */
835
			this.constant != null && this.constant != Constant.NotAConstant)
836
		this.constant != null && this.constant != Constant.NotAConstant)
836
		return FlowInfo.NON_NULL; // constant expression cannot be null
837
	return FlowInfo.NON_NULL; // constant expression cannot be null
837
838
838
	LocalVariableBinding local = localVariableBinding();
839
	LocalVariableBinding local = localVariableBinding();
839
	if (local != null) {
840
	if (local != null) {
Lines 841-846 Link Here
841
			return FlowInfo.NULL;
842
			return FlowInfo.NULL;
842
		if (flowInfo.isDefinitelyNonNull(local))
843
		if (flowInfo.isDefinitelyNonNull(local))
843
			return FlowInfo.NON_NULL;
844
			return FlowInfo.NON_NULL;
845
		if (flowInfo.isPotentiallyNull(local))
846
			return FlowInfo.POTENTIALLY_NULL;
844
		return FlowInfo.UNKNOWN;
847
		return FlowInfo.UNKNOWN;
845
	}
848
	}
846
	return FlowInfo.NON_NULL;
849
	return FlowInfo.NON_NULL;
(-)compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java (-1 / +5 lines)
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 - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
11
 *     												and bug 292478 - Report potentially null across variable assignment
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.internal.compiler.ast;
13
package org.eclipse.jdt.internal.compiler.ast;
13
14
Lines 63-68 Link Here
63
			case FlowInfo.NON_NULL :
64
			case FlowInfo.NON_NULL :
64
				flowInfo.markAsDefinitelyNonNull(this.binding);
65
				flowInfo.markAsDefinitelyNonNull(this.binding);
65
				break;
66
				break;
67
			case FlowInfo.POTENTIALLY_NULL :
68
				flowInfo.markAsPotentiallyNull(this.binding);
69
				break;
66
			default:
70
			default:
67
				flowInfo.markAsDefinitelyUnknown(this.binding);
71
				flowInfo.markAsDefinitelyUnknown(this.binding);
68
		}
72
		}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java (+3 lines)
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 292478 - Report potentially null across variable assignment
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
12
package org.eclipse.jdt.internal.compiler.ast;
12
13
Lines 774-779 Link Here
774
					return FlowInfo.NULL;
775
					return FlowInfo.NULL;
775
				if (flowInfo.isDefinitelyNonNull(local))
776
				if (flowInfo.isDefinitelyNonNull(local))
776
					return FlowInfo.NON_NULL;
777
					return FlowInfo.NON_NULL;
778
				if (flowInfo.isPotentiallyNull(local))
779
					return FlowInfo.POTENTIALLY_NULL;
777
				return FlowInfo.UNKNOWN;
780
				return FlowInfo.UNKNOWN;
778
			}
781
			}
779
	}
782
	}
(-)compiler/org/eclipse/jdt/internal/compiler/flow/ConditionalFlowInfo.java (+5 lines)
Lines 157-162 Link Here
157
	this.initsWhenFalse.markAsDefinitelyNull(local);
157
	this.initsWhenFalse.markAsDefinitelyNull(local);
158
}
158
}
159
159
160
public void markAsPotentiallyNull(LocalVariableBinding local) {
161
	this.initsWhenTrue.markAsPotentiallyNull(local);
162
	this.initsWhenFalse.markAsPotentiallyNull(local);
163
}
164
160
public void markAsDefinitelyUnknown(LocalVariableBinding local) {
165
public void markAsDefinitelyUnknown(LocalVariableBinding local) {
161
	this.initsWhenTrue.markAsDefinitelyUnknown(local);
166
	this.initsWhenTrue.markAsDefinitelyUnknown(local);
162
	this.initsWhenFalse.markAsDefinitelyUnknown(local);
167
	this.initsWhenFalse.markAsDefinitelyUnknown(local);
(-)compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java (+7 lines)
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 292478 - Report potentially null across variable assignment
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.flow;
12
package org.eclipse.jdt.internal.compiler.flow;
12
13
Lines 25-30 Link Here
25
	public final static int UNKNOWN = 0;
26
	public final static int UNKNOWN = 0;
26
	public final static int NULL = 1;
27
	public final static int NULL = 1;
27
	public final static int NON_NULL = -1;
28
	public final static int NON_NULL = -1;
29
	public final static int POTENTIALLY_NULL = 2;
28
30
29
	public static final UnconditionalFlowInfo DEAD_END; // Represents a dead branch status of initialization
31
	public static final UnconditionalFlowInfo DEAD_END; // Represents a dead branch status of initialization
30
	static {
32
	static {
Lines 246-251 Link Here
246
	 * Record a local got definitely assigned to null.
248
	 * Record a local got definitely assigned to null.
247
	 */
249
	 */
248
	abstract public void markAsDefinitelyNull(LocalVariableBinding local);
250
	abstract public void markAsDefinitelyNull(LocalVariableBinding local);
251
	
252
	/**
253
	 * Record a local may have got assigned to null.
254
	 */
255
	abstract public void markAsPotentiallyNull(LocalVariableBinding local);
249
256
250
	/**
257
	/**
251
	 * Record a local got definitely assigned.
258
	 * Record a local got definitely assigned.
(-)compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java (-1 / +34 lines)
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 bug 320170   
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bugs 320170 and 292478   
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.compiler.flow;
12
package org.eclipse.jdt.internal.compiler.flow;
13
13
Lines 1330-1335 Link Here
1330
	}
1330
	}
1331
}
1331
}
1332
1332
1333
public void markAsPotentiallyNull(LocalVariableBinding local) {
1334
	if (this != DEAD_END) {
1335
		this.tagBits |= NULL_FLAG_MASK;
1336
        int position;
1337
        long mask;
1338
        if ((position = local.id + this.maxFieldCount) < BitCacheSize) {
1339
            // use bits
1340
            this.nullBit1 &= ~(mask = 1L << position);
1341
            this.nullBit2 |= mask;
1342
            this.nullBit3 &= ~mask;
1343
            this.nullBit4 &= ~mask;
1344
            if (COVERAGE_TEST_FLAG) {
1345
				if(CoverageTestId == 40) {
1346
				  	this.nullBit4 = ~0;
1347
				}
1348
			}
1349
        } else {
1350
    		// use extra vector
1351
    		int vectorIndex ;
1352
    		this.extra[2][vectorIndex = (position / BitCacheSize) - 1]
1353
    		    &= ~(mask = 1L << (position % BitCacheSize));
1354
    		this.extra[3][vectorIndex] |= mask;
1355
    		this.extra[4][vectorIndex] &= (mask = ~mask);
1356
    		this.extra[5][vectorIndex] &= mask;
1357
    		if (COVERAGE_TEST_FLAG) {
1358
				if(CoverageTestId == 41) {
1359
					this.extra[5][vectorIndex] = ~0;
1360
				}
1361
			}
1362
    	}
1363
	}
1364
}
1365
1333
public UnconditionalFlowInfo mergedWith(UnconditionalFlowInfo otherInits) {
1366
public UnconditionalFlowInfo mergedWith(UnconditionalFlowInfo otherInits) {
1334
	if ((otherInits.tagBits & UNREACHABLE) != 0 && this != DEAD_END) {
1367
	if ((otherInits.tagBits & UNREACHABLE) != 0 && this != DEAD_END) {
1335
		if (COVERAGE_TEST_FLAG) {
1368
		if (COVERAGE_TEST_FLAG) {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTests.java (-5 / +17 lines)
Lines 25-30 Link Here
25
import java.util.SortedMap;
25
import java.util.SortedMap;
26
import java.util.TreeMap;
26
import java.util.TreeMap;
27
27
28
import junit.framework.AssertionFailedError;
29
import junit.framework.Test;
30
import junit.framework.TestSuite;
31
28
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
32
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
29
import org.eclipse.jdt.internal.compiler.flow.NullInfoRegistry;
33
import org.eclipse.jdt.internal.compiler.flow.NullInfoRegistry;
30
import org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo;
34
import org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo;
Lines 34-43 Link Here
34
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
38
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
35
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
39
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
36
40
37
import junit.framework.AssertionFailedError;
38
import junit.framework.Test;
39
import junit.framework.TestSuite;
40
41
/**
41
/**
42
 * A tests series especially meant to validate the internals of our null
42
 * A tests series especially meant to validate the internals of our null
43
 * reference analysis. See NullReferenceTest for tests targetted at
43
 * reference analysis. See NullReferenceTest for tests targetted at
Lines 559-564 Link Here
559
	assertTrue("nb of failures: " + failures, failures == 0);
559
	assertTrue("nb of failures: " + failures, failures == 0);
560
}
560
}
561
561
562
public void test2058_markAsPotentiallyNull() {
563
	int failures = NullReferenceImplTransformations.markAsPotentiallyNull.test();
564
	assertTrue("nb of failures: " + failures, failures == 0);
565
}
566
562
public void test2060_addInitializationsFrom() {
567
public void test2060_addInitializationsFrom() {
563
	int failures = NullReferenceImplTransformations.addInitializationsFrom.test();
568
	int failures = NullReferenceImplTransformations.addInitializationsFrom.test();
564
	assertTrue("nb of failures: " + failures, failures == 0);
569
	assertTrue("nb of failures: " + failures, failures == 0);
Lines 854-860 Link Here
854
// Note: coverage tests tend to fill the console with messages, and the
859
// Note: coverage tests tend to fill the console with messages, and the
855
//       instrumented code is slower, so never release code with active
860
//       instrumented code is slower, so never release code with active
856
//       coverage tests.
861
//       coverage tests.
857
private static int coveragePointsNb = 39;
862
private static int coveragePointsNb = 41;
858
863
859
// PREMATURE reactivate coverage tests
864
// PREMATURE reactivate coverage tests
860
// Coverage by state transition tables methods.
865
// Coverage by state transition tables methods.
Lines 870-875 Link Here
870
		test2055_markAsDefinitelyNonNull();
875
		test2055_markAsDefinitelyNonNull();
871
		test2056_markAsDefinitelyNull();
876
		test2056_markAsDefinitelyNull();
872
		test2057_markAsDefinitelyUnknown();
877
		test2057_markAsDefinitelyUnknown();
878
		test2058_markAsPotentiallyNull();
873
		test2060_addInitializationsFrom();
879
		test2060_addInitializationsFrom();
874
		test2061_addPotentialInitializationsFrom();
880
		test2061_addPotentialInitializationsFrom();
875
		test2062_mergedWith();
881
		test2062_mergedWith();
Lines 891-896 Link Here
891
				test2055_markAsDefinitelyNonNull();
897
				test2055_markAsDefinitelyNonNull();
892
				test2056_markAsDefinitelyNull();
898
				test2056_markAsDefinitelyNull();
893
				test2057_markAsDefinitelyUnknown();
899
				test2057_markAsDefinitelyUnknown();
900
				test2058_markAsPotentiallyNull();
894
				test2060_addInitializationsFrom();
901
				test2060_addInitializationsFrom();
895
				test2061_addPotentialInitializationsFrom();
902
				test2061_addPotentialInitializationsFrom();
896
				test2062_mergedWith();
903
				test2062_mergedWith();
Lines 1098-1103 Link Here
1098
	super.markAsDefinitelyUnknown(local);
1105
	super.markAsDefinitelyUnknown(local);
1099
}
1106
}
1100
1107
1108
public void markAsPotentiallyNull(LocalVariableBinding local) {
1109
	grow(local.id + this.maxFieldCount);
1110
	super.markAsPotentiallyNull(local);
1111
}
1112
1101
/**
1113
/**
1102
 * Return a fake unconditional flow info which bit fields represent the given
1114
 * Return a fake unconditional flow info which bit fields represent the given
1103
 * null bits for a local variable of id 0 within a class that would have no
1115
 * null bits for a local variable of id 0 within a class that would have no
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTransformations.java (-1 / +45 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
2
 * Copyright (c) 2005, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 242-247 Link Here
242
				return result;
242
				return result;
243
			}
243
			}
244
		},
244
		},
245
		markAsPotentiallyNull =
246
			// markAsDefinitelyNull DEFINITION START
247
			// start => pot. null
248
			// prot. non null => pot. null
249
			// prot. null => pot. null
250
			// pot. unknown => pot. null
251
			// pot. non null => pot. null
252
			// pot. nn & prot. nn => pot. null
253
			// pot. nn & pot. un => pot. null
254
			// pot. null => pot. null
255
			// pot. n & prot. n => pot. null
256
			// pot. n & pot. un => pot. null
257
			// pot. n & pot. nn => pot. null
258
			// def. unknown => pot. null
259
			// def. non null => pot. null
260
			// def. null => pot. null
261
			// markAsPotentiallyNull DEFINITION END
262
				// PREMATURE add 'catch rules'
263
				new TwoDimensionalTransformation("markAsPotentiallyNull",
264
					new byte[][] {
265
					// markAsPotentiallyNull INITIALIZER START
266
					{0x00,0x08},
267
					{0x04,0x08},
268
					{0x08,0x08},
269
					{0x0C,0x08},
270
					{0x10,0x08},
271
					{0x14,0x08},
272
					{0x18,0x08},
273
					{0x24,0x08},
274
					{0x28,0x08},
275
					{0x2C,0x08},
276
					{0x30,0x08},
277
					{0x34,0x08},
278
					{0x38,0x08},
279
					{0x3C,0x08},
280
					// markAsPotentiallyNull INITIALIZER END
281
					}) {
282
				UnconditionalFlowInfo output(UnconditionalFlowInfo input,
283
						TestLocalVariableBinding local) {
284
					UnconditionalFlowInfo result = (UnconditionalFlowInfo)input.copy();
285
					result.markAsPotentiallyNull(local);
286
					return result;
287
				}
288
			},
245
		addInitializationsFrom =
289
		addInitializationsFrom =
246
		// addInitializationsFrom DEFINITION START
290
		// addInitializationsFrom DEFINITION START
247
		// def. non null + def. non null => def. non null
291
		// def. non null + def. non null => def. non null
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (-1 / +133 lines)
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
}

Return to bug 292478