View | Details | Raw Unified | Return to bug 303448
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java (+3 lines)
Lines 47-52 Link Here
47
					initsWhenTrue.markAsComparedEqualToNonNull(local); // from thereon it is set
47
					initsWhenTrue.markAsComparedEqualToNonNull(local); // from thereon it is set
48
					initsWhenFalse.markAsComparedEqualToNull(local); // from thereon it is set
48
					initsWhenFalse.markAsComparedEqualToNull(local); // from thereon it is set
49
				}
49
				}
50
				if (flowContext.hideNullComparisonWarnings) {
51
					flowInfo.markedAsNullOrNonNullInAssertExpression(local);
52
				}
50
				break;
53
				break;
51
			case FlowInfo.NON_NULL :
54
			case FlowInfo.NON_NULL :
52
				if (((this.bits & OperatorMASK) >> OperatorSHIFT) == EQUAL_EQUAL) {
55
				if (((this.bits & OperatorMASK) >> OperatorSHIFT) == EQUAL_EQUAL) {
(-)compiler/org/eclipse/jdt/internal/compiler/flow/ConditionalFlowInfo.java (-1 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 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 214-217 Link Here
214
	return this.initsWhenTrue.unconditionalCopy().
214
	return this.initsWhenTrue.unconditionalCopy().
215
			mergedWith(this.initsWhenFalse.unconditionalInits());
215
			mergedWith(this.initsWhenFalse.unconditionalInits());
216
}
216
}
217
218
public void markedAsNullOrNonNullInAssertExpression(LocalVariableBinding local) {
219
	this.initsWhenTrue.markedAsNullOrNonNullInAssertExpression(local);
220
	this.initsWhenFalse.markedAsNullOrNonNullInAssertExpression(local);
221
}
222
223
public boolean isMarkedAsNullOrNonNullInAssertExpression(LocalVariableBinding local) {
224
	return (this.initsWhenTrue.isMarkedAsNullOrNonNullInAssertExpression(local)
225
		|| this.initsWhenFalse.isMarkedAsNullOrNonNullInAssertExpression(local));
226
}
217
}
227
}
(-)compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java (-8 / +24 lines)
Lines 228-239 Link Here
228
								if (!this.hideNullComparisonWarnings) {
228
								if (!this.hideNullComparisonWarnings) {
229
									scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
229
									scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
230
								}
230
								}
231
								flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
231
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
232
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
233
								}
232
							} else if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) {
234
							} else if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) {
233
								if (!this.hideNullComparisonWarnings) {
235
								if (!this.hideNullComparisonWarnings) {
234
									scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
236
									scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
235
								}
237
								}
236
								flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
238
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
239
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
240
								}
237
							}
241
							}
238
							return;
242
							return;
239
						}
243
						}
Lines 247-253 Link Here
247
									if (!this.hideNullComparisonWarnings) {
251
									if (!this.hideNullComparisonWarnings) {
248
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
252
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
249
									}
253
									}
250
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
254
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
255
										flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
256
									}
251
									return;
257
									return;
252
								case FlowContext.IN_COMPARISON_NON_NULL:
258
								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
259
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
Lines 257-263 Link Here
257
									if (!this.hideNullComparisonWarnings) {
263
									if (!this.hideNullComparisonWarnings) {
258
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
264
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
259
									}
265
									}
260
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
266
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
267
										flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
268
									}
261
									return;
269
									return;
262
								case FlowContext.IN_ASSIGNMENT:
270
								case FlowContext.IN_ASSIGNMENT:
263
									scope.problemReporter().localVariableRedundantNullAssignment(local, reference);
271
									scope.problemReporter().localVariableRedundantNullAssignment(local, reference);
Lines 305-316 Link Here
305
								if (!this.hideNullComparisonWarnings) {
313
								if (!this.hideNullComparisonWarnings) {
306
									scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
314
									scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
307
								}
315
								}
308
								flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
316
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
317
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
318
								}
309
							} else {
319
							} else {
310
								if (!this.hideNullComparisonWarnings) {
320
								if (!this.hideNullComparisonWarnings) {
311
									scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
321
									scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
312
								}
322
								}
313
								flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);	
323
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
324
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
325
								}
314
							}
326
							}
315
							return;
327
							return;
316
						}
328
						}
Lines 329-335 Link Here
329
									if (!this.hideNullComparisonWarnings) {
341
									if (!this.hideNullComparisonWarnings) {
330
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
342
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
331
									}
343
									}
332
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
344
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
345
										flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
346
									}
333
									return;
347
									return;
334
								case FlowContext.IN_COMPARISON_NON_NULL:
348
								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
349
									if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
Lines 339-345 Link Here
339
									if (!this.hideNullComparisonWarnings) {
353
									if (!this.hideNullComparisonWarnings) {
340
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
354
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
341
									}
355
									}
342
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
356
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
357
										flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
358
									}
343
									return;
359
									return;
344
								case FlowContext.IN_ASSIGNMENT:
360
								case FlowContext.IN_ASSIGNMENT:
345
									scope.problemReporter().localVariableRedundantNullAssignment(local, reference);
361
									scope.problemReporter().localVariableRedundantNullAssignment(local, reference);
(-)compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java (-4 / +12 lines)
Lines 550-561 Link Here
550
					if (!this.hideNullComparisonWarnings) {
550
					if (!this.hideNullComparisonWarnings) {
551
						scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
551
						scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
552
					}
552
					}
553
					flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
553
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
554
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
555
					}
554
				} else {
556
				} else {
555
					if (!this.hideNullComparisonWarnings) {
557
					if (!this.hideNullComparisonWarnings) {
556
						scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
558
						scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
557
					}
559
					}
558
					flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
560
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
561
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
562
					}
559
				}
563
				}
560
				return;
564
				return;
561
			}
565
			}
Lines 577-583 Link Here
577
						if (!this.hideNullComparisonWarnings) {
581
						if (!this.hideNullComparisonWarnings) {
578
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
582
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
579
						}
583
						}
580
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
584
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
585
							flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
586
						}
581
						return;
587
						return;
582
					case FlowContext.IN_COMPARISON_NON_NULL:
588
					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
589
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
Lines 587-593 Link Here
587
						if (!this.hideNullComparisonWarnings) {
593
						if (!this.hideNullComparisonWarnings) {
588
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
594
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
589
						}
595
						}
590
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
596
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
597
							flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
598
						}
591
						return;
599
						return;
592
					case FlowContext.IN_ASSIGNMENT:
600
					case FlowContext.IN_ASSIGNMENT:
593
						scope.problemReporter().localVariableRedundantNullAssignment(local, reference);
601
						scope.problemReporter().localVariableRedundantNullAssignment(local, reference);
(-)compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java (+16 lines)
Lines 457-460 Link Here
457
 * @return a flow info carrying this unconditional flow info
457
 * @return a flow info carrying this unconditional flow info
458
 */
458
 */
459
abstract public UnconditionalFlowInfo unconditionalInitsWithoutSideEffect();
459
abstract public UnconditionalFlowInfo unconditionalInitsWithoutSideEffect();
460
461
/**
462
 * Tell the flowInfo that a local variable got marked as non null or null
463
 * due to comparison with null inside an assert expression.
464
 * This is to prevent over-aggressive code generation for subsequent if statements
465
 * where this variable is being checked against null
466
 */
467
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448
468
abstract public void markedAsNullOrNonNullInAssertExpression(LocalVariableBinding local);
469
470
/** 
471
 * Returns true if the local variable being checked for was marked as null or not null
472
 * inside an assert expression due to comparison against null.
473
 */
474
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448
475
abstract public boolean isMarkedAsNullOrNonNullInAssertExpression(LocalVariableBinding local);
460
}
476
}
(-)compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java (-6 / +18 lines)
Lines 473-496 Link Here
473
					if (!this.hideNullComparisonWarnings) {
473
					if (!this.hideNullComparisonWarnings) {
474
						scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
474
						scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
475
					}
475
					}
476
					flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
476
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
477
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
478
					}
477
				} else {
479
				} else {
478
					if (!this.hideNullComparisonWarnings) {
480
					if (!this.hideNullComparisonWarnings) {
479
						scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
481
						scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
480
					}
482
					}
481
					flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
483
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
484
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
485
					}
482
				}
486
				}
483
			} else if (flowInfo.isDefinitelyNull(local)) {
487
			} else if (flowInfo.isDefinitelyNull(local)) {
484
				if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) {
488
				if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) {
485
					if (!this.hideNullComparisonWarnings) {
489
					if (!this.hideNullComparisonWarnings) {
486
						scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
490
						scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
487
					}
491
					}
488
					flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
492
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
493
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
494
					}
