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 114-124 Link Here
114
					if (flowInfo.isDefinitelyNull(local)) {
115
					if (flowInfo.isDefinitelyNull(local)) {
115
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
116
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
116
							case FlowContext.IN_COMPARISON_NULL:
117
							case FlowContext.IN_COMPARISON_NULL:
118
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
119
									scope.problemReporter().localVariableNullReference(local, expression);
120
									continue;
121
								}
117
								if (!this.hideNullComparisonWarnings) {
122
								if (!this.hideNullComparisonWarnings) {
118
									scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
123
									scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
119
								}
124
								}
120
								continue;
125
								continue;
121
							case FlowContext.IN_COMPARISON_NON_NULL:
126
							case FlowContext.IN_COMPARISON_NON_NULL:
127
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
128
									scope.problemReporter().localVariableNullReference(local, expression);
129
									continue;
130
								}
122
								if (!this.hideNullComparisonWarnings) {
131
								if (!this.hideNullComparisonWarnings) {
123
									scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
132
									scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
124
								}
133
								}
Lines 130-135 Link Here
130
								scope.problemReporter().localVariableNullInstanceof(local, expression);
139
								scope.problemReporter().localVariableNullInstanceof(local, expression);
131
								continue;
140
								continue;
132
						}
141
						}
142
					} else if (flowInfo.isPotentiallyNull(local)) {
143
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
144
							case FlowContext.IN_COMPARISON_NULL:
145
								this.nullReferences[i] = null;
146
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
147
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
148
									continue;
149
								}
150
								break;
151
							case FlowContext.IN_COMPARISON_NON_NULL:
152
								this.nullReferences[i] = null;
153
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
154
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
155
									continue;
156
								}
157
								break;
158
						}
133
					}
159
					}
134
					break;
160
					break;
135
				case MAY_NULL:
161
				case MAY_NULL:
Lines 214-225 Link Here
214
						if (flowInfo.canOnlyBeNull(local)) {
240
						if (flowInfo.canOnlyBeNull(local)) {
215
							switch(checkType & CONTEXT_MASK) {
241
							switch(checkType & CONTEXT_MASK) {
216
								case FlowContext.IN_COMPARISON_NULL:
242
								case FlowContext.IN_COMPARISON_NULL:
243
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
244
										scope.problemReporter().localVariableNullReference(local, reference);
245
										return;
246
									}
217
									if (!this.hideNullComparisonWarnings) {
247
									if (!this.hideNullComparisonWarnings) {
218
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
248
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
219
									}
249
									}
220
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
250
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
221
									return;
251
									return;
222
								case FlowContext.IN_COMPARISON_NON_NULL:
252
								case FlowContext.IN_COMPARISON_NON_NULL:
253
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
254
										scope.problemReporter().localVariableNullReference(local, reference);
255
										return;
256
									}
223
									if (!this.hideNullComparisonWarnings) {
257
									if (!this.hideNullComparisonWarnings) {
224
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
258
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
225
									}
259
									}
Lines 232-237 Link Here
232
									scope.problemReporter().localVariableNullInstanceof(local, reference);
266
									scope.problemReporter().localVariableNullInstanceof(local, reference);
233
									return;
267
									return;
234
							}
268
							}
269
						} else if (flowInfo.isPotentiallyNull(local)) {
270
							switch(checkType & CONTEXT_MASK) {
271
								case FlowContext.IN_COMPARISON_NULL:
272
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
273
										scope.problemReporter().localVariablePotentialNullReference(local, reference);
274
										return;
275
									}
276
									break;
277
								case FlowContext.IN_COMPARISON_NON_NULL:
278
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
279
										scope.problemReporter().localVariablePotentialNullReference(local, reference);
280
										return;
281
									}
282
									break;
283
							}
235
						}
284
						}
236
						break;
285
						break;
237
					case MAY_NULL :
286
					case MAY_NULL :
