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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/NullInfoRegistry.java (-1 / +144 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2010 IBM Corporation and others.
2
 * Copyright (c) 2006, 2011 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 402-406 Link Here
402
			return nullS + "]>"; //$NON-NLS-1$
402
			return nullS + "]>"; //$NON-NLS-1$
403
	}
403
	}
404
}
404
}
405
406
/**
407
 * Mark a local as potentially having been assigned to an unknown value.
408
 * @param local the local to mark
409
 */
410
public void markPotentiallyUnknownBit(LocalVariableBinding local) {
411
	// protected from non-object locals in calling methods
412
	if (this != DEAD_END) {
413
		this.tagBits |= NULL_FLAG_MASK;
414
        int position;
415
        long mask;
416
        if ((position = local.id + this.maxFieldCount) < BitCacheSize) {
417
            // use bits
418
        	mask = 1L << position;
419
        	isTrue((this.nullBit1 & mask) == 0, "Adding 'unknown' mark in unexpected state"); //$NON-NLS-1$
420
            this.nullBit4 |= mask;
421
            if (COVERAGE_TEST_FLAG) {
422
				if(CoverageTestId == 46) {
423
				  	this.nullBit4 = ~0;
424
				}
425
			}
426
        } else {
427
    		// use extra vector
428
    		int vectorIndex = (position / BitCacheSize) - 1;
429
    		if (this.extra == null) {
430
    			int length = vectorIndex + 1;
431
    			this.extra = new long[extraLength][];
432
    			for (int j = 2; j < extraLength; j++) {
433
    				this.extra[j] = new long[length];
434
    			}
435
    		} else {
436
    			int oldLength; // might need to grow the arrays
437
    			if (vectorIndex >= (oldLength = this.extra[2].length)) {
438
    				for (int j = 2; j < extraLength; j++) {
439
    					System.arraycopy(this.extra[j], 0,
440
    						(this.extra[j] = new long[vectorIndex + 1]), 0,
441
    						oldLength);
442
    				}
443
    			}
444
    		}
445
    		mask = 1L << (position % BitCacheSize);
446
    		isTrue((this.extra[2][vectorIndex] & mask) == 0, "Adding 'unknown' mark in unexpected state"); //$NON-NLS-1$
447
    		this.extra[5][vectorIndex] |= mask;
448
    		if (COVERAGE_TEST_FLAG) {
449
				if(CoverageTestId == 47) {
450
					this.extra[5][vectorIndex] = ~0;
451
				}
452
			}
453
    	}
454
	}
455
}
456
457
public void markPotentiallyNullBit(LocalVariableBinding local) {
458
	if (this != DEAD_END) {
459
		this.tagBits |= NULL_FLAG_MASK;
460
        int position;
461
        long mask;
462
        if ((position = local.id + this.maxFieldCount) < BitCacheSize) {
463
            // use bits
464
        	mask = 1L << position;
465
        	isTrue((this.nullBit1 & mask) == 0, "Adding 'potentially null' mark in unexpected state"); //$NON-NLS-1$
466
            this.nullBit2 |= mask;
467
            if (COVERAGE_TEST_FLAG) {
468
				if(CoverageTestId == 40) {
469
				  	this.nullBit4 = ~0;
470
				}
471
			}
472
        } else {
473
    		// use extra vector
474
    		int vectorIndex = (position / BitCacheSize) - 1;
475
    		if (this.extra == null) {
476
    			int length = vectorIndex + 1;
477
    			this.extra = new long[extraLength][];
478
    			for (int j = 2; j < extraLength; j++) {
479
    				this.extra[j] = new long[length];
480
    			}
481
    		} else {
482
    			int oldLength; // might need to grow the arrays
483
    			if (vectorIndex >= (oldLength = this.extra[2].length)) {
484
    				for (int j = 2; j < extraLength; j++) {
485
    					System.arraycopy(this.extra[j], 0,
486
    						(this.extra[j] = new long[vectorIndex + 1]), 0,
487
    						oldLength);
488
    				}
489
    			}
490
    		}
491
    		mask = 1L << (position % BitCacheSize);
492
    		this.extra[3][vectorIndex] |= mask;
493
    		isTrue((this.extra[2][vectorIndex] & mask) == 0, "Adding 'potentially null' mark in unexpected state"); //$NON-NLS-1$
494
    		if (COVERAGE_TEST_FLAG) {
495
				if(CoverageTestId == 41) {
496
					this.extra[5][vectorIndex] = ~0;
497
				}
498
			}
499
    	}
500
	}
501
}
502
503
public void markPotentiallyNonNullBit(LocalVariableBinding local) {
504
	if (this != DEAD_END) {
505
		this.tagBits |= NULL_FLAG_MASK;
506
        int position;
507
        long mask;
508
        if ((position = local.id + this.maxFieldCount) < BitCacheSize) {
509
            // use bits
510
        	mask = 1L << position;
511
        	isTrue((this.nullBit1 & mask) == 0, "Adding 'potentially non-null' mark in unexpected state"); //$NON-NLS-1$
512
            this.nullBit3 |= mask;
513
            if (COVERAGE_TEST_FLAG) {
514
				if(CoverageTestId == 42) {
515
				  	this.nullBit4 = ~0;
516
				}
517
			}
518
        } else {
519
    		// use extra vector
520
    		int vectorIndex  = (position / BitCacheSize) - 1;
521
    		if (this.extra == null) {
522
    			int length = vectorIndex + 1;
523
    			this.extra = new long[extraLength][];
524
    			for (int j = 2; j < extraLength; j++) {
525
    				this.extra[j] = new long[length];
526
    			}
527
    		} else {
528
    			int oldLength; // might need to grow the arrays
529
    			if (vectorIndex >= (oldLength = this.extra[2].length)) {
530
    				for (int j = 2; j < extraLength; j++) {
531
    					System.arraycopy(this.extra[j], 0,
532
    						(this.extra[j] = new long[vectorIndex + 1]), 0,
533
    						oldLength);
534
    				}
535
    			}
536
    		}
537
    		mask = 1L << (position % BitCacheSize);
538
    		isTrue((this.extra[2][vectorIndex] & mask) == 0, "Adding 'potentially non-null' mark in unexpected state"); //$NON-NLS-1$
539
    		this.extra[4][vectorIndex] |= mask;
540
    		if (COVERAGE_TEST_FLAG) {
541
				if(CoverageTestId == 43) {
542
					this.extra[5][vectorIndex] = ~0;
543
				}
544
			}
545
    	}
546
	}
547
}
405
}
548
}
406
549
(-)compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java (-4 / +60 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 996-1002 Link Here
996
 * @return <code>true</code> if the check passes (does not return
996
 * @return <code>true</code> if the check passes (does not return
997
 *    if the check fails)
997
 *    if the check fails)
998
 */
998
 */
999
private static boolean isTrue(boolean expression, String message) {
999
protected static boolean isTrue(boolean expression, String message) {
1000
	if (!expression)
1000
	if (!expression)
1001
		throw new AssertionFailedException("assertion failed: " + message); //$NON-NLS-1$
1001
		throw new AssertionFailedException("assertion failed: " + message); //$NON-NLS-1$
1002
	return expression;
1002
	return expression;
Lines 1367-1374 Link Here
1367
            this.nullBit4 &= mask;
1367
            this.nullBit4 &= mask;
1368
        } else {
1368
        } else {
1369
    		// use extra vector
1369
    		// use extra vector
1370
    		int vectorIndex ;
1370
    		int vectorIndex = (position / BitCacheSize) - 1;
1371
    		this.extra[2][vectorIndex = (position / BitCacheSize) - 1]
1371
    		if (this.extra == null || vectorIndex >= this.extra[2].length) {
1372
    			// in case we attempt to reset the null info of a variable that has not been encountered
1373
    			// before and for which no null bits exist.
1374
    			return;
1375
    		}
1376
    		this.extra[2][vectorIndex]
1372
    		    &= (mask = ~(1L << (position % BitCacheSize)));
1377
    		    &= (mask = ~(1L << (position % BitCacheSize)));
1373
    		this.extra[3][vectorIndex] &= mask;
1378
    		this.extra[3][vectorIndex] &= mask;
1374
    		this.extra[4][vectorIndex] &= mask;
1379
    		this.extra[4][vectorIndex] &= mask;
Lines 1400-1405 Link Here
1400
        } else {
1405
        } else {
1401
    		// use extra vector
1406
    		// use extra vector
1402
    		int vectorIndex = (position / BitCacheSize) - 1;
1407
    		int vectorIndex = (position / BitCacheSize) - 1;
1408
    		if (this.extra == null) {
1409
				int length = vectorIndex + 1;
1410
				this.extra = new long[extraLength][];
1411
				for (int j = 0; j < extraLength; j++) {
1412
					this.extra[j] = new long[length];
1413
				}
1414
			}
1415
			else {
1416
				int oldLength; // might need to grow the arrays
1417
				if (vectorIndex >= (oldLength = this.extra[0].length)) {
1418
					for (int j = 0; j < extraLength; j++) {
1419
						System.arraycopy(this.extra[j], 0,
1420
							(this.extra[j] = new long[vectorIndex + 1]), 0,
1421
							oldLength);
1422
					}
1423
				}
1424
			}
1403
    		mask = 1L << (position % BitCacheSize);
1425
    		mask = 1L << (position % BitCacheSize);
1404
    		isTrue((this.extra[2][vectorIndex] & mask) == 0, "Adding 'unknown' mark in unexpected state"); //$NON-NLS-1$
1426
    		isTrue((this.extra[2][vectorIndex] & mask) == 0, "Adding 'unknown' mark in unexpected state"); //$NON-NLS-1$
1405
    		this.extra[5][vectorIndex] |= mask;
1427
    		this.extra[5][vectorIndex] |= mask;
Lines 1430-1435 Link Here
1430
        } else {
1452
        } else {
1431
    		// use extra vector
1453
    		// use extra vector
1432
    		int vectorIndex = (position / BitCacheSize) - 1;
1454
    		int vectorIndex = (position / BitCacheSize) - 1;
1455
    		if (this.extra == null) {
1456
				int length = vectorIndex + 1;
1457
				this.extra = new long[extraLength][];
1458
				for (int j = 0; j < extraLength; j++) {
1459
					this.extra[j] = new long[length];
1460
				}
1461
			}
1462
			else {
1463
				int oldLength; // might need to grow the arrays
1464
				if (vectorIndex >= (oldLength = this.extra[0].length)) {
1465
					for (int j = 0; j < extraLength; j++) {
1466
						System.arraycopy(this.extra[j], 0,
1467
							(this.extra[j] = new long[vectorIndex + 1]), 0,
1468
							oldLength);
1469
					}
1470
				}
1471
			}
1433
    		mask = 1L << (position % BitCacheSize);
1472
    		mask = 1L << (position % BitCacheSize);
1434
    		this.extra[3][vectorIndex] |= mask;
1473
    		this.extra[3][vectorIndex] |= mask;
1435
    		isTrue((this.extra[2][vectorIndex] & mask) == 0, "Adding 'potentially null' mark in unexpected state"); //$NON-NLS-1$
1474
    		isTrue((this.extra[2][vectorIndex] & mask) == 0, "Adding 'potentially null' mark in unexpected state"); //$NON-NLS-1$
Lines 1460-1465 Link Here
1460
        } else {
1499
        } else {
1461
    		// use extra vector
1500
    		// use extra vector
1462
    		int vectorIndex  = (position / BitCacheSize) - 1;
1501
    		int vectorIndex  = (position / BitCacheSize) - 1;
1502
    		if (this.extra == null) {
1503
				int length = vectorIndex + 1;
1504
				this.extra = new long[extraLength][];
1505
				for (int j = 0; j < extraLength; j++) {
1506
					this.extra[j] = new long[length];
1507
				}
1508
			}
1509
			else {
1510
				int oldLength; // might need to grow the arrays
1511
				if (vectorIndex >= (oldLength = this.extra[0].length)) {
1512
					for (int j = 0; j < extraLength; j++) {
1513
						System.arraycopy(this.extra[j], 0,
1514
							(this.extra[j] = new long[vectorIndex + 1]), 0,
1515
							oldLength);
1516
					}
1517
				}
1518
			}
1463
    		mask = 1L << (position % BitCacheSize);
1519
    		mask = 1L << (position % BitCacheSize);
1464
    		isTrue((this.extra[2][vectorIndex] & mask) == 0, "Adding 'potentially non-null' mark in unexpected state"); //$NON-NLS-1$
1520
    		isTrue((this.extra[2][vectorIndex] & mask) == 0, "Adding 'potentially non-null' mark in unexpected state"); //$NON-NLS-1$
1465
    		this.extra[4][vectorIndex] |= mask;
1521
    		this.extra[4][vectorIndex] |= mask;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (-1 / +27 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2010 IBM Corporation and others.
2
 * Copyright (c) 2005, 2011 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 13806-13809 Link Here
13806
		"Done\n" + 
13806
		"Done\n" + 
13807
		"-1");
13807
		"-1");
13808
}
13808
}
13809
13810
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=333089 
13811
// null analysis -- to make sure no AIOOBE or NPE is thrown while calling UnconditionalFlowInfo.markNullStatus(..)
13812
public void testBug333089() {
13813
	this.runConformTest(
13814
		new String[] {
13815
			"X.java",
13816
			"public class X {\n" + 
13817
			"	public static void foo(Object s1) {\n" + 
13818
	        "    int i00, i01, i02, i03, i04, i05, i06, i07, i08, i09;\n" +
13819
	        "    int i10, i11, i12, i13, i14, i15, i16, i17, i18, i19;\n" +
13820
	        "    int i20, i21, i22, i23, i24, i25, i26, i27, i28, i29;\n" +
13821
	        "    int i30, i31, i32, i33, i34, i35, i36, i37, i38, i39;\n" +
13822
	        "    int i40, i41, i42, i43, i44, i45, i46, i47, i48, i49;\n" +
13823
	        "    int i50, i51, i52, i53, i54, i55, i56, i57, i58, i59;\n" +
13824
	        "    int i60, i61, i62, i63, i64, i65, i66, i67, i68, i69;\n" +
13825
			"	 Object local1;\n" + 
13826
			"	 if (s1 == null){}\n" + 
13827
			"	 try {" +
13828
			"		local1 = s1;\n" +
13829
			"	 } finally {\n" +
13830
			"	 }\n" + 
13831
			"	}\n" + 
13832
			"}"},
13833
		"");
13834
}
13809
}
13835
}

Return to bug 333089