489
				} else {
495
				} else {
490
					if (!this.hideNullComparisonWarnings) {
496
					if (!this.hideNullComparisonWarnings) {
491
						scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
497
						scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
492
					}
498
					}
493
					flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
499
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
500
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
501
					}
494
				}
502
				}
495
			} else if (this.upstreamNullFlowInfo.isDefinitelyNonNull(local) && !flowInfo.isPotentiallyNull(local)) {    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=291418
503
			} else if (this.upstreamNullFlowInfo.isDefinitelyNonNull(local) && !flowInfo.isPotentiallyNull(local)) {    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=291418
496
				flowInfo.markAsDefinitelyNonNull(local);
504
				flowInfo.markAsDefinitelyNonNull(local);
Lines 525-531 Link Here
525
						if (!this.hideNullComparisonWarnings) {
533
						if (!this.hideNullComparisonWarnings) {
526
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
534
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
527
						}
535
						}
528
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
536
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
537
							flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
538
						}
529
						return;
539
						return;
530
					case FlowContext.IN_COMPARISON_NON_NULL:
540
					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
541
						if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
Lines 535-541 Link Here
535
						if (!this.hideNullComparisonWarnings) {
545
						if (!this.hideNullComparisonWarnings) {
536
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
546
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
537
						}
547
						}
538
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
548
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
549
							flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
550
						}
539
						return;
551
						return;
540
					case FlowContext.IN_ASSIGNMENT:
552
					case FlowContext.IN_ASSIGNMENT:
541
						scope.problemReporter().localVariableRedundantNullAssignment(local, reference);
553
						scope.problemReporter().localVariableRedundantNullAssignment(local, reference);
(-)compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java (-1 / +62 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 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 84-89 Link Here
84
84
85
	// Constants
85
	// Constants
86
	public static final int BitCacheSize = 64; // 64 bits in a long.
86
	public static final int BitCacheSize = 64; // 64 bits in a long.
87
	public int nullStatusChangedInAssert[];		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448
87
88
88
public FlowInfo addInitializationsFrom(FlowInfo inits) {
89
public FlowInfo addInitializationsFrom(FlowInfo inits) {
89
	if (this == DEAD_END)
90
	if (this == DEAD_END)
Lines 283-288 Link Here
283
			}
284
			}
284
		}
285
		}
285
	}
286
	}
287
	combineNullStatusChangeInAssertInfo(otherInits);
286
	return this;
288
	return this;
287
}
289
}
288
290
Lines 490-495 Link Here
490
			}
492
			}
491
		}
493
		}
492
	}
494
	}
495
	combineNullStatusChangeInAssertInfo(otherInits);
493
	if (thisHasNulls) {
496
	if (thisHasNulls) {
494
		this.tagBits |= NULL_FLAG_MASK;
497
		this.tagBits |= NULL_FLAG_MASK;
495
	}
498
	}
Lines 621-626 Link Here
621
			}
624
			}
622
		}
625
		}
623
	}
626
	}
627
	copy.nullStatusChangedInAssert = this.nullStatusChangedInAssert;
624
	return copy;
628
	return copy;
625
}
629
}
626
630
Lines 1571-1576 Link Here
1571
			}
1575
			}
1572
		}
1576
		}
1573
	}
1577
	}
1578
	combineNullStatusChangeInAssertInfo(otherInits);
1574
	if (thisHasNulls) {
1579
	if (thisHasNulls) {
1575
		this.tagBits |= NULL_FLAG_MASK;
1580
		this.tagBits |= NULL_FLAG_MASK;
1576
	}
1581
	}
Lines 1732-1737 Link Here
1732
		copy.nullBit3 = this.nullBit3 & mask;
1737
		copy.nullBit3 = this.nullBit3 & mask;
1733
		copy.nullBit4 = this.nullBit4 & mask;
1738
		copy.nullBit4 = this.nullBit4 & mask;
1734
	}
1739
	}
1740
	copy.nullStatusChangedInAssert = this.nullStatusChangedInAssert;
1735
	// use extra vector
1741
	// use extra vector
1736
	if (this.extra == null) {
1742
	if (this.extra == null) {
1737
		return copy; // if vector not yet allocated, then not initialized
1743
		return copy; // if vector not yet allocated, then not initialized
Lines 1774-1778 Link Here
1774
public UnconditionalFlowInfo unconditionalInitsWithoutSideEffect() {
1780
public UnconditionalFlowInfo unconditionalInitsWithoutSideEffect() {
1775
	return this;
1781
	return this;
1776
}
1782
}
1783
1784
public void markedAsNullOrNonNullInAssertExpression(LocalVariableBinding local) {
1785
	int position = local.id + this.maxFieldCount;
1786
	int oldLength;
1787
	if (this.nullStatusChangedInAssert == null) {
1788
		this.nullStatusChangedInAssert = new int[position + 1];
1789
	}
1790
	else {
1791
		if(position >= (oldLength = this.nullStatusChangedInAssert.length)) {
1792
			System.arraycopy(this.nullStatusChangedInAssert, 0, (this.nullStatusChangedInAssert = new int[position + 1]), 0, oldLength); 
1793
		}
1794
	}
1795
	this.nullStatusChangedInAssert[position] = 1;
1796
}
1797
1798
public boolean isMarkedAsNullOrNonNullInAssertExpression(LocalVariableBinding local) {
1799
	int position = local.id + this.maxFieldCount;
1800
	if(this.nullStatusChangedInAssert == null || position >= this.nullStatusChangedInAssert.length) {
1801
		return false;
1802
	}
1803
	if(this.nullStatusChangedInAssert[position] == 1) {
1804
		return true;
1805
	}
1806
	return false;
1807
}
1808
1809
/**
1810
 * Combine the null status changes in assert expressions info
1811
 * @param otherInits
1812
 */
1813
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448
1814
private void combineNullStatusChangeInAssertInfo(UnconditionalFlowInfo otherInits) {
1815
	if (this.nullStatusChangedInAssert != null || otherInits.nullStatusChangedInAssert != null) {
1816
		int mergedLength, length;
1817
		if (this.nullStatusChangedInAssert != null) {
1818
			if (otherInits.nullStatusChangedInAssert != null) {
1819
				if(otherInits.nullStatusChangedInAssert.length > this.nullStatusChangedInAssert.length) {
1820
					mergedLength = otherInits.nullStatusChangedInAssert.length;
1821
					length = this.nullStatusChangedInAssert.length;
1822
					System.arraycopy(this.nullStatusChangedInAssert, 0, (this.nullStatusChangedInAssert = new int[mergedLength]), 0, length);
1823
					for(int i = 0; i < length; i ++) {
1824
						this.nullStatusChangedInAssert[i] |= otherInits.nullStatusChangedInAssert[i];
1825
					}
1826
					System.arraycopy(otherInits.nullStatusChangedInAssert, length, this.nullStatusChangedInAssert, length, mergedLength - length);
1827
				} else {
1828
					for(int i = 0; i < otherInits.nullStatusChangedInAssert.length; i ++) {
1829
						this.nullStatusChangedInAssert[i] |= otherInits.nullStatusChangedInAssert[i];
1830
					}
1831
				}
1832
			}
1833
		} else if (otherInits.nullStatusChangedInAssert != null) {
1834
			this.nullStatusChangedInAssert = otherInits.nullStatusChangedInAssert;
1835
		}
1836
	}
1837
}
1777
}
1838
}
1778
1839
(-)Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/ConformTest.java (+778 lines)
Lines 6766-6771 Link Here
6766
		},
6766
		},
6767
		"SUCCESS");
6767
		"SUCCESS");