Lines 273-284 Link Here
273
						if (flowInfo.isDefinitelyNull(local)) {
322
						if (flowInfo.isDefinitelyNull(local)) {
274
							switch(checkType & CONTEXT_MASK) {
323
							switch(checkType & CONTEXT_MASK) {
275
								case FlowContext.IN_COMPARISON_NULL:
324
								case FlowContext.IN_COMPARISON_NULL:
325
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
326
										scope.problemReporter().localVariableNullReference(local, reference);
327
										return;
328
									}
276
									if (!this.hideNullComparisonWarnings) {
329
									if (!this.hideNullComparisonWarnings) {
277
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
330
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
278
									}
331
									}
279
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
332
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
280
									return;
333
									return;
281
								case FlowContext.IN_COMPARISON_NON_NULL:
334
								case FlowContext.IN_COMPARISON_NON_NULL:
335
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
336
										scope.problemReporter().localVariableNullReference(local, reference);
337
										return;
338
									}
282
									if (!this.hideNullComparisonWarnings) {
339
									if (!this.hideNullComparisonWarnings) {
283
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
340
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
284
									}
341
									}
Lines 291-296 Link Here
291
									scope.problemReporter().localVariableNullInstanceof(local, reference);
348
									scope.problemReporter().localVariableNullInstanceof(local, reference);
292
									return;
349
									return;
293
							}
350
							}
351
						} else if (flowInfo.isPotentiallyNull(local)) {
352
							switch(checkType & CONTEXT_MASK) {
353
								case FlowContext.IN_COMPARISON_NULL:
354
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
355
										scope.problemReporter().localVariablePotentialNullReference(local, reference);
356
										return;
357
									}
358
									break;
359
								case FlowContext.IN_COMPARISON_NON_NULL:
360
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
361
										scope.problemReporter().localVariablePotentialNullReference(local, reference);
362
										return;
363
									}
364
									break;
365
							}
294
						}
366
						}
295
						break;
367
						break;
296
					case MAY_NULL :
368
					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 569-580 Link Here
569
			if (flowInfo.isDefinitelyNull(local)) {
570
			if (flowInfo.isDefinitelyNull(local)) {
570
				switch(checkType & CONTEXT_MASK) {
571
				switch(checkType & CONTEXT_MASK) {
571
					case FlowContext.IN_COMPARISON_NULL:
572
					case FlowContext.IN_COMPARISON_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
						}
572
						if (!this.hideNullComparisonWarnings) {
577
						if (!this.hideNullComparisonWarnings) {
573
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
578
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
574
						}
579
						}
575
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
580
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
576
						return;
581
						return;
577
					case FlowContext.IN_COMPARISON_NON_NULL:
582
					case FlowContext.IN_COMPARISON_NON_NULL:
583
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
584
							scope.problemReporter().localVariableNullReference(local, reference);
585
							return;
586
						}
578
						if (!this.hideNullComparisonWarnings) {
587
						if (!this.hideNullComparisonWarnings) {
579
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
588
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
580
						}
589
						}
Lines 587-592 Link Here
587
						scope.problemReporter().localVariableNullInstanceof(local, reference);
596
						scope.problemReporter().localVariableNullInstanceof(local, reference);
588
						return;
597
						return;
589
				}
598
				}
599
			} else if (flowInfo.isPotentiallyNull(local)) {
600
				switch(checkType & CONTEXT_MASK) {
601
					case FlowContext.IN_COMPARISON_NULL:
602
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
603
							scope.problemReporter().localVariablePotentialNullReference(local, reference);
604
							return;
605
						}
606
						break;
607
					case FlowContext.IN_COMPARISON_NON_NULL:
608
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
609
							scope.problemReporter().localVariablePotentialNullReference(local, reference);
610
							return;
611
						}
612
						break;
613
				}
590
			} else if (flowInfo.cannotBeDefinitelyNullOrNonNull(local)) {
614
			} else if (flowInfo.cannotBeDefinitelyNullOrNonNull(local)) {
591
				return;
615
				return;
592
			}
616
			}
(-)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 175-185 Link Here
175
						this.nullReferences[i] = null;
176
						this.nullReferences[i] = null;
176
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
177
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
177
							case FlowContext.IN_COMPARISON_NULL:
178
							case FlowContext.IN_COMPARISON_NULL:
179
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
180
									scope.problemReporter().localVariableNullReference(local, expression);
181
									continue;
182
								}
