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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java (+72 lines)
Lines 17-22 Link Here
17
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
17
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
18
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
18
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
19
import org.eclipse.jdt.internal.compiler.lookup.Scope;
19
import org.eclipse.jdt.internal.compiler.lookup.Scope;
20
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
20
import org.eclipse.jdt.internal.compiler.lookup.VariableBinding;
21
import org.eclipse.jdt.internal.compiler.lookup.VariableBinding;
21
22
22
/**
23
/**
Lines 110-118 Link Here
110
					if (flowInfo.isDefinitelyNull(local)) {
111
					if (flowInfo.isDefinitelyNull(local)) {
111
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
112
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
112
							case FlowContext.IN_COMPARISON_NULL:
113
							case FlowContext.IN_COMPARISON_NULL:
114
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
115
									scope.problemReporter().localVariableNullReference(local, expression);
116
									continue;
117
								}
113
								scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
118
								scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
114
								continue;
119
								continue;
115
							case FlowContext.IN_COMPARISON_NON_NULL:
120
							case FlowContext.IN_COMPARISON_NON_NULL:
121
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
122
									scope.problemReporter().localVariableNullReference(local, expression);
123
									continue;
124
								}
116
								scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
125
								scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
117
								continue;
126
								continue;
118
							case FlowContext.IN_ASSIGNMENT:
127
							case FlowContext.IN_ASSIGNMENT:
Lines 122-127 Link Here
122
								scope.problemReporter().localVariableNullInstanceof(local, expression);
131
								scope.problemReporter().localVariableNullInstanceof(local, expression);
123
								continue;
132
								continue;
124
						}
133
						}
134
					} else if (flowInfo.isPotentiallyNull(local)) {
135
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
136
							case FlowContext.IN_COMPARISON_NULL:
137
								this.nullReferences[i] = null;
138
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
139
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
140
									continue;
141
								}
142
								break;
143
							case FlowContext.IN_COMPARISON_NON_NULL:
144
								this.nullReferences[i] = null;
145
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
146
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
147
									continue;
148
								}
149
								break;
150
						}
125
					}
151
					}
126
					break;
152
					break;
127
				case MAY_NULL:
153
				case MAY_NULL:
Lines 202-211 Link Here
202
						if (flowInfo.canOnlyBeNull(local)) {
228
						if (flowInfo.canOnlyBeNull(local)) {
203
							switch(checkType & CONTEXT_MASK) {
229
							switch(checkType & CONTEXT_MASK) {
204
								case FlowContext.IN_COMPARISON_NULL:
230
								case FlowContext.IN_COMPARISON_NULL:
231
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
232
										scope.problemReporter().localVariableNullReference(local, reference);
233
										return;
234
									}
205
									scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
235
									scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
206
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
236
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
207
									return;
237
									return;
208
								case FlowContext.IN_COMPARISON_NON_NULL:
238
								case FlowContext.IN_COMPARISON_NON_NULL:
239
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
240
										scope.problemReporter().localVariableNullReference(local, reference);
241
										return;
242
									}
209
									scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
243
									scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
210
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
244
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
211
									return;
245
									return;
Lines 216-221 Link Here
216
									scope.problemReporter().localVariableNullInstanceof(local, reference);
250
									scope.problemReporter().localVariableNullInstanceof(local, reference);
217
									return;
251
									return;
218
							}
252
							}
253
						} else if (flowInfo.isPotentiallyNull(local)) {
254
							switch(checkType & CONTEXT_MASK) {
255
								case FlowContext.IN_COMPARISON_NULL:
256
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
257
										scope.problemReporter().localVariablePotentialNullReference(local, reference);
258
										return;
259
									}
260
									break;
261
								case FlowContext.IN_COMPARISON_NON_NULL:
262
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
263
										scope.problemReporter().localVariablePotentialNullReference(local, reference);
264
										return;
265
									}
266
									break;
267
							}
219
						}
268
						}
220
						break;
269
						break;
221
					case MAY_NULL :
270
					case MAY_NULL :
Lines 253-262 Link Here
253
						if (flowInfo.isDefinitelyNull(local)) {
302
						if (flowInfo.isDefinitelyNull(local)) {
254
							switch(checkType & CONTEXT_MASK) {
303
							switch(checkType & CONTEXT_MASK) {
255
								case FlowContext.IN_COMPARISON_NULL:
304
								case FlowContext.IN_COMPARISON_NULL:
305
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
306
										scope.problemReporter().localVariableNullReference(local, reference);
307
										return;
308
									}
256
									scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
309
									scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
257
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
310
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
258
									return;
311
									return;
259
								case FlowContext.IN_COMPARISON_NON_NULL:
312
								case FlowContext.IN_COMPARISON_NON_NULL:
313
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
314
										scope.problemReporter().localVariableNullReference(local, reference);
315
										return;
316
									}
260
									scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
317
									scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
261
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
318
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
262
									return;
319
									return;
Lines 267-272 Link Here
267
									scope.problemReporter().localVariableNullInstanceof(local, reference);
324
									scope.problemReporter().localVariableNullInstanceof(local, reference);
268
									return;
325
									return;
269
							}
326
							}
327
						} else if (flowInfo.isPotentiallyNull(local)) {
328
							switch(checkType & CONTEXT_MASK) {
329
								case FlowContext.IN_COMPARISON_NULL:
330
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
331
										scope.problemReporter().localVariablePotentialNullReference(local, reference);
332
										return;
333
									}
334
									break;
335
								case FlowContext.IN_COMPARISON_NON_NULL:
336
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
337
										scope.problemReporter().localVariablePotentialNullReference(local, reference);
338
										return;
339
									}
340
									break;
341
							}
270
						}
342
						}
271
						break;
343
						break;
272
					case MAY_NULL :
344
					case MAY_NULL :
(-)compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java (+24 lines)
Lines 27-32 Link Here
27
import org.eclipse.jdt.internal.compiler.lookup.Scope;
27
import org.eclipse.jdt.internal.compiler.lookup.Scope;
28
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
28
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
29
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
29
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
30
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
30
import org.eclipse.jdt.internal.compiler.lookup.VariableBinding;
31
import org.eclipse.jdt.internal.compiler.lookup.VariableBinding;
31
32
32
/**
33
/**
Lines 561-570 Link Here
561
			if (flowInfo.isDefinitelyNull(local)) {
562
			if (flowInfo.isDefinitelyNull(local)) {
562
				switch(checkType & CONTEXT_MASK) {
563
				switch(checkType & CONTEXT_MASK) {
563
					case FlowContext.IN_COMPARISON_NULL:
564
					case FlowContext.IN_COMPARISON_NULL:
565
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
566
							scope.problemReporter().localVariableNullReference(local, reference);
567
							return;
568
						}
564
						scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
569
						scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
565
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
570
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
566
						return;
571
						return;
567
					case FlowContext.IN_COMPARISON_NON_NULL:
572
					case FlowContext.IN_COMPARISON_NON_NULL:
573
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
574
							scope.problemReporter().localVariableNullReference(local, reference);
575
							return;
576
						}
568
						scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
577
						scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
569
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
578
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
570
						return;
579
						return;
Lines 575-580 Link Here
575
						scope.problemReporter().localVariableNullInstanceof(local, reference);
584
						scope.problemReporter().localVariableNullInstanceof(local, reference);
576
						return;
585
						return;
577
				}
586
				}
587
			} else if (flowInfo.isPotentiallyNull(local)) {
588
				switch(checkType & CONTEXT_MASK) {
589
					case FlowContext.IN_COMPARISON_NULL:
590
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
591
							scope.problemReporter().localVariablePotentialNullReference(local, reference);
592
							return;
593
						}
594
						break;
595
					case FlowContext.IN_COMPARISON_NON_NULL:
596
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
597
							scope.problemReporter().localVariablePotentialNullReference(local, reference);
598
							return;
599
						}
600
						break;
601
				}
578
			} else if (flowInfo.cannotBeDefinitelyNullOrNonNull(local)) {
602
			} else if (flowInfo.cannotBeDefinitelyNullOrNonNull(local)) {
579
				return;
603
				return;
580
			}
604
			}
(-)compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java (-1 / +75 lines)
Lines 18-23 Link Here
18
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
18
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
19
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
19
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
20
import org.eclipse.jdt.internal.compiler.lookup.Scope;
20
import org.eclipse.jdt.internal.compiler.lookup.Scope;
21
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
21
import org.eclipse.jdt.internal.compiler.lookup.VariableBinding;
22
import org.eclipse.jdt.internal.compiler.lookup.VariableBinding;
22
23
23
/**
24
/**
Lines 163-171 Link Here
163
						this.nullReferences[i] = null;
164
						this.nullReferences[i] = null;
164
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
165
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
165
							case FlowContext.IN_COMPARISON_NULL:
166
							case FlowContext.IN_COMPARISON_NULL:
167
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
168
									scope.problemReporter().localVariableNullReference(local, expression);
169
									continue;
170
								}
166
								scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
171
								scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
167
								continue;
172
								continue;
168
							case FlowContext.IN_COMPARISON_NON_NULL:
173
							case FlowContext.IN_COMPARISON_NON_NULL:
174
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
175
									scope.problemReporter().localVariableNullReference(local, expression);
176
									continue;
177
								}
169
								scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
178
								scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
170
								continue;
179
								continue;
171
							case FlowContext.IN_ASSIGNMENT:
180
							case FlowContext.IN_ASSIGNMENT:
Lines 175-181 Link Here
175
								scope.problemReporter().localVariableNullInstanceof(local, expression);
184
								scope.problemReporter().localVariableNullInstanceof(local, expression);
176
								continue;
185
								continue;
177
						}
186
						}
178
					}
187
					} else if (flowInfo.isPotentiallyNull(local)) {
188
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
189
							case FlowContext.IN_COMPARISON_NULL:
190
								this.nullReferences[i] = null;
191
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
192
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
193
									continue;
194
								}
195
								break;
196
							case FlowContext.IN_COMPARISON_NON_NULL:
197
								this.nullReferences[i] = null;
198
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
199
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
200
									continue;
201
								}
202
								break;
203
						}
204
					}					
179
					break;
205
					break;
180
				case MAY_NULL:
206
				case MAY_NULL:
181
					if (flowInfo.isDefinitelyNull(local)) {
207
					if (flowInfo.isDefinitelyNull(local)) {
Lines 218-226 Link Here
218
						this.nullReferences[i] = null;
244
						this.nullReferences[i] = null;
219
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
245
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
220
							case FlowContext.IN_COMPARISON_NULL:
246
							case FlowContext.IN_COMPARISON_NULL:
247
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
248
									scope.problemReporter().localVariableNullReference(local, expression);
249
									continue;
250
								}
221
								scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
251
								scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
222
								continue;
252
								continue;
223
							case FlowContext.IN_COMPARISON_NON_NULL:
253
							case FlowContext.IN_COMPARISON_NON_NULL:
254
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
255
									scope.problemReporter().localVariableNullReference(local, expression);
256
									continue;
257
								}
224
								scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
258
								scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
225
								continue;
259
								continue;
226
							case FlowContext.IN_ASSIGNMENT:
260
							case FlowContext.IN_ASSIGNMENT:
Lines 230-235 Link Here
230
								scope.problemReporter().localVariableNullInstanceof(local, expression);
264
								scope.problemReporter().localVariableNullInstanceof(local, expression);
231
								continue;
265
								continue;
232
						}
266
						}
267
					} else if (flowInfo.isPotentiallyNull(local)) {
268
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
269
							case FlowContext.IN_COMPARISON_NULL:
270
								this.nullReferences[i] = null;
271
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
272
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
273
									continue;
274
								}
275
								break;
276
							case FlowContext.IN_COMPARISON_NON_NULL:
277
								this.nullReferences[i] = null;
278
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
279
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
280
									continue;
281
								}
282
								break;
283
						}
233
					}
284
					}
234
					break;
285
					break;
235
				case MAY_NULL:
286
				case MAY_NULL:
Lines 431-440 Link Here
431
			if (flowInfo.isDefinitelyNull(local)) {
482
			if (flowInfo.isDefinitelyNull(local)) {
432
				switch(checkType & CONTEXT_MASK) {
483
				switch(checkType & CONTEXT_MASK) {
433
					case FlowContext.IN_COMPARISON_NULL:
484
					case FlowContext.IN_COMPARISON_NULL:
485
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
486
							scope.problemReporter().localVariableNullReference(local, reference);
487
							return;
488
						}
434
						scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
489
						scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
435
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
490
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
436
						return;
491
						return;
437
					case FlowContext.IN_COMPARISON_NON_NULL:
492
					case FlowContext.IN_COMPARISON_NON_NULL:
493
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
494
							scope.problemReporter().localVariableNullReference(local, reference);
495
							return;
496
						}
438
						scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
497
						scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
439
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
498
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
440
						return;
499
						return;
Lines 445-450 Link Here
445
						scope.problemReporter().localVariableNullInstanceof(local, reference);
504
						scope.problemReporter().localVariableNullInstanceof(local, reference);
446
						return;
505
						return;
447
				}
506
				}
507
			} else if (flowInfo.isPotentiallyNull(local)) {
508
				switch(checkType & CONTEXT_MASK) {
509
					case FlowContext.IN_COMPARISON_NULL:
510
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
511
							scope.problemReporter().localVariablePotentialNullReference(local, reference);
512
							return;
513
						}
514
						break;
515
					case FlowContext.IN_COMPARISON_NON_NULL:
516
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
517
							scope.problemReporter().localVariablePotentialNullReference(local, reference);
518
							return;
519
						}
520
						break;
521
				}
448
			}
522
			}
449
			recordNullReference(local, reference, checkType);
523
			recordNullReference(local, reference, checkType);
450
			return;
524
			return;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+218 lines)
Lines 10753-10756 Link Here
10753
		"Potential null pointer access: The variable bar may be null at this location\n" + 
10753
		"Potential null pointer access: The variable bar may be null at this location\n" + 
10754
		"----------\n");
10754
		"----------\n");
10755
}
10755
}
10756
10757
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
10758
// Test whether Null pointer access warnings are being reported correctly when auto-unboxing
10759
public void testBug253896a() {
10760
	if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
10761
		this.runNegativeTest(
10762
			new String[] {
10763
				"X.java",
10764
				"public class X {\n" +
10765
				"  public void foo() {\n" +
10766
				"    Integer f1 = null;\n" +
10767
				"	 if(f1 == 1)\n" +
10768
				" 	 	System.out.println(\"f1 is 1\");\n" +
10769
				"    Integer f2 = null;\n" +
10770
				"	 int abc = (f2 != 1)? 1 : 0;\n" +
10771
				"    Float f3 = null;\n" +
10772
				"	 if(f3 == null)\n" +
10773
				" 	 	System.out.println(\"f3 is null\");\n" +
10774
				"    Byte f4 = null;\n" +
10775
				"	 if(f4 != null)\n" +
10776
				" 	 	System.out.println(\"f4 is not null\");\n" +
10777
				"  }\n" +
10778
				"}"},
10779
			"----------\n" +
10780
			"1. ERROR in X.java (at line 4)\n" + 
10781
			"	if(f1 == 1)\n" + 
10782
			"	   ^^\n" + 
10783
			"Null pointer access: The variable f1 can only be null at this location\n" + 
10784
			"----------\n" + 
10785
			"2. ERROR in X.java (at line 7)\n" + 
10786
			"	int abc = (f2 != 1)? 1 : 0;\n" + 
10787
			"	           ^^\n" + 
10788
			"Null pointer access: The variable f2 can only be null at this location\n" + 
10789
			"----------\n" + 
10790
			"3. ERROR in X.java (at line 9)\n" + 
10791
			"	if(f3 == null)\n" + 
10792
			"	   ^^\n" + 
10793
			"Redundant null check: The variable f3 can only be null at this location\n" + 
10794
			"----------\n" + 
10795
			"4. ERROR in X.java (at line 12)\n" + 
10796
			"	if(f4 != null)\n" + 
10797
			"	   ^^\n" + 
10798
			"Null comparison always yields false: The variable f4 can only be null at this location\n" + 
10799
			"----------\n" + 
10800
			"5. WARNING in X.java (at line 13)\n" + 
10801
			"	System.out.println(\"f4 is not null\");\n" + 
10802
			"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
10803
			"Dead code\n" + 
10804
			"----------\n");
10805
	}
10806
}
10807
10808
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
10809
// To test whether null pointer access and potential null pointer access warnings are correctly reported when auto-unboxing
10810
public void testBug253896b() {
10811
	if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
10812
		this.runNegativeTest(
10813
			new String[] {
10814
				"X.java",
10815
				"public class X {\n" +
10816
				"  public void foo(Integer i1, Integer i2) {\n" +
10817
				"	 if(i1 == null && i2 == null){\n" +
10818
				"		if(i1 == 1)\n" +
10819
				" 	 	System.out.println(i1);}\n" +	//i1 is definitely null here
10820
				"	 else {\n" +
10821
				"		if(i1 == 0) {}\n" +		//i1 may be null here.
10822
				"	 }\n" +
10823
				"  }\n" +
10824
				"}"},
10825
			"----------\n" +
10826
			"1. ERROR in X.java (at line 4)\n" +
10827
			"	if(i1 == 1)\n" +
10828
			"	   ^^\n" +
10829
			"Null pointer access: The variable i1 can only be null at this location\n" +
10830
			"----------\n" +
10831
			"2. ERROR in X.java (at line 7)\n" +
10832
			"	if(i1 == 0) {}\n" +
10833
			"	   ^^\n" +
10834
			"Potential null pointer access: The variable i1 may be null at this location\n" +
10835
			"----------\n");
10836
	}
10837
}
10838
10839
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
10840
// Test whether Null pointer access warnings are being reported correctly when auto-unboxing inside loops
10841
public void testBug253896c() {
10842
	if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
10843
		this.runNegativeTest(
10844
			new String[] {
10845
				"X.java",
10846
				"public class X {\n" +
10847
				"  public void foo() {\n" +
10848
				"	 Integer a = null;\n" +
10849
				"	 Integer outer2 = null;\n" +
10850
				"	 while (true) {\n" +
10851
				"    	Integer f1 = null;\n" +
10852
				"	 	if(f1 == 1)\n" +
10853
				" 	 		System.out.println(\"f1 is 1\");\n" +
10854
				"    	Integer f2 = null;\n" +
10855
				"	 	int abc = (f2 != 1)? 1 : 0;\n" +
10856
				"    	Float f3 = null;\n" +
10857
				"	 	if(f3 == null)\n" +
10858
				" 	 		System.out.println(\"f3 is null\");\n" +
10859
				"    	Byte f4 = null;\n" +
10860
				"	 	if(f4 != null)\n" +
10861
				" 	 		System.out.println(\"f4 is not null\");\n" +
10862
				"		if(a == 1) {}\n" +	// warn null reference in deferred check case
10863
				"		if(outer2 == 1) {}\n" +	// warn potential null reference in deferred check case
10864
				"		outer2 = 1;\n" +
10865
				"	 }\n" +
10866
				"  }\n" +
10867
				"}"},
10868
			"----------\n" +
10869
			"1. ERROR in X.java (at line 7)\n" + 
10870
			"	if(f1 == 1)\n" + 
10871
			"	   ^^\n" + 
10872
			"Null pointer access: The variable f1 can only be null at this location\n" + 
10873
			"----------\n" + 
10874
			"2. ERROR in X.java (at line 10)\n" + 
10875
			"	int abc = (f2 != 1)? 1 : 0;\n" + 
10876
			"	           ^^\n" + 
10877
			"Null pointer access: The variable f2 can only be null at this location\n" + 
10878
			"----------\n" + 
10879
			"3. ERROR in X.java (at line 12)\n" + 
10880
			"	if(f3 == null)\n" + 
10881
			"	   ^^\n" + 
10882
			"Redundant null check: The variable f3 can only be null at this location\n" + 
10883
			"----------\n" + 
10884
			"4. ERROR in X.java (at line 15)\n" + 
10885
			"	if(f4 != null)\n" + 
10886
			"	   ^^\n" + 
10887
			"Null comparison always yields false: The variable f4 can only be null at this location\n" + 
10888
			"----------\n" + 
10889
			"5. WARNING in X.java (at line 16)\n" + 
10890
			"	System.out.println(\"f4 is not null\");\n" + 
10891
			"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
10892
			"Dead code\n" + 
10893
			"----------\n" + 
10894
			"6. ERROR in X.java (at line 17)\n" + 
10895
			"	if(a == 1) {}\n" + 
10896
			"	   ^\n" + 
10897
			"Null pointer access: The variable a can only be null at this location\n" + 
10898
			"----------\n" + 
10899
			"7. ERROR in X.java (at line 18)\n" + 
10900
			"	if(outer2 == 1) {}\n" + 
10901
			"	   ^^^^^^\n" + 
10902
			"Potential null pointer access: The variable outer2 may be null at this location\n" + 
10903
			"----------\n");
10904
	}
10905
}
10906
10907
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
10908
// Test whether Null pointer access warnings are being reported correctly when auto-unboxing inside finally contexts
10909
public void testBug253896d() {
10910
	if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
10911
		this.runNegativeTest(
10912
			new String[] {
10913
				"X.java",
10914
				"public class X {\n" +
10915
				"  public void foo(Integer param) {\n" +
10916
				"	 Integer outer = null;\n" +
10917
				"	 if (param == null) {}\n" +	//tainting param
10918
				"	 try {}\n" +
10919
				"	 finally {\n" +
10920
				"    	Integer f1 = null;\n" +
10921
				"	 	if(f1 == 1)\n" +
10922
				" 	 		System.out.println(\"f1 is 1\");\n" +
10923
				"    	Integer f2 = null;\n" +
10924
				"	 	int abc = (f2 != 1)? 1 : 0;\n" +
10925
				"    	Float f3 = null;\n" +
10926
				"	 	if(f3 == null)\n" +
10927
				" 	 		System.out.println(\"f3 is null\");\n" +
10928
				"    	Byte f4 = null;\n" +
10929
				"	 	if(f4 != null)\n" +
10930
				" 	 		System.out.println(\"f4 is not null\");\n" +
10931
				"		if(outer == 1) {}\n" +  // warn null reference in deferred check case
10932
				"		if(param == 1) {}\n" +
10933
				"	 }\n" +
10934
				"  }\n" +
10935
				"}"},
10936
			"----------\n" +
10937
			"1. ERROR in X.java (at line 8)\n" + 
10938
			"	if(f1 == 1)\n" + 
10939
			"	   ^^\n" + 
10940
			"Null pointer access: The variable f1 can only be null at this location\n" + 
10941
			"----------\n" + 
10942
			"2. ERROR in X.java (at line 11)\n" + 
10943
			"	int abc = (f2 != 1)? 1 : 0;\n" + 
10944
			"	           ^^\n" + 
10945
			"Null pointer access: The variable f2 can only be null at this location\n" + 
10946
			"----------\n" + 
10947
			"3. ERROR in X.java (at line 13)\n" + 
10948
			"	if(f3 == null)\n" + 
10949
			"	   ^^\n" + 
10950
			"Redundant null check: The variable f3 can only be null at this location\n" + 
10951
			"----------\n" + 
10952
			"4. ERROR in X.java (at line 16)\n" + 
10953
			"	if(f4 != null)\n" + 
10954
			"	   ^^\n" + 
10955
			"Null comparison always yields false: The variable f4 can only be null at this location\n" + 
10956
			"----------\n" + 
10957
			"5. WARNING in X.java (at line 17)\n" + 
10958
			"	System.out.println(\"f4 is not null\");\n" + 
10959
			"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
10960
			"Dead code\n" + 
10961
			"----------\n" + 
10962
			"6. ERROR in X.java (at line 18)\n" + 
10963
			"	if(outer == 1) {}\n" + 
10964
			"	   ^^^^^\n" + 
10965
			"Null pointer access: The variable outer can only be null at this location\n" + 
10966
			"----------\n" + 
10967
			"7. ERROR in X.java (at line 19)\n" + 
10968
			"	if(param == 1) {}\n" + 
10969
			"	   ^^^^^\n" + 
10970
			"Potential null pointer access: The variable param may be null at this location\n" + 
10971
			"----------\n");
10972
	}
10973
}
10756
}
10974
}

Return to bug 253896