6768
}
6768
}
6769
6770
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448
6771
// To check that code gen is not optimized for an if statement
6772
// where a local variable's definite nullness or otherwise is known because of
6773
// an earlier assert expression
6774
public void testBug303448a() throws Exception {
6775
	if (this.complianceLevel >= ClassFileConstants.JDK1_4) {
6776
		this.runConformTest(
6777
			new String[] {
6778
				"X.java",
6779
				"public class X {\n" +
6780
				"	public void foo(String[] args, Object foo) {\n" +
6781
				"		assert foo != null;" +
6782
				"		if (foo!= null) {\n" +
6783
				"			System.out.println(\"foo is not null\");\n" +
6784
				"		} else {\n" +
6785
				"			System.out.println(\"foo is null\");\n" +
6786
				"		}\n" +
6787
				"	}\n" +
6788
				"}\n",
6789
			},
6790
			"",
6791
			null,
6792
			true,
6793
			null,
6794
			getCompilerOptions(),
6795
			null); // custom requestor
6796
	
6797
		String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_5 ?
6798
				"  // Method descriptor #49 ([Ljava/lang/String;Ljava/lang/Object;)V\n" + 
6799
				"  // Stack: 2, Locals: 3\n" + 
6800
				"  public void foo(java.lang.String[] args, java.lang.Object foo);\n" + 
6801
				"     0  getstatic X.$assertionsDisabled : boolean [38]\n" + 
6802
				"     3  ifne 18\n" + 
6803
				"     6  aload_2 [foo]\n" + 
6804
				"     7  ifnonnull 18\n" + 
6805
				"    10  new java.lang.AssertionError [50]\n" + 
6806
				"    13  dup\n" + 
6807
				"    14  invokespecial java.lang.AssertionError() [52]\n" + 
6808
				"    17  athrow\n" + 
6809
				"    18  aload_2 [foo]\n" + 
6810
				"    19  ifnull 33\n" + 
6811
				"    22  getstatic java.lang.System.out : java.io.PrintStream [53]\n" + 
6812
				"    25  ldc <String \"foo is not null\"> [59]\n" + 
6813
				"    27  invokevirtual java.io.PrintStream.println(java.lang.String) : void [61]\n" + 
6814
				"    30  goto 41\n" + 
6815
				"    33  getstatic java.lang.System.out : java.io.PrintStream [53]\n" + 
6816
				"    36  ldc <String \"foo is null\"> [66]\n" + 
6817
				"    38  invokevirtual java.io.PrintStream.println(java.lang.String) : void [61]\n" + 
6818
				"    41  return\n" + 
6819
				"      Line numbers:\n" + 
6820
				"        [pc: 0, line: 3]\n" + 
6821
				"        [pc: 22, line: 4]\n" + 
6822
				"        [pc: 33, line: 6]\n" + 
6823
				"        [pc: 41, line: 8]\n" + 
6824
				"      Local variable table:\n" + 
6825
				"        [pc: 0, pc: 42] local: this index: 0 type: X\n" + 
6826
				"        [pc: 0, pc: 42] local: args index: 1 type: java.lang.String[]\n" + 
6827
				"        [pc: 0, pc: 42] local: foo index: 2 type: java.lang.Object\n"
6828
			:	this.complianceLevel < ClassFileConstants.JDK1_6 ?
6829
					"  // Method descriptor #26 ([Ljava/lang/String;Ljava/lang/Object;)V\n" + 
6830
					"  // Stack: 2, Locals: 3\n" + 
6831
					"  public void foo(java.lang.String[] args, java.lang.Object foo);\n" + 
6832
					"     0  getstatic X.$assertionsDisabled : boolean [16]\n" + 
6833
					"     3  ifne 18\n" + 
6834
					"     6  aload_2 [foo]\n" + 
6835
					"     7  ifnonnull 18\n" + 
6836
					"    10  new java.lang.AssertionError [27]\n" + 
6837
					"    13  dup\n" + 
6838
					"    14  invokespecial java.lang.AssertionError() [29]\n" + 
6839
					"    17  athrow\n" + 
6840
					"    18  aload_2 [foo]\n" + 
6841
					"    19  ifnull 33\n" + 
6842
					"    22  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
6843
					"    25  ldc <String \"foo is not null\"> [36]\n" + 
6844
					"    27  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
6845
					"    30  goto 41\n" + 
6846
					"    33  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
6847
					"    36  ldc <String \"foo is null\"> [44]\n" + 
6848
					"    38  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
6849
					"    41  return\n" + 
6850
					"      Line numbers:\n" + 
6851
					"        [pc: 0, line: 3]\n" + 
6852
					"        [pc: 22, line: 4]\n" + 
6853
					"        [pc: 33, line: 6]\n" + 
6854
					"        [pc: 41, line: 8]\n" + 
6855
					"      Local variable table:\n" + 
6856
					"        [pc: 0, pc: 42] local: this index: 0 type: X\n" + 
6857
					"        [pc: 0, pc: 42] local: args index: 1 type: java.lang.String[]\n" + 
6858
					"        [pc: 0, pc: 42] local: foo index: 2 type: java.lang.Object\n"
6859
				:	"  // Method descriptor #27 ([Ljava/lang/String;Ljava/lang/Object;)V\n" + 
6860
					"  // Stack: 2, Locals: 3\n" + 
6861
					"  public void foo(java.lang.String[] args, java.lang.Object foo);\n" + 
6862
					"     0  getstatic X.$assertionsDisabled : boolean [16]\n" + 
6863
					"     3  ifne 18\n" + 
6864
					"     6  aload_2 [foo]\n" + 
6865
					"     7  ifnonnull 18\n" + 
6866
					"    10  new java.lang.AssertionError [28]\n" + 
6867
					"    13  dup\n" + 
6868
					"    14  invokespecial java.lang.AssertionError() [30]\n" + 
6869
					"    17  athrow\n" + 
6870
					"    18  aload_2 [foo]\n" + 
6871
					"    19  ifnull 33\n" + 
6872
					"    22  getstatic java.lang.System.out : java.io.PrintStream [31]\n" + 
6873
					"    25  ldc <String \"foo is not null\"> [37]\n" + 
6874
					"    27  invokevirtual java.io.PrintStream.println(java.lang.String) : void [39]\n" + 
6875
					"    30  goto 41\n" + 
6876
					"    33  getstatic java.lang.System.out : java.io.PrintStream [31]\n" + 
6877
					"    36  ldc <String \"foo is null\"> [45]\n" + 
6878
					"    38  invokevirtual java.io.PrintStream.println(java.lang.String) : void [39]\n" + 
6879
					"    41  return\n" + 
6880
					"      Line numbers:\n" + 
6881
					"        [pc: 0, line: 3]\n" + 
6882
					"        [pc: 22, line: 4]\n" + 
6883
					"        [pc: 33, line: 6]\n" + 
6884
					"        [pc: 41, line: 8]\n" + 
6885
					"      Local variable table:\n" + 
6886
					"        [pc: 0, pc: 42] local: this index: 0 type: X\n" + 
6887
					"        [pc: 0, pc: 42] local: args index: 1 type: java.lang.String[]\n" + 
6888
					"        [pc: 0, pc: 42] local: foo index: 2 type: java.lang.Object\n" + 
6889
					"      Stack map table: number of frames 3\n" + 
6890
					"        [pc: 18, same]\n" + 
6891
					"        [pc: 33, same]\n" + 
6892
					"        [pc: 41, same]\n" ;
6893
		
6894
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
6895
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
6896
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
6897
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
6898
		int index = result.indexOf(expectedOutput);
6899
		if (index == -1 || expectedOutput.length() == 0) {
6900
			System.out.println(Util.displayString(result, 3));
6901
		}
6902
		if (index == -1) {
6903
			assertEquals("Wrong contents", expectedOutput, result);
6904
		}
6905
	}
6906
}
6907
6908
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448
6909
// To check that code gen is not optimized for an if statement
6910
// where a local variable's definite nullness or otherwise is known because of
6911
// an earlier assert expression
6912
public void testBug303448b() throws Exception {
6913
	if (this.complianceLevel >= ClassFileConstants.JDK1_4) {
6914
		this.runConformTest(
6915
			new String[] {
6916
				"X.java",
6917
				"public class X {\n" +
6918
				"	public void foo() {\n" +
6919
				"		Object foo = null;\n" +
6920
				"		Object foo2 = null;\n" +
6921
				"		assert (foo != null && foo2 != null);\n" +
6922
				"		if (foo != null) {\n" +
6923
				"			System.out.println(\"foo is not null\");\n" +
6924
				"		} else {\n" +
6925
				"			System.out.println(\"foo is null\");\n" +
6926
				"		}\n" +
6927
				"		if (foo2 != null) {\n" +
6928
				"			System.out.println(\"foo2 is not null\");\n" +
6929
				"		} else {\n" +
6930
				"			System.out.println(\"foo2 is null\");\n" +
6931
				"		}\n" +
6932
				"	}\n" +
6933
				"}\n",
6934
			},
6935
			"",
6936
			null,
6937
			true,
6938
			null,
6939
			getCompilerOptions(),
6940
			null); // custom requestor
6941
	
6942
		String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_5?
6943
				"  // Method descriptor #11 ()V\n" + 
6944
				"  // Stack: 2, Locals: 3\n" + 
6945
				"  public void foo();\n" + 
6946
				"     0  aconst_null\n" + 
6947
				"     1  astore_1 [foo]\n" + 
6948
				"     2  aconst_null\n" + 
6949
				"     3  astore_2 [foo2]\n" + 
6950
				"     4  getstatic X.$assertionsDisabled : boolean [38]\n" + 
6951
				"     7  ifne 26\n" + 
6952
				"    10  aload_1 [foo]\n" + 
6953
				"    11  ifnull 18\n" + 
6954
				"    14  aload_2 [foo2]\n" + 
6955
				"    15  ifnonnull 26\n" + 
6956
				"    18  new java.lang.AssertionError [49]\n" + 
6957
				"    21  dup\n" + 
6958
				"    22  invokespecial java.lang.AssertionError() [51]\n" + 
6959
				"    25  athrow\n" + 
6960
				"    26  aload_1 [foo]\n" + 
6961
				"    27  ifnull 41\n" + 
6962
				"    30  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
6963
				"    33  ldc <String \"foo is not null\"> [58]\n" + 
6964
				"    35  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
6965
				"    38  goto 49\n" + 
6966
				"    41  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
6967
				"    44  ldc <String \"foo is null\"> [65]\n" + 
6968
				"    46  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
6969
				"    49  aload_2 [foo2]\n" + 
6970
				"    50  ifnull 64\n" + 
6971
				"    53  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
6972
				"    56  ldc <String \"foo2 is not null\"> [67]\n" + 
6973
				"    58  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
6974
				"    61  goto 72\n" + 
6975
				"    64  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
6976
				"    67  ldc <String \"foo2 is null\"> [69]\n" + 
6977
				"    69  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
6978
				"    72  return\n" + 
6979
				"      Line numbers:\n" + 
6980
				"        [pc: 0, line: 3]\n" + 
6981
				"        [pc: 2, line: 4]\n" + 
6982
				"        [pc: 4, line: 5]\n" + 
6983
				"        [pc: 26, line: 6]\n" + 
6984
				"        [pc: 30, line: 7]\n" + 
6985
				"        [pc: 41, line: 9]\n" + 
6986
				"        [pc: 49, line: 11]\n" + 
6987
				"        [pc: 53, line: 12]\n" + 
6988
				"        [pc: 64, line: 14]\n" + 
6989
				"        [pc: 72, line: 16]\n" + 
6990
				"      Local variable table:\n" + 
6991
				"        [pc: 0, pc: 73] local: this index: 0 type: X\n" + 
6992
				"        [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + 
6993
				"        [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n"
6994
			: 	this.complianceLevel < ClassFileConstants.JDK1_6?
6995
						"  // Method descriptor #8 ()V\n" + 
6996
						"  // Stack: 2, Locals: 3\n" + 
6997
						"  public void foo();\n" + 
6998
						"     0  aconst_null\n" + 
6999
						"     1  astore_1 [foo]\n" + 
7000
						"     2  aconst_null\n" + 
7001
						"     3  astore_2 [foo2]\n" + 
7002
						"     4  getstatic X.$assertionsDisabled : boolean [16]\n" + 
7003
						"     7  ifne 26\n" + 
7004
						"    10  aload_1 [foo]\n" + 
7005
						"    11  ifnull 18\n" + 
7006
						"    14  aload_2 [foo2]\n" + 
7007
						"    15  ifnonnull 26\n" + 
7008
						"    18  new java.lang.AssertionError [26]\n" + 
7009
						"    21  dup\n" + 
7010
						"    22  invokespecial java.lang.AssertionError() [28]\n" + 
7011
						"    25  athrow\n" + 
7012
						"    26  aload_1 [foo]\n" + 
7013
						"    27  ifnull 41\n" + 
7014
						"    30  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7015
						"    33  ldc <String \"foo is not null\"> [35]\n" + 
7016
						"    35  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7017
						"    38  goto 49\n" + 
7018
						"    41  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7019
						"    44  ldc <String \"foo is null\"> [43]\n" + 
7020
						"    46  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7021
						"    49  aload_2 [foo2]\n" + 
7022
						"    50  ifnull 64\n" + 
7023
						"    53  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7024
						"    56  ldc <String \"foo2 is not null\"> [45]\n" + 
7025
						"    58  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7026
						"    61  goto 72\n" + 
7027
						"    64  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7028
						"    67  ldc <String \"foo2 is null\"> [47]\n" + 
7029
						"    69  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7030
						"    72  return\n" + 
7031
						"      Line numbers:\n" + 
7032
						"        [pc: 0, line: 3]\n" + 
7033
						"        [pc: 2, line: 4]\n" + 
7034
						"        [pc: 4, line: 5]\n" + 
7035
						"        [pc: 26, line: 6]\n" + 
7036
						"        [pc: 30, line: 7]\n" + 
7037
						"        [pc: 41, line: 9]\n" + 
7038
						"        [pc: 49, line: 11]\n" + 
7039
						"        [pc: 53, line: 12]\n" + 
7040
						"        [pc: 64, line: 14]\n" + 
7041
						"        [pc: 72, line: 16]\n" + 
7042
						"      Local variable table:\n" + 
7043
						"        [pc: 0, pc: 73] local: this index: 0 type: X\n" + 
7044
						"        [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + 
7045
						"        [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n"
7046
					:	"  // Method descriptor #8 ()V\n" + 
7047
						"  // Stack: 2, Locals: 3\n" + 
7048
						"  public void foo();\n" + 
7049
						"     0  aconst_null\n" + 
7050
						"     1  astore_1 [foo]\n" + 
7051
						"     2  aconst_null\n" + 
7052
						"     3  astore_2 [foo2]\n" + 
7053
						"     4  getstatic X.$assertionsDisabled : boolean [16]\n" + 
7054
						"     7  ifne 26\n" + 
7055
						"    10  aload_1 [foo]\n" + 
7056
						"    11  ifnull 18\n" + 
7057
						"    14  aload_2 [foo2]\n" + 
7058
						"    15  ifnonnull 26\n" + 
7059
						"    18  new java.lang.AssertionError [27]\n" + 
7060
						"    21  dup\n" + 
7061
						"    22  invokespecial java.lang.AssertionError() [29]\n" + 
7062
						"    25  athrow\n" + 
7063
						"    26  aload_1 [foo]\n" + 
7064
						"    27  ifnull 41\n" + 
7065
						"    30  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7066
						"    33  ldc <String \"foo is not null\"> [36]\n" + 
7067
						"    35  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7068
						"    38  goto 49\n" + 
7069
						"    41  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7070
						"    44  ldc <String \"foo is null\"> [44]\n" + 
7071
						"    46  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7072
						"    49  aload_2 [foo2]\n" + 
7073
						"    50  ifnull 64\n" + 
7074
						"    53  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7075
						"    56  ldc <String \"foo2 is not null\"> [46]\n" + 
7076
						"    58  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7077
						"    61  goto 72\n" + 
7078
						"    64  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7079
						"    67  ldc <String \"foo2 is null\"> [48]\n" + 
7080
						"    69  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7081
						"    72  return\n" + 
7082
						"      Line numbers:\n" + 
7083
						"        [pc: 0, line: 3]\n" + 
7084
						"        [pc: 2, line: 4]\n" + 
7085
						"        [pc: 4, line: 5]\n" + 
7086
						"        [pc: 26, line: 6]\n" + 
7087
						"        [pc: 30, line: 7]\n" + 
7088
						"        [pc: 41, line: 9]\n" + 
7089
						"        [pc: 49, line: 11]\n" + 
7090
						"        [pc: 53, line: 12]\n" + 
7091
						"        [pc: 64, line: 14]\n" + 
7092
						"        [pc: 72, line: 16]\n" + 
7093
						"      Local variable table:\n" + 
7094
						"        [pc: 0, pc: 73] local: this index: 0 type: X\n" + 
7095
						"        [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + 
7096
						"        [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" + 
7097
						"      Stack map table: number of frames 6\n" + 
7098
						"        [pc: 18, append: {java.lang.Object, java.lang.Object}]\n" + 
7099
						"        [pc: 26, same]\n" + 
7100
						"        [pc: 41, same]\n" + 
7101
						"        [pc: 49, same]\n" + 
7102
						"        [pc: 64, same]\n" + 
7103
						"        [pc: 72, same]\n";
7104
		
7105
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
7106
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
7107
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
7108
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
7109
		int index = result.indexOf(expectedOutput);
7110
		if (index == -1 || expectedOutput.length() == 0) {
7111
			System.out.println(Util.displayString(result, 3));
7112
		}
7113
		if (index == -1) {
7114
			assertEquals("Wrong contents", expectedOutput, result);
7115
		}
7116
	}
7117
}
7118
7119
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448
7120
// To check that code gen is not optimized for an if statement
7121
// where a local variable's definite nullness or otherwise is known because of
7122
// an earlier assert expression (inside looping context)
7123
public void testBug303448c() throws Exception {
7124
	if (this.complianceLevel >= ClassFileConstants.JDK1_4) {
7125
		this.runConformTest(
7126
			new String[] {
7127
				"X.java",
7128
				"public class X {\n" +
7129
				"	public void foo() {\n" +
7130
				"		Object foo = null;\n" +
7131
				"		Object foo2 = null;\n" +
7132
				"		while(true){\n" +
7133
				"		assert (foo != null && foo2 != null);\n" +
7134
				"		if (foo != null) {\n" +
7135
				"			System.out.println(\"foo is not null\");\n" +
7136
				"		} else {\n" +
7137
				"			System.out.println(\"foo is null\");\n" +
7138
				"		}\n" +
7139
				"		if (foo2 != null) {\n" +
7140
				"			System.out.println(\"foo2 is not null\");\n" +
7141
				"		} else {\n" +
7142
				"			System.out.println(\"foo2 is null\");\n" +
7143
				"		}\n" +
7144
				"		}\n" +
7145
				"	}\n" +
7146
				"}\n",
7147
			},
7148
			"",
7149
			null,
7150
			true,
7151
			null,
7152
			getCompilerOptions(),
7153
			null); // custom requestor
7154
	
7155
		String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_5?
7156
				"  // Method descriptor #11 ()V\n" + 
7157
				"  // Stack: 2, Locals: 3\n" + 
7158
				"  public void foo();\n" + 
7159
				"     0  aconst_null\n" + 
7160
				"     1  astore_1 [foo]\n" + 
7161
				"     2  aconst_null\n" + 
7162
				"     3  astore_2 [foo2]\n" + 
7163
				"     4  getstatic X.$assertionsDisabled : boolean [38]\n" + 
7164
				"     7  ifne 26\n" + 
7165
				"    10  aload_1 [foo]\n" + 
7166
				"    11  ifnull 18\n" + 
7167
				"    14  aload_2 [foo2]\n" + 
7168
				"    15  ifnonnull 26\n" + 
7169
				"    18  new java.lang.AssertionError [49]\n" + 
7170
				"    21  dup\n" + 
7171
				"    22  invokespecial java.lang.AssertionError() [51]\n" + 
7172
				"    25  athrow\n" + 
7173
				"    26  aload_1 [foo]\n" + 
7174
				"    27  ifnull 41\n" + 
7175
				"    30  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
7176
				"    33  ldc <String \"foo is not null\"> [58]\n" + 
7177
				"    35  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
7178
				"    38  goto 49\n" + 
7179
				"    41  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
7180
				"    44  ldc <String \"foo is null\"> [65]\n" + 
7181
				"    46  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
7182
				"    49  aload_2 [foo2]\n" + 
7183
				"    50  ifnull 64\n" + 
7184
				"    53  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
7185
				"    56  ldc <String \"foo2 is not null\"> [67]\n" + 
7186
				"    58  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
7187
				"    61  goto 4\n" + 
7188
				"    64  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
7189
				"    67  ldc <String \"foo2 is null\"> [69]\n" + 
7190
				"    69  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
7191
				"    72  goto 4\n" + 
7192
				"      Line numbers:\n" + 
7193
				"        [pc: 0, line: 3]\n" + 
7194
				"        [pc: 2, line: 4]\n" + 
7195
				"        [pc: 4, line: 6]\n" + 
7196
				"        [pc: 26, line: 7]\n" + 
7197
				"        [pc: 30, line: 8]\n" + 
7198
				"        [pc: 41, line: 10]\n" + 
7199
				"        [pc: 49, line: 12]\n" + 
7200
				"        [pc: 53, line: 13]\n" + 
7201
				"        [pc: 64, line: 15]\n" + 
7202
				"        [pc: 72, line: 5]\n" + 
7203
				"      Local variable table:\n" + 
7204
				"        [pc: 0, pc: 75] local: this index: 0 type: X\n" + 
7205
				"        [pc: 2, pc: 75] local: foo index: 1 type: java.lang.Object\n" + 
7206
				"        [pc: 4, pc: 75] local: foo2 index: 2 type: java.lang.Object\n"
7207
			: 	this.complianceLevel < ClassFileConstants.JDK1_6?
7208
						"  // Method descriptor #8 ()V\n" + 
7209
						"  // Stack: 2, Locals: 3\n" + 
7210
						"  public void foo();\n" + 
7211
						"     0  aconst_null\n" + 
7212
						"     1  astore_1 [foo]\n" + 
7213
						"     2  aconst_null\n" + 
7214
						"     3  astore_2 [foo2]\n" + 
7215
						"     4  getstatic X.$assertionsDisabled : boolean [16]\n" + 
7216
						"     7  ifne 26\n" + 
7217
						"    10  aload_1 [foo]\n" + 
7218
						"    11  ifnull 18\n" + 
7219
						"    14  aload_2 [foo2]\n" + 
7220
						"    15  ifnonnull 26\n" + 
7221
						"    18  new java.lang.AssertionError [26]\n" + 
7222
						"    21  dup\n" + 
7223
						"    22  invokespecial java.lang.AssertionError() [28]\n" + 
7224
						"    25  athrow\n" + 
7225
						"    26  aload_1 [foo]\n" + 
7226
						"    27  ifnull 41\n" + 
7227
						"    30  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7228
						"    33  ldc <String \"foo is not null\"> [35]\n" + 
7229
						"    35  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7230
						"    38  goto 49\n" + 
7231
						"    41  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7232
						"    44  ldc <String \"foo is null\"> [43]\n" + 
7233
						"    46  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7234
						"    49  aload_2 [foo2]\n" + 
7235
						"    50  ifnull 64\n" + 
7236
						"    53  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7237
						"    56  ldc <String \"foo2 is not null\"> [45]\n" + 
7238
						"    58  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7239
						"    61  goto 4\n" + 
7240
						"    64  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7241
						"    67  ldc <String \"foo2 is null\"> [47]\n" + 
7242
						"    69  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7243
						"    72  goto 4\n" + 
7244
						"      Line numbers:\n" + 
7245
						"        [pc: 0, line: 3]\n" + 
7246
						"        [pc: 2, line: 4]\n" + 
7247
						"        [pc: 4, line: 6]\n" + 
7248
						"        [pc: 26, line: 7]\n" + 
7249
						"        [pc: 30, line: 8]\n" + 
7250
						"        [pc: 41, line: 10]\n" + 
7251
						"        [pc: 49, line: 12]\n" + 
7252
						"        [pc: 53, line: 13]\n" + 
7253
						"        [pc: 64, line: 15]\n" + 
7254
						"        [pc: 72, line: 5]\n" + 
7255
						"      Local variable table:\n" + 
7256
						"        [pc: 0, pc: 75] local: this index: 0 type: X\n" + 
7257
						"        [pc: 2, pc: 75] local: foo index: 1 type: java.lang.Object\n" + 
7258
						"        [pc: 4, pc: 75] local: foo2 index: 2 type: java.lang.Object\n"
7259
					:	"  // Method descriptor #8 ()V\n" + 
7260
						"  // Stack: 2, Locals: 3\n" + 
7261
						"  public void foo();\n" + 
7262
						"     0  aconst_null\n" + 
7263
						"     1  astore_1 [foo]\n" + 
7264
						"     2  aconst_null\n" + 
7265
						"     3  astore_2 [foo2]\n" + 
7266
						"     4  getstatic X.$assertionsDisabled : boolean [16]\n" + 
7267
						"     7  ifne 26\n" + 
7268
						"    10  aload_1 [foo]\n" + 
7269
						"    11  ifnull 18\n" + 
7270
						"    14  aload_2 [foo2]\n" + 
7271
						"    15  ifnonnull 26\n" + 
7272
						"    18  new java.lang.AssertionError [27]\n" + 
7273
						"    21  dup\n" + 
7274
						"    22  invokespecial java.lang.AssertionError() [29]\n" + 
7275
						"    25  athrow\n" + 
7276
						"    26  aload_1 [foo]\n" + 
7277
						"    27  ifnull 41\n" + 
7278
						"    30  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7279
						"    33  ldc <String \"foo is not null\"> [36]\n" + 
7280
						"    35  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7281
						"    38  goto 49\n" + 
7282
						"    41  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7283
						"    44  ldc <String \"foo is null\"> [44]\n" + 
7284
						"    46  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7285
						"    49  aload_2 [foo2]\n" + 
7286
						"    50  ifnull 64\n" + 
7287
						"    53  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7288
						"    56  ldc <String \"foo2 is not null\"> [46]\n" + 
7289
						"    58  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7290
						"    61  goto 4\n" + 
7291
						"    64  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7292
						"    67  ldc <String \"foo2 is null\"> [48]\n" + 
7293
						"    69  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7294
						"    72  goto 4\n" + 
7295
						"      Line numbers:\n" + 
7296
						"        [pc: 0, line: 3]\n" + 
7297
						"        [pc: 2, line: 4]\n" + 
7298
						"        [pc: 4, line: 6]\n" + 
7299
						"        [pc: 26, line: 7]\n" + 
7300
						"        [pc: 30, line: 8]\n" + 
7301
						"        [pc: 41, line: 10]\n" + 
7302
						"        [pc: 49, line: 12]\n" + 
7303
						"        [pc: 53, line: 13]\n" + 
7304
						"        [pc: 64, line: 15]\n" + 
7305
						"        [pc: 72, line: 5]\n" + 
7306
						"      Local variable table:\n" + 
7307
						"        [pc: 0, pc: 75] local: this index: 0 type: X\n" + 
7308
						"        [pc: 2, pc: 75] local: foo index: 1 type: java.lang.Object\n" + 
7309
						"        [pc: 4, pc: 75] local: foo2 index: 2 type: java.lang.Object\n" + 
7310
						"      Stack map table: number of frames 7\n" + 
7311
						"        [pc: 4, append: {java.lang.Object, java.lang.Object}]\n" + 
7312
						"        [pc: 18, same]\n" + 
7313
						"        [pc: 26, same]\n" + 
7314
						"        [pc: 41, same]\n" + 
7315
						"        [pc: 49, same]\n" + 
7316
						"        [pc: 64, same]\n" + 
7317
						"        [pc: 72, same]\n";
7318
		
7319
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
7320
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
7321
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
7322
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
7323
		int index = result.indexOf(expectedOutput);
7324
		if (index == -1 || expectedOutput.length() == 0) {
7325
			System.out.println(Util.displayString(result, 3));
7326
		}
7327
		if (index == -1) {
7328
			assertEquals("Wrong contents", expectedOutput, result);
7329
		}
7330
	}
7331
}
7332
7333
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448
7334
// To check that code gen is not optimized for an if statement
7335
// where a local variable's definite nullness or otherwise is known because of
7336
// an earlier assert expression (inside finally context)
7337
public void testBug303448d() throws Exception {
7338
	if (this.complianceLevel >= ClassFileConstants.JDK1_4) {
7339
		this.runConformTest(
7340
			new String[] {
7341
				"X.java",
7342
				"public class X {\n" +
7343
				"	public void foo() {\n" +
7344
				"		Object foo = null;\n" +
7345
				"		Object foo2 = null;\n" +
7346
				"		try {} \n" +
7347
				"		finally {\n" +
7348
				"		assert (foo != null && foo2 != null);\n" +
7349
				"		if (foo != null) {\n" +
7350
				"			System.out.println(\"foo is not null\");\n" +
7351
				"		} else {\n" +
7352
				"			System.out.println(\"foo is null\");\n" +
7353
				"		}\n" +
7354
				"		if (foo2 != null) {\n" +
7355
				"			System.out.println(\"foo2 is not null\");\n" +
7356
				"		} else {\n" +
7357
				"			System.out.println(\"foo2 is null\");\n" +
7358
				"		}\n" +
7359
				"		}\n" +
7360
				"	}\n" +
7361
				"}\n",
7362
			},
7363
			"",
7364
			null,
7365
			true,
7366
			null,
7367
			getCompilerOptions(),
7368
			null); // custom requestor
7369
	
7370
		String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_5?
7371
				"  // Method descriptor #11 ()V\n" + 
7372
				"  // Stack: 2, Locals: 3\n" + 
7373
				"  public void foo();\n" + 
7374
				"     0  aconst_null\n" + 
7375
				"     1  astore_1 [foo]\n" + 
7376
				"     2  aconst_null\n" + 
7377
				"     3  astore_2 [foo2]\n" + 
7378
				"     4  getstatic X.$assertionsDisabled : boolean [38]\n" + 
7379
				"     7  ifne 26\n" + 
7380
				"    10  aload_1 [foo]\n" + 
7381
				"    11  ifnull 18\n" + 
7382
				"    14  aload_2 [foo2]\n" + 
7383
				"    15  ifnonnull 26\n" + 
7384
				"    18  new java.lang.AssertionError [49]\n" + 
7385
				"    21  dup\n" + 
7386
				"    22  invokespecial java.lang.AssertionError() [51]\n" + 
7387
				"    25  athrow\n" + 
7388
				"    26  aload_1 [foo]\n" + 
7389
				"    27  ifnull 41\n" + 
7390
				"    30  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
7391
				"    33  ldc <String \"foo is not null\"> [58]\n" + 
7392
				"    35  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
7393
				"    38  goto 49\n" + 
7394
				"    41  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
7395
				"    44  ldc <String \"foo is null\"> [65]\n" + 
7396
				"    46  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
7397
				"    49  aload_2 [foo2]\n" + 
7398
				"    50  ifnull 64\n" + 
7399
				"    53  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
7400
				"    56  ldc <String \"foo2 is not null\"> [67]\n" + 
7401
				"    58  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
7402
				"    61  goto 72\n" + 
7403
				"    64  getstatic java.lang.System.out : java.io.PrintStream [52]\n" + 
7404
				"    67  ldc <String \"foo2 is null\"> [69]\n" + 
7405
				"    69  invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + 
7406
				"    72  return\n" + 
7407
				"      Line numbers:\n" + 
7408
				"        [pc: 0, line: 3]\n" + 
7409
				"        [pc: 2, line: 4]\n" + 
7410
				"        [pc: 4, line: 7]\n" + 
7411
				"        [pc: 26, line: 8]\n" + 
7412
				"        [pc: 30, line: 9]\n" + 
7413
				"        [pc: 41, line: 11]\n" + 
7414
				"        [pc: 49, line: 13]\n" + 
7415
				"        [pc: 53, line: 14]\n" + 
7416
				"        [pc: 64, line: 16]\n" + 
7417
				"        [pc: 72, line: 19]\n" + 
7418
				"      Local variable table:\n" + 
7419
				"        [pc: 0, pc: 73] local: this index: 0 type: X\n" + 
7420
				"        [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + 
7421
				"        [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n"
7422
			: 	this.complianceLevel < ClassFileConstants.JDK1_6?
7423
						"  // Method descriptor #8 ()V\n" + 
7424
						"  // Stack: 2, Locals: 3\n" + 
7425
						"  public void foo();\n" + 
7426
						"     0  aconst_null\n" + 
7427
						"     1  astore_1 [foo]\n" + 
7428
						"     2  aconst_null\n" + 
7429
						"     3  astore_2 [foo2]\n" + 
7430
						"     4  getstatic X.$assertionsDisabled : boolean [16]\n" + 
7431
						"     7  ifne 26\n" + 
7432
						"    10  aload_1 [foo]\n" + 
7433
						"    11  ifnull 18\n" + 
7434
						"    14  aload_2 [foo2]\n" + 
7435
						"    15  ifnonnull 26\n" + 
7436
						"    18  new java.lang.AssertionError [26]\n" + 
7437
						"    21  dup\n" + 
7438
						"    22  invokespecial java.lang.AssertionError() [28]\n" + 
7439
						"    25  athrow\n" + 
7440
						"    26  aload_1 [foo]\n" + 
7441
						"    27  ifnull 41\n" + 
7442
						"    30  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7443
						"    33  ldc <String \"foo is not null\"> [35]\n" + 
7444
						"    35  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7445
						"    38  goto 49\n" + 
7446
						"    41  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7447
						"    44  ldc <String \"foo is null\"> [43]\n" + 
7448
						"    46  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7449
						"    49  aload_2 [foo2]\n" + 
7450
						"    50  ifnull 64\n" + 
7451
						"    53  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7452
						"    56  ldc <String \"foo2 is not null\"> [45]\n" + 
7453
						"    58  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7454
						"    61  goto 72\n" + 
7455
						"    64  getstatic java.lang.System.out : java.io.PrintStream [29]\n" + 
7456
						"    67  ldc <String \"foo2 is null\"> [47]\n" + 
7457
						"    69  invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + 
7458
						"    72  return\n" + 
7459
						"      Line numbers:\n" + 
7460
						"        [pc: 0, line: 3]\n" + 
7461
						"        [pc: 2, line: 4]\n" + 
7462
						"        [pc: 4, line: 7]\n" + 
7463
						"        [pc: 26, line: 8]\n" + 
7464
						"        [pc: 30, line: 9]\n" + 
7465
						"        [pc: 41, line: 11]\n" + 
7466
						"        [pc: 49, line: 13]\n" + 
7467
						"        [pc: 53, line: 14]\n" + 
7468
						"        [pc: 64, line: 16]\n" + 
7469
						"        [pc: 72, line: 19]\n" + 
7470
						"      Local variable table:\n" + 
7471
						"        [pc: 0, pc: 73] local: this index: 0 type: X\n" + 
7472
						"        [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + 
7473
						"        [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n"
7474
					:	"  // Method descriptor #8 ()V\n" + 
7475
						"  // Stack: 2, Locals: 3\n" + 
7476
						"  public void foo();\n" + 
7477
						"     0  aconst_null\n" + 
7478
						"     1  astore_1 [foo]\n" + 
7479
						"     2  aconst_null\n" + 
7480
						"     3  astore_2 [foo2]\n" + 
7481
						"     4  getstatic X.$assertionsDisabled : boolean [16]\n" + 
7482
						"     7  ifne 26\n" + 
7483
						"    10  aload_1 [foo]\n" + 
7484
						"    11  ifnull 18\n" + 
7485
						"    14  aload_2 [foo2]\n" + 
7486
						"    15  ifnonnull 26\n" + 
7487
						"    18  new java.lang.AssertionError [27]\n" + 
7488
						"    21  dup\n" + 
7489
						"    22  invokespecial java.lang.AssertionError() [29]\n" + 
7490
						"    25  athrow\n" + 
7491
						"    26  aload_1 [foo]\n" + 
7492
						"    27  ifnull 41\n" + 
7493
						"    30  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7494
						"    33  ldc <String \"foo is not null\"> [36]\n" + 
7495
						"    35  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7496
						"    38  goto 49\n" + 
7497
						"    41  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7498
						"    44  ldc <String \"foo is null\"> [44]\n" + 
7499
						"    46  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7500
						"    49  aload_2 [foo2]\n" + 
7501
						"    50  ifnull 64\n" + 
7502
						"    53  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7503
						"    56  ldc <String \"foo2 is not null\"> [46]\n" + 
7504
						"    58  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7505
						"    61  goto 72\n" + 
7506
						"    64  getstatic java.lang.System.out : java.io.PrintStream [30]\n" + 
7507
						"    67  ldc <String \"foo2 is null\"> [48]\n" + 
7508
						"    69  invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + 
7509
						"    72  return\n" + 
7510
						"      Line numbers:\n" + 
7511
						"        [pc: 0, line: 3]\n" + 
7512
						"        [pc: 2, line: 4]\n" + 
7513
						"        [pc: 4, line: 7]\n" + 
7514
						"        [pc: 26, line: 8]\n" + 
7515
						"        [pc: 30, line: 9]\n" + 
7516
						"        [pc: 41, line: 11]\n" + 
7517
						"        [pc: 49, line: 13]\n" + 
7518
						"        [pc: 53, line: 14]\n" + 
7519
						"        [pc: 64, line: 16]\n" + 
7520
						"        [pc: 72, line: 19]\n" + 
7521
						"      Local variable table:\n" + 
7522
						"        [pc: 0, pc: 73] local: this index: 0 type: X\n" + 
7523
						"        [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + 
7524
						"        [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" + 
7525
						"      Stack map table: number of frames 6\n" + 
7526
						"        [pc: 18, append: {java.lang.Object, java.lang.Object}]\n" + 
7527
						"        [pc: 26, same]\n" + 
7528
						"        [pc: 41, same]\n" + 
7529
						"        [pc: 49, same]\n" + 
7530
						"        [pc: 64, same]\n" + 
7531
						"        [pc: 72, same]\n";
7532
		
7533
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
7534
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
7535
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
7536
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
7537
		int index = result.indexOf(expectedOutput);
7538
		if (index == -1 || expectedOutput.length() == 0) {
7539
			System.out.println(Util.displayString(result, 3));
7540
		}
7541
		if (index == -1) {
7542
			assertEquals("Wrong contents", expectedOutput, result);
7543
		}
7544
	}
7545
}
7546
6769
public static Class testClass() {
7547
public static Class testClass() {
6770
	return ConformTest.class;
7548
	return ConformTest.class;
6771
}
7549
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (-69 / +14 lines)
Lines 8232-8243 Link Here
8232
			"	    ^^\n" +
8232
			"	    ^^\n" +
8233
			"Null comparison always yields false: The variable o1 cannot be null at this location\n" +
8233
			"Null comparison always yields false: The variable o1 cannot be null at this location\n" +
8234
			"----------\n" +
8234
			"----------\n" +
8235
			"2. WARNING in X.java (at line 4)\n" + 
8235
			"2. ERROR in X.java (at line 5)\n" +
8236
			"	if (o1 == null) { };\n" + 
8237
			"	                ^^^\n" + 
8238
			"Dead code\n" + 
8239
			"----------\n" + 
8240
			"3. ERROR in X.java (at line 5)\n" +
8241
			"	if (o2 == null) { };\n" +
8236
			"	if (o2 == null) { };\n" +
8242
			"	    ^^\n" +
8237
			"	    ^^\n" +
8243
			"Redundant null check: The variable o2 can only be null at this location\n" +
8238
			"Redundant null check: The variable o2 can only be null at this location\n" +
Lines 8286-8296 Link Here
8286
		"	if (o == null) { };\n" +
8281
		"	if (o == null) { };\n" +
8287
		"	    ^\n" +
8282
		"	    ^\n" +
8288
		"Null comparison always yields false: The variable o cannot be null at this location\n" +
8283
		"Null comparison always yields false: The variable o cannot be null at this location\n" +
8289
		"----------\n" +
8290
		"2. WARNING in X.java (at line 4)\n" + 
8291
		"	if (o == null) { };\n" + 
8292
		"	               ^^^\n" + 
8293
		"Dead code\n" + 
8294
		"----------\n",
8284
		"----------\n",
8295
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8285
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8296
	}