178
								if (!this.hideNullComparisonWarnings) {
183
								if (!this.hideNullComparisonWarnings) {
179
									scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
184
									scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
180
								}
185
								}
181
								continue;
186
								continue;
182
							case FlowContext.IN_COMPARISON_NON_NULL:
187
							case FlowContext.IN_COMPARISON_NON_NULL:
188
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
189
									scope.problemReporter().localVariableNullReference(local, expression);
190
									continue;
191
								}
183
								if (!this.hideNullComparisonWarnings) {
192
								if (!this.hideNullComparisonWarnings) {
184
									scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
193
									scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
185
								}
194
								}
Lines 191-197 Link Here
191
								scope.problemReporter().localVariableNullInstanceof(local, expression);
200
								scope.problemReporter().localVariableNullInstanceof(local, expression);
192
								continue;
201
								continue;
193
						}
202
						}
194
					}
203
					} else if (flowInfo.isPotentiallyNull(local)) {
204
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
205
							case FlowContext.IN_COMPARISON_NULL:
206
								this.nullReferences[i] = null;
207
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
208
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
209
									continue;
210
								}
211
								break;
212
							case FlowContext.IN_COMPARISON_NON_NULL:
213
								this.nullReferences[i] = null;
214
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
215
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
216
									continue;
217
								}
218
								break;
219
						}
220
					}	
195
					break;
221
					break;
196
				case MAY_NULL:
222
				case MAY_NULL:
197
					if (flowInfo.isDefinitelyNull(local)) {
223
					if (flowInfo.isDefinitelyNull(local)) {
Lines 238-248 Link Here
238
						this.nullReferences[i] = null;
264
						this.nullReferences[i] = null;
239
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
265
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
240
							case FlowContext.IN_COMPARISON_NULL:
266
							case FlowContext.IN_COMPARISON_NULL:
267
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
268
									scope.problemReporter().localVariableNullReference(local, expression);
269
									continue;
270
								}
241
								if (!this.hideNullComparisonWarnings) {
271
								if (!this.hideNullComparisonWarnings) {
242
									scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
272
									scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
243
								}
273
								}
244
								continue;
274
								continue;
245
							case FlowContext.IN_COMPARISON_NON_NULL:
275
							case FlowContext.IN_COMPARISON_NON_NULL:
276
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
277
									scope.problemReporter().localVariableNullReference(local, expression);
278
									continue;
279
								}
246
								if (!this.hideNullComparisonWarnings) {
280
								if (!this.hideNullComparisonWarnings) {
247
									scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
281
									scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
248
								}
282
								}
Lines 254-259 Link Here
254
								scope.problemReporter().localVariableNullInstanceof(local, expression);
288
								scope.problemReporter().localVariableNullInstanceof(local, expression);
255
								continue;
289
								continue;
256
						}
290
						}
291
					} else if (flowInfo.isPotentiallyNull(local)) {
292
						switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
293
							case FlowContext.IN_COMPARISON_NULL:
294
								this.nullReferences[i] = null;
295
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
296
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
297
									continue;
298
								}
299
								break;
300
							case FlowContext.IN_COMPARISON_NON_NULL:
301
								this.nullReferences[i] = null;
302
								if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
303
									scope.problemReporter().localVariablePotentialNullReference(local, expression);
304
									continue;
305
								}
306
								break;
307
						}
257
					}
308
					}
258
					break;
309
					break;
259
				case MAY_NULL:
310
				case MAY_NULL:
Lines 467-478 Link Here
467
			if (flowInfo.isDefinitelyNull(local)) {
518
			if (flowInfo.isDefinitelyNull(local)) {
468
				switch(checkType & CONTEXT_MASK) {
519
				switch(checkType & CONTEXT_MASK) {
469
					case FlowContext.IN_COMPARISON_NULL:
520
					case FlowContext.IN_COMPARISON_NULL:
521
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
522
							scope.problemReporter().localVariableNullReference(local, reference);
523
							return;
524
						}
470
						if (!this.hideNullComparisonWarnings) {
525
						if (!this.hideNullComparisonWarnings) {
471
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
526
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
472
						}
527
						}
473
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
528
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
474
						return;
529
						return;
475
					case FlowContext.IN_COMPARISON_NON_NULL:
530
					case FlowContext.IN_COMPARISON_NON_NULL:
531
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
532
							scope.problemReporter().localVariableNullReference(local, reference);
533
							return;
534
						}
476
						if (!this.hideNullComparisonWarnings) {
535
						if (!this.hideNullComparisonWarnings) {
477
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
536
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
478
						}
537
						}
Lines 485-490 Link Here
485
						scope.problemReporter().localVariableNullInstanceof(local, reference);
544
						scope.problemReporter().localVariableNullInstanceof(local, reference);
486
						return;
545
						return;
487
				}
546
				}
547
			} else if (flowInfo.isPotentiallyNull(local)) {
548
				switch(checkType & CONTEXT_MASK) {
549
					case FlowContext.IN_COMPARISON_NULL:
550
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
551
							scope.problemReporter().localVariablePotentialNullReference(local, reference);
552
							return;
553
						}
554
						break;
555
					case FlowContext.IN_COMPARISON_NON_NULL:
556
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
557
							scope.problemReporter().localVariablePotentialNullReference(local, reference);
558
							return;
559
						}
560
						break;
561
				}
488
			}
562
			}
489
			// if the contention is inside assert statement, we want to avoid null warnings only in case of
563
			// if the contention is inside assert statement, we want to avoid null warnings only in case of
490
			// comparisons and not in case of assignment and instanceof
564
			// comparisons and not in case of assignment and instanceof
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+218 lines)
Lines 11031-11034 Link Here
11031
		"Potential null pointer access: The variable bar may be null at this location\n" + 
11031
		"Potential null pointer access: The variable bar may be null at this location\n" + 
11032
		"----------\n");
11032
		"----------\n");
11033
}
11033
}
11034
11035
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
11036
// Test whether Null pointer access warnings are being reported correctly when auto-unboxing
11037
public void testBug253896a() {
11038
	if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
11039
		this.runNegativeTest(
11040
			new String[] {
11041
				"X.java",
11042
				"public class X {\n" +
11043
				"  public void foo() {\n" +
11044
				"    Integer f1 = null;\n" +
11045
				"	 if(f1 == 1)\n" +
11046
				" 	 	System.out.println(\"f1 is 1\");\n" +
11047
				"    Integer f2 = null;\n" +
11048
				"	 int abc = (f2 != 1)? 1 : 0;\n" +
11049
				"    Float f3 = null;\n" +
11050
				"	 if(f3 == null)\n" +
11051
				" 	 	System.out.println(\"f3 is null\");\n" +
11052
				"    Byte f4 = null;\n" +
11053
				"	 if(f4 != null)\n" +
11054
				" 	 	System.out.println(\"f4 is not null\");\n" +
11055
				"  }\n" +
11056
				"}"},
11057
			"----------\n" +
11058
			"1. ERROR in X.java (at line 4)\n" + 
11059
			"	if(f1 == 1)\n" + 
11060
			"	   ^^\n" + 
11061
			"Null pointer access: The variable f1 can only be null at this location\n" + 
11062
			"----------\n" + 
11063
			"2. ERROR in X.java (at line 7)\n" + 
11064
			"	int abc = (f2 != 1)? 1 : 0;\n" + 
11065
			"	           ^^\n" + 
11066
			"Null pointer access: The variable f2 can only be null at this location\n" + 
11067
			"----------\n" + 
11068
			"3. ERROR in X.java (at line 9)\n" + 
11069
			"	if(f3 == null)\n" + 
11070
			"	   ^^\n" + 
11071
			"Redundant null check: The variable f3 can only be null at this location\n" + 
11072
			"----------\n" + 
11073
			"4. ERROR in X.java (at line 12)\n" + 
11074
			"	if(f4 != null)\n" + 
11075
			"	   ^^\n" + 
11076
			"Null comparison always yields false: The variable f4 can only be null at this location\n" + 
11077
			"----------\n" + 
11078
			"5. WARNING in X.java (at line 13)\n" + 
11079
			"	System.out.println(\"f4 is not null\");\n" + 
11080
			"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11081
			"Dead code\n" + 
11082
			"----------\n");
11083
	}