8286
	}
Lines 8315-8325 Link Here
8315
		"	if (o == null) { };\n" +
8305
		"	if (o == null) { };\n" +
8316
		"	    ^\n" +
8306
		"	    ^\n" +
8317
		"Null comparison always yields false: The variable o cannot be null at this location\n" +
8307
		"Null comparison always yields false: The variable o cannot be null at this location\n" +
8318
		"----------\n" +
8319
		"2. WARNING in X.java (at line 5)\n" +
8320
		"	if (o == null) { };\n" +
8321
		"	               ^^^\n" +
8322
		"Dead code\n" +
8323
		"----------\n",
8308
		"----------\n",
8324
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8309
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8325
	}
8310
	}
Lines 8354-8384 Link Here
8354
		"	if (foo == null) {}\n" + 
8339
		"	if (foo == null) {}\n" + 
8355
		"	    ^^^\n" + 
8340
		"	    ^^^\n" + 
8356
		"Null comparison always yields false: The variable foo cannot be null at this location\n" + 
8341
		"Null comparison always yields false: The variable foo cannot be null at this location\n" + 
8357
		"----------\n" + 
8342
		"----------\n" +  
8358
		"2. WARNING in X.java (at line 5)\n" + 
8343
		"2. ERROR in X.java (at line 8)\n" + 
8359
		"	if (foo == null) {}\n" + 
8360
		"	                 ^^\n" + 
8361
		"Dead code\n" + 
8362
		"----------\n" + 
8363
		"3. ERROR in X.java (at line 8)\n" + 
8364
		"	if (foo2 == null) {}\n" + 
8344
		"	if (foo2 == null) {}\n" + 
8365
		"	    ^^^^\n" + 
8345
		"	    ^^^^\n" + 
8366
		"Redundant null check: The variable foo2 can only be null at this location\n" + 
8346
		"Redundant null check: The variable foo2 can only be null at this location\n" + 
8367
		"----------\n" + 
8347
		"----------\n" + 
8368
		"4. ERROR in X.java (at line 11)\n" + 
8348
		"3. ERROR in X.java (at line 11)\n" + 
8369
		"	if (bar == null) {}\n" + 
8349
		"	if (bar == null) {}\n" + 
8370
		"	    ^^^\n" + 
8350
		"	    ^^^\n" + 
8371
		"Redundant null check: The variable bar can only be null at this location\n" + 
8351
		"Redundant null check: The variable bar can only be null at this location\n" + 
8372
		"----------\n" + 
8352
		"----------\n" + 
8373
		"5. ERROR in X.java (at line 14)\n" + 
8353
		"4. ERROR in X.java (at line 14)\n" + 