11084
}
11085
11086
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
11087
// To test whether null pointer access and potential null pointer access warnings are correctly reported when auto-unboxing
11088
public void testBug253896b() {
11089
	if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
11090
		this.runNegativeTest(
11091
			new String[] {
11092
				"X.java",
11093
				"public class X {\n" +
11094
				"  public void foo(Integer i1, Integer i2) {\n" +
11095
				"	 if(i1 == null && i2 == null){\n" +
11096
				"		if(i1 == 1)\n" +
11097
				" 	 	System.out.println(i1);}\n" +	//i1 is definitely null here
11098
				"	 else {\n" +
11099
				"		if(i1 == 0) {}\n" +		//i1 may be null here.
11100
				"	 }\n" +
11101
				"  }\n" +
11102
				"}"},
11103
			"----------\n" +
11104
			"1. ERROR in X.java (at line 4)\n" +
11105
			"	if(i1 == 1)\n" +
11106
			"	   ^^\n" +
11107
			"Null pointer access: The variable i1 can only be null at this location\n" +
11108
			"----------\n" +
11109
			"2. ERROR in X.java (at line 7)\n" +
11110
			"	if(i1 == 0) {}\n" +
11111
			"	   ^^\n" +
11112
			"Potential null pointer access: The variable i1 may be null at this location\n" +
11113
			"----------\n");
11114
	}
11115
}
11116
11117
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
11118
// Test whether Null pointer access warnings are being reported correctly when auto-unboxing inside loops
11119
public void testBug253896c() {
11120
	if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
11121
		this.runNegativeTest(
11122
			new String[] {
11123
				"X.java",
11124
				"public class X {\n" +
11125
				"  public void foo() {\n" +
11126
				"	 Integer a = null;\n" +
11127
				"	 Integer outer2 = null;\n" +
11128
				"	 while (true) {\n" +
11129
				"    	Integer f1 = null;\n" +
11130
				"	 	if(f1 == 1)\n" +
11131
				" 	 		System.out.println(\"f1 is 1\");\n" +
11132
				"    	Integer f2 = null;\n" +
11133
				"	 	int abc = (f2 != 1)? 1 : 0;\n" +
11134
				"    	Float f3 = null;\n" +
11135
				"	 	if(f3 == null)\n" +
11136
				" 	 		System.out.println(\"f3 is null\");\n" +
11137
				"    	Byte f4 = null;\n" +
11138
				"	 	if(f4 != null)\n" +
11139
				" 	 		System.out.println(\"f4 is not null\");\n" +
11140
				"		if(a == 1) {}\n" +	// warn null reference in deferred check case
11141
				"		if(outer2 == 1) {}\n" +	// warn potential null reference in deferred check case
11142
				"		outer2 = 1;\n" +
11143
				"	 }\n" +
11144
				"  }\n" +
11145
				"}"},
11146
			"----------\n" +
11147
			"1. ERROR in X.java (at line 7)\n" + 
11148
			"	if(f1 == 1)\n" + 
11149
			"	   ^^\n" + 
11150
			"Null pointer access: The variable f1 can only be null at this location\n" + 
11151
			"----------\n" + 
11152
			"2. ERROR in X.java (at line 10)\n" + 
11153
			"	int abc = (f2 != 1)? 1 : 0;\n" + 
11154
			"	           ^^\n" + 
11155
			"Null pointer access: The variable f2 can only be null at this location\n" + 
11156
			"----------\n" + 
11157
			"3. ERROR in X.java (at line 12)\n" + 
11158
			"	if(f3 == null)\n" + 
11159
			"	   ^^\n" + 
11160
			"Redundant null check: The variable f3 can only be null at this location\n" + 
11161
			"----------\n" + 
11162
			"4. ERROR in X.java (at line 15)\n" + 
11163
			"	if(f4 != null)\n" + 
11164
			"	   ^^\n" + 
11165
			"Null comparison always yields false: The variable f4 can only be null at this location\n" + 
11166
			"----------\n" + 
11167
			"5. WARNING in X.java (at line 16)\n" + 
11168
			"	System.out.println(\"f4 is not null\");\n" + 
11169
			"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11170
			"Dead code\n" + 
11171
			"----------\n" + 
11172
			"6. ERROR in X.java (at line 17)\n" + 
11173
			"	if(a == 1) {}\n" + 
11174
			"	   ^\n" + 
11175
			"Null pointer access: The variable a can only be null at this location\n" + 
11176
			"----------\n" + 
11177
			"7. ERROR in X.java (at line 18)\n" + 
11178
			"	if(outer2 == 1) {}\n" + 
11179
			"	   ^^^^^^\n" + 
11180
			"Potential null pointer access: The variable outer2 may be null at this location\n" + 
11181
			"----------\n");
11182
	}