8374
		"	if (bar2 == null) {}\n" + 
8354
		"	if (bar2 == null) {}\n" + 
8375
		"	    ^^^^\n" + 
8355
		"	    ^^^^\n" + 
8376
		"Null comparison always yields false: The variable bar2 cannot be null at this location\n" + 
8356
		"Null comparison always yields false: The variable bar2 cannot be null at this location\n" + 
8377
		"----------\n" + 
8378
		"6. WARNING in X.java (at line 14)\n" + 
8379
		"	if (bar2 == null) {}\n" + 
8380
		"	                  ^^\n" + 
8381
		"Dead code\n" + 
8382
		"----------\n",
8357
		"----------\n",
8383
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8358
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8384
	}
8359
	}
Lines 8454-8483 Link Here
8454
		"	    ^^^\n" + 
8429
		"	    ^^^\n" + 
8455
		"Null comparison always yields false: The variable foo cannot be null at this location\n" + 
8430
		"Null comparison always yields false: The variable foo cannot be null at this location\n" + 
8456
		"----------\n" + 
8431
		"----------\n" + 
8457
		"2. WARNING in X.java (at line 9)\n" + 
8432
		"2. ERROR in X.java (at line 11)\n" + 
8458
		"	if (foo == null) {}\n" + 
8459
		"	                 ^^\n" + 
8460
		"Dead code\n" + 
8461
		"----------\n" + 
8462
		"3. ERROR in X.java (at line 11)\n" + 
8463
		"	if (foo2 == null) {}\n" + 
8433
		"	if (foo2 == null) {}\n" + 
8464
		"	    ^^^^\n" + 
8434
		"	    ^^^^\n" + 
8465
		"Redundant null check: The variable foo2 can only be null at this location\n" + 
8435
		"Redundant null check: The variable foo2 can only be null at this location\n" + 
8466
		"----------\n" + 
8436
		"----------\n" + 
8467
		"4. ERROR in X.java (at line 13)\n" + 
8437
		"3. ERROR in X.java (at line 13)\n" + 
8468
		"	if (bar == null) {}\n" + 
8438
		"	if (bar == null) {}\n" + 
8469
		"	    ^^^\n" + 
8439
		"	    ^^^\n" + 
8470
		"Redundant null check: The variable bar can only be null at this location\n" + 
8440
		"Redundant null check: The variable bar can only be null at this location\n" + 
8471
		"----------\n" + 
8441
		"----------\n" + 
8472
		"5. ERROR in X.java (at line 15)\n" + 
8442
		"4. ERROR in X.java (at line 15)\n" + 
8473
		"	if (bar2 == null) {}\n" + 