11183
}
11184
11185
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
11186
// Test whether Null pointer access warnings are being reported correctly when auto-unboxing inside finally contexts
11187
public void testBug253896d() {
11188
	if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
11189
		this.runNegativeTest(
11190
			new String[] {
11191
				"X.java",
11192
				"public class X {\n" +
11193
				"  public void foo(Integer param) {\n" +
11194
				"	 Integer outer = null;\n" +
11195
				"	 if (param == null) {}\n" +	//tainting param
11196
				"	 try {}\n" +
11197
				"	 finally {\n" +
11198
				"    	Integer f1 = null;\n" +
11199
				"	 	if(f1 == 1)\n" +
11200
				" 	 		System.out.println(\"f1 is 1\");\n" +
11201
				"    	Integer f2 = null;\n" +
11202
				"	 	int abc = (f2 != 1)? 1 : 0;\n" +
11203
				"    	Float f3 = null;\n" +
11204
				"	 	if(f3 == null)\n" +
11205
				" 	 		System.out.println(\"f3 is null\");\n" +
11206
				"    	Byte f4 = null;\n" +
11207
				"	 	if(f4 != null)\n" +
11208
				" 	 		System.out.println(\"f4 is not null\");\n" +
11209
				"		if(outer == 1) {}\n" +  // warn null reference in deferred check case
11210
				"		if(param == 1) {}\n" +
11211
				"	 }\n" +
11212
				"  }\n" +
11213
				"}"},
11214
			"----------\n" +
11215
			"1. ERROR in X.java (at line 8)\n" + 
11216
			"	if(f1 == 1)\n" + 
11217
			"	   ^^\n" + 
11218
			"Null pointer access: The variable f1 can only be null at this location\n" + 
11219
			"----------\n" + 
11220
			"2. ERROR in X.java (at line 11)\n" + 
11221
			"	int abc = (f2 != 1)? 1 : 0;\n" + 
11222
			"	           ^^\n" + 
11223
			"Null pointer access: The variable f2 can only be null at this location\n" + 
11224
			"----------\n" + 
11225
			"3. ERROR in X.java (at line 13)\n" + 
11226
			"	if(f3 == null)\n" + 
11227
			"	   ^^\n" + 
11228
			"Redundant null check: The variable f3 can only be null at this location\n" + 
11229
			"----------\n" + 
11230
			"4. ERROR in X.java (at line 16)\n" + 
11231
			"	if(f4 != null)\n" + 
11232
			"	   ^^\n" + 
11233
			"Null comparison always yields false: The variable f4 can only be null at this location\n" + 
11234
			"----------\n" + 
11235
			"5. WARNING in X.java (at line 17)\n" + 
11236
			"	System.out.println(\"f4 is not null\");\n" + 
11237
			"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11238
			"Dead code\n" + 
11239
			"----------\n" + 
11240
			"6. ERROR in X.java (at line 18)\n" + 
11241
			"	if(outer == 1) {}\n" + 
11242
			"	   ^^^^^\n" + 
11243
			"Null pointer access: The variable outer can only be null at this location\n" + 
11244
			"----------\n" + 
11245
			"7. ERROR in X.java (at line 19)\n" + 
11246
			"	if(param == 1) {}\n" + 
11247
			"	   ^^^^^\n" + 
11248
			"Potential null pointer access: The variable param may be null at this location\n" + 
11249
			"----------\n");
11250
	}
11251
}
11034
}
11252
}

Return to bug 253896