8443
		"	if (bar2 == null) {}\n" + 
8474
		"	    ^^^^\n" + 
8444
		"	    ^^^^\n" + 
8475
		"Null comparison always yields false: The variable bar2 cannot be null at this location\n" + 
8445
		"Null comparison always yields false: The variable bar2 cannot be null at this location\n" + 
8476
		"----------\n" + 
8477
		"6. WARNING in X.java (at line 15)\n" + 
8478
		"	if (bar2 == null) {}\n" + 
8479
		"	                  ^^\n" + 
8480
		"Dead code\n" + 
8481
		"----------\n",
8446
		"----------\n",
8482
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8447
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8483
	}
8448
	}
Lines 8515-8544 Link Here
8515
		"	    ^^^\n" + 
8480
		"	    ^^^\n" + 
8516
		"Null comparison always yields false: The variable foo cannot be null at this location\n" + 
8481
		"Null comparison always yields false: The variable foo cannot be null at this location\n" + 
8517
		"----------\n" + 
8482
		"----------\n" + 
8518
		"2. WARNING in X.java (at line 6)\n" + 
8483
		"2. ERROR in X.java (at line 9)\n" + 
8519
		"	if (foo == null) {}\n" + 
8520
		"	                 ^^\n" + 
8521
		"Dead code\n" + 
8522
		"----------\n" + 
8523
		"3. ERROR in X.java (at line 9)\n" + 
8524
		"	if (foo2 == null) {}\n" + 
8484
		"	if (foo2 == null) {}\n" + 
8525
		"	    ^^^^\n" + 
8485
		"	    ^^^^\n" + 
8526
		"Redundant null check: The variable foo2 can only be null at this location\n" + 
8486
		"Redundant null check: The variable foo2 can only be null at this location\n" + 
8527
		"----------\n" + 
8487
		"----------\n" + 
8528
		"4. ERROR in X.java (at line 12)\n" + 
8488
		"3. ERROR in X.java (at line 12)\n" + 
8529
		"	if (bar == null) {}\n" + 
8489
		"	if (bar == null) {}\n" + 
8530
		"	    ^^^\n" + 
8490
		"	    ^^^\n" + 
8531
		"Redundant null check: The variable bar can only be null at this location\n" + 
8491
		"Redundant null check: The variable bar can only be null at this location\n" + 
8532
		"----------\n" + 
8492
		"----------\n" + 
8533
		"5. ERROR in X.java (at line 15)\n" + 
8493
		"4. ERROR in X.java (at line 15)\n" + 
8534
		"	if (bar2 == null) {}\n" + 
8494
		"	if (bar2 == null) {}\n" + 
8535
		"	    ^^^^\n" + 
8495
		"	    ^^^^\n" + 
8536
		"Null comparison always yields false: The variable bar2 cannot be null at this location\n" + 
8496
		"Null comparison always yields false: The variable bar2 cannot be null at this location\n" + 
8537
		"----------\n" + 
8538
		"6. WARNING in X.java (at line 15)\n" + 
8539
		"	if (bar2 == null) {}\n" + 
8540
		"	                  ^^\n" + 
8541
		"Dead code\n" + 
8542
		"----------\n",
8497
		"----------\n",
8543
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8498
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8544
	}
8499
	}
Lines 8579-8608 Link Here
8579
		"	    ^^^\n" +
8534
		"	    ^^^\n" +
8580
		"Null comparison always yields false: The variable foo cannot be null at this location\n" +
8535
		"Null comparison always yields false: The variable foo cannot be null at this location\n" +
8581
		"----------\n" +
8536
		"----------\n" +
8582
		"2. WARNING in X.java (at line 12)\n" +
8537
		"2. ERROR in X.java (at line 14)\n" +
8583
		"	if (foo == null) {}\n" +
8584
		"	                 ^^\n" +
8585
		"Dead code\n" +
8586
		"----------\n" +
8587
		"3. ERROR in X.java (at line 14)\n" +
8588
		"	if (foo2 == null) {}\n" +
8538
		"	if (foo2 == null) {}\n" +
8589
		"	    ^^^^\n" +
8539
		"	    ^^^^\n" +
8590
		"Redundant null check: The variable foo2 can only be null at this location\n" +
8540
		"Redundant null check: The variable foo2 can only be null at this location\n" +
8591
		"----------\n" +
8541
		"----------\n" +
8592
		"4. ERROR in X.java (at line 16)\n" +
8542
		"3. ERROR in X.java (at line 16)\n" +
8593
		"	if (bar == null) {}\n" +
8543
		"	if (bar == null) {}\n" +
8594
		"	    ^^^\n" +
8544
		"	    ^^^\n" +
8595
		"Redundant null check: The variable bar can only be null at this location\n" +
8545
		"Redundant null check: The variable bar can only be null at this location\n" +
8596
		"----------\n" +
8546
		"----------\n" +
8597
		"5. ERROR in X.java (at line 18)\n" +
8547
		"4. ERROR in X.java (at line 18)\n" +
8598
		"	if (bar2 == null) {}\n" +
8548
		"	if (bar2 == null) {}\n" +
8599
		"	    ^^^^\n" +
8549
		"	    ^^^^\n" +
8600
		"Null comparison always yields false: The variable bar2 cannot be null at this location\n" +
8550
		"Null comparison always yields false: The variable bar2 cannot be null at this location\n" +
8601
		"----------\n" +
8602
		"6. WARNING in X.java (at line 18)\n" +
8603
		"	if (bar2 == null) {}\n" +
8604
		"	                  ^^\n" +
8605
		"Dead code\n" +
8606
		"----------\n",
8551
		"----------\n",
8607
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8552
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8608
	}
8553
	}

Return to bug 303448