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

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (-1 / +343 lines)
Lines 15-20 Link Here
15
 *     							bug 349326 - [1.7] new warning for missing try-with-resources
15
 *     							bug 349326 - [1.7] new warning for missing try-with-resources
16
 *     							bug 359721 - [options] add command line option for new warning token "resource"
16
 *     							bug 359721 - [options] add command line option for new warning token "resource"
17
 *     							bug 186342 - [compiler][null] Using annotations for null checking
17
 *     							bug 186342 - [compiler][null] Using annotations for null checking
18
 *								bug 365208 - [compiler][batch] command line options for annotation based null analysis
18
 *******************************************************************************/
19
 *******************************************************************************/
19
package org.eclipse.jdt.core.tests.compiler.regression;
20
package org.eclipse.jdt.core.tests.compiler.regression;
20
21
Lines 51-58 Link Here
51
	static final String JRE_HOME_DIR = Util.getJREDirectory();
52
	static final String JRE_HOME_DIR = Util.getJREDirectory();
52
	private static final Main MAIN = new Main(null/*outWriter*/, null/*errWriter*/, false/*systemExit*/, null/*options*/, null/*progress*/);
53
	private static final Main MAIN = new Main(null/*outWriter*/, null/*errWriter*/, false/*systemExit*/, null/*options*/, null/*progress*/);
53
54
55
	private static final String NONNULL_BY_DEFAULT_ANNOTATION_CONTENT = "package org.eclipse.jdt.annotation;\n" +
56
			"import static java.lang.annotation.ElementType.*;\n" +
57
			"import java.lang.annotation.*;\n" +
58
			"@Documented\n" +
59
			"@Retention(RetentionPolicy.CLASS)\n" +
60
			"@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })\n" +
61
			"public @interface NonNullByDefault{\n" +
62
			"}";
63
	private static final String NULLABLE_ANNOTATION_CONTENT = "package org.eclipse.jdt.annotation;\n" +
64
			"import static java.lang.annotation.ElementType.*;\n" +
65
			"import java.lang.annotation.*;\n" +
66
			"@Documented\n" +
67
			"@Retention(RetentionPolicy.CLASS)\n" +
68
			"@Target({ METHOD, PARAMETER })\n" +
69
			"public @interface Nullable{\n" +
70
			"}\n";
71
	private static final String NONNULL_ANNOTATION_CONTENT = "package org.eclipse.jdt.annotation;\n" +
72
			"import static java.lang.annotation.ElementType.*;\n" +
73
			"import java.lang.annotation.*;\n" +
74
			"@Documented\n" +
75
			"@Retention(RetentionPolicy.CLASS)\n" +
76
			"@Target({ METHOD, PARAMETER })\n" +
77
			"public @interface NonNull{\n" +
78
			"}\n";
79
54
	static {
80
	static {
55
//		TESTS_NAMES = new String[] { "test295_warn_options" };
81
//		TESTS_NAMES = new String[] { "test31" };
56
//		TESTS_NUMBERS = new int[] { 306 };
82
//		TESTS_NUMBERS = new int[] { 306 };
57
//		TESTS_RANGE = new int[] { 298, -1 };
83
//		TESTS_RANGE = new int[] { 298, -1 };
58
	}
84
	}
Lines 1614-1619 Link Here
1614
        "    -enableJavadoc     consider references in javadoc\n" +
1640
        "    -enableJavadoc     consider references in javadoc\n" +
1615
        "    -Xemacs            used to enable emacs-style output in the console.\n" +
1641
        "    -Xemacs            used to enable emacs-style output in the console.\n" +
1616
        "                       It does not affect the xml log output\n" +
1642
        "                       It does not affect the xml log output\n" +
1643
        "    -nonNullByDefault  for annotation based null analysis assume nonnull\n" + 
1644
        "                       as the global default\n" + 
1617
        " \n" +
1645
        " \n" +
1618
        "    -? -help           print this help message\n" +
1646
        "    -? -help           print this help message\n" +
1619
        "    -v -version        print compiler version\n" +
1647
        "    -v -version        print compiler version\n" +
Lines 1702-1707 Link Here
1702
        "      nls                  string literal lacking non-nls tag //$NON-NLS-<n>$\n" + 
1730
        "      nls                  string literal lacking non-nls tag //$NON-NLS-<n>$\n" + 
1703
        "      noEffectAssign     + assignment without effect\n" + 
1731
        "      noEffectAssign     + assignment without effect\n" + 
1704
        "      null                 potential missing or redundant null check\n" + 
1732
        "      null                 potential missing or redundant null check\n" + 
1733
        "      nullAnnot(<annot. names separated by |>) + annotation based null analysis,\n" +
1734
        "                           nonnull|nullable|nonnullbydefault annotation types\n" +
1735
        "                           optionally specified using fully qualified names\n" +
1705
        "      nullDereference    + missing null check\n" + 
1736
        "      nullDereference    + missing null check\n" + 
1706
        "      nullFields    	  + null analysis for fields\n" + 
1737
        "      nullFields    	  + null analysis for fields\n" + 
1707
        "      over-ann             missing @Override annotation (superclass)\n" + 
1738
        "      over-ann             missing @Override annotation (superclass)\n" + 
Lines 12384-12387 Link Here
12384
		"1 problem (1 warning)", 
12415
		"1 problem (1 warning)", 
12385
		true);
12416
		true);
12386
}
12417
}
12418
12419
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342
12420
// -warn option - regression tests to check option nullAnnot (with args)
12421
// Null warnings because of annotations - custom annotation types used - challenging various kinds of diagnostics
12422
public void test312_warn_options() {
12423
	this.runConformTest(
12424
		new String[] {
12425
				"p/X.java",
12426
				"package p;\n" +
12427
				"import static java.lang.annotation.ElementType.*;\n" +
12428
				"import java.lang.annotation.*;\n" +
12429
				"@SuppressWarnings(\"unused\")\n" +
12430
				"public class X {\n" +
12431
				"	public void test() { Object o = null; o.toString();}\n" +
12432
				"  @NonNull Object foo(@Nullable Object o, @NonNull Object o2) {\n" +
12433
				"    if (o.toString() == \"\"){ return null;}\n" +
12434
				"    if (o2 == null) {}\n" +
12435
				"    goo(null).toString();\n" +
12436
				"	 Object local = null;\n" +
12437
				"	 o.toString();\n" +
12438
				"	 return null;\n" +
12439
				"  }\n" +
12440
				"  @Nullable Object goo(@NonNull Object o2) {\n" +
12441
				"    return new Object();\n" +
12442
				"  }\n" +
12443
				"  @NonNullByDefault Object hoo(Object o2) {\n" +
12444
				"    if (o2 == null){}\n" +
12445
				"    if (o2 == null){\n" +
12446
				"	    return null;\n" +
12447
				"	 }\n" +
12448
				"	 return new Object();\n" +
12449
				"  }\n" +
12450
				"}\n" +
12451
				"@Documented\n" +
12452
				"@Retention(RetentionPolicy.CLASS)\n" +
12453
				"@Target({ METHOD, PARAMETER })\n" +
12454
				"@interface NonNull{\n" +
12455
				"}\n" +
12456
				"@Documented\n" +
12457
				"@Retention(RetentionPolicy.CLASS)\n" +
12458
				"@Target({ METHOD, PARAMETER })\n" +
12459
				"@interface Nullable{\n" +
12460
				"}\n" +
12461
				"@Documented\n" +
12462
				"@Retention(RetentionPolicy.CLASS)\n" +
12463
				"@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })\n" +
12464
				"@interface NonNullByDefault{\n" +
12465
				"}"
12466
		},
12467
		"\"" + OUTPUT_DIR +  File.separator + "p" + File.separator + "X.java\""
12468
//		+ " -sourcepath \"" + OUTPUT_DIR + "\""
12469
		+ " -1.5"
12470
		+ " -warn:+nullAnnot(p.NonNull|p.Nullable|p.NonNullByDefault) -warn:+null -proc:none -d \"" + OUTPUT_DIR + "\"",
12471
		"",
12472
		"----------\n" + 
12473
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 6)\n" + 
12474
		"	public void test() { Object o = null; o.toString();}\n" + 
12475
		"	                                      ^\n" + 
12476
		"Null pointer access: The variable o can only be null at this location\n" + 
12477
		"----------\n" + 
12478
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 8)\n" + 
12479
		"	if (o.toString() == \"\"){ return null;}\n" + 
12480
		"	    ^\n" + 
12481
		"Potential null pointer access: The variable o may be null at this location\n" + 
12482
		"----------\n" + 
12483
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 8)\n" + 
12484
		"	if (o.toString() == \"\"){ return null;}\n" + 
12485
		"	                                ^^^^\n" + 
12486
		"Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + 
12487
		"----------\n" + 
12488
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + 
12489
		"	if (o2 == null) {}\n" + 
12490
		"	    ^^\n" + 
12491
		"Null comparison always yields false: The variable o2 cannot be null at this location\n" + 
12492
		"----------\n" + 
12493
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 10)\n" + 
12494
		"	goo(null).toString();\n" + 
12495
		"	^^^^^^^^^\n" + 
12496
		"Potential null pointer access: The method goo(Object) may return null\n" + 
12497
		"----------\n" + 
12498
		"6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 10)\n" + 
12499
		"	goo(null).toString();\n" + 
12500
		"	    ^^^^\n" + 
12501
		"Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + 
12502
		"----------\n" + 
12503
		"7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 13)\n" + 
12504
		"	return null;\n" + 
12505
		"	       ^^^^\n" + 
12506
		"Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + 
12507
		"----------\n" + 
12508
		"8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 19)\n" + 
12509
		"	if (o2 == null){}\n" + 
12510
		"	    ^^\n" + 
12511
		"Null comparison always yields false: The variable o2 cannot be null at this location\n" + 
12512
		"----------\n" + 
12513
		"9. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 20)\n" + 
12514
		"	if (o2 == null){\n" + 
12515
		"	    ^^\n" + 
12516
		"Null comparison always yields false: The variable o2 cannot be null at this location\n" + 
12517
		"----------\n" + 
12518
		"9 problems (9 warnings)", 
12519
		true);
12520
}
12521
12522
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342
12523
// -warn option - regression tests to check option nullAnnot (no args)
12524
// Null warnings because of annotations, null spec violations
12525
public void test313_warn_options() {
12526
	this.runConformTest(
12527
		new String[] {
12528
				"p/X.java",
12529
				"package p;\n" +
12530
				"import org.eclipse.jdt.annotation.*;\n" +
12531
				"public class X {\n" +
12532
				"  @NonNull Object foo(@Nullable Object o, @NonNull Object o2) {\n" +
12533
				"	 return this;\n" +
12534
				"  }\n" +
12535
				"}\n" +
12536
				"class Y extends X {\n" +
12537
				"    @Nullable Object foo(Object o, Object o2) { return null; }\n" +
12538
				"}\n",
12539
				"org/eclipse/jdt/annotation/NonNull.java",
12540
				NONNULL_ANNOTATION_CONTENT,
12541
				"org/eclipse/jdt/annotation/Nullable.java",
12542
				NULLABLE_ANNOTATION_CONTENT,
12543
				"org/eclipse/jdt/annotation/NonNullByDefault.java",				
12544
				NONNULL_BY_DEFAULT_ANNOTATION_CONTENT
12545
		},
12546
		"\"" + OUTPUT_DIR +  File.separator + "p" + File.separator + "X.java\""
12547
		+ " -sourcepath \"" + OUTPUT_DIR + "\""
12548
		+ " -1.5"
12549
		+ " -warn:+nullAnnot -warn:-null -proc:none -d \"" + OUTPUT_DIR + "\"",
12550
		"",
12551
		"----------\n" + 
12552
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + 
12553
		"	@Nullable Object foo(Object o, Object o2) { return null; }\n" + 
12554
		"	^^^^^^^^^^^^^^^^\n" + 
12555
		"The return type is incompatible with the @NonNull return from X.foo(Object, Object)\n" + 
12556
		"----------\n" + 
12557
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + 
12558
		"	@Nullable Object foo(Object o, Object o2) { return null; }\n" + 
12559
		"	                     ^^^^^^\n" + 
12560
		"Missing nullable annotation: inherited method from X declares this parameter as @Nullable\n" + 
12561
		"----------\n" + 
12562
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + 
12563
		"	@Nullable Object foo(Object o, Object o2) { return null; }\n" + 
12564
		"	                               ^^^^^^\n" + 
12565
		"Missing non-null annotation: inherited method from X declares this parameter as @NonNull\n" + 
12566
		"----------\n" + 
12567
		"3 problems (3 warnings)", 
12568
		true);
12569
}
12570
12571
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342
12572
// -err option - regression tests to check option nullAnnot
12573
// Null warnings because of annotations, null spec violations configured as errors
12574
public void test314_warn_options() {
12575
	this.runNegativeTest(
12576
		new String[] {
12577
				"p/X.java",
12578
				"package p;\n" +
12579
				"import org.eclipse.jdt.annotation.*;\n" +
12580
				"public class X {\n" +
12581
				"  @NonNull Object foo(@Nullable Object o, @NonNull Object o2) {\n" +
12582
				"	 return this;\n" +
12583
				"  }\n" +
12584
				"}\n" +
12585
				"class Y extends X {\n" +
12586
				"    @Nullable Object foo(Object o, Object o2) { return null; }\n" +
12587
				"}\n",
12588
				"org/eclipse/jdt/annotation/NonNull.java",
12589
				NONNULL_ANNOTATION_CONTENT,
12590
				"org/eclipse/jdt/annotation/Nullable.java",
12591
				NULLABLE_ANNOTATION_CONTENT,
12592
				"org/eclipse/jdt/annotation/NonNullByDefault.java",				
12593
				NONNULL_BY_DEFAULT_ANNOTATION_CONTENT
12594
		},
12595
		"\"" + OUTPUT_DIR +  File.separator + "p" + File.separator + "X.java\""
12596
		+ " -sourcepath \"" + OUTPUT_DIR + "\""
12597
		+ " -1.5"
12598
		+ " -err:+nullAnnot -warn:-null -proc:none -d \"" + OUTPUT_DIR + "\"",
12599
		"",
12600
		"----------\n" + 
12601
		"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + 
12602
		"	@Nullable Object foo(Object o, Object o2) { return null; }\n" + 
12603
		"	^^^^^^^^^^^^^^^^\n" + 
12604
		"The return type is incompatible with the @NonNull return from X.foo(Object, Object)\n" + 
12605
		"----------\n" + 
12606
		"2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + 
12607
		"	@Nullable Object foo(Object o, Object o2) { return null; }\n" + 
12608
		"	                     ^^^^^^\n" + 
12609
		"Missing nullable annotation: inherited method from X declares this parameter as @Nullable\n" + 
12610
		"----------\n" + 
12611
		"3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + 
12612
		"	@Nullable Object foo(Object o, Object o2) { return null; }\n" + 
12613
		"	                               ^^^^^^\n" + 
12614
		"Missing non-null annotation: inherited method from X declares this parameter as @NonNull\n" + 
12615
		"----------\n" + 
12616
		"3 problems (3 errors)", 
12617
		true);
12618
}
12619
12620
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342
12621
// -warn option - regression tests to check option nullAnnot
12622
// Null warnings because of annotations, global nonNullByDefault
12623
public void test315_warn_options() {
12624
	this.runConformTest(
12625
		new String[] {
12626
				"p/X.java",
12627
				"package p;\n" +
12628
				"import org.eclipse.jdt.annotation.*;\n" +
12629
				"@SuppressWarnings(\"unused\")\n" +
12630
				"public class X {\n" +
12631
				"  Object foo(@Nullable Object o, Object o2) {\n" +
12632
				"    if (o.toString() == \"\"){ return null;}\n" +
12633
				"    if (o2 == null) {}\n" +
12634
				"    goo(null).toString();\n" +
12635
				"	 return null;\n" +
12636
				"  }\n" +
12637
				"  @Nullable Object goo(Object o2) {\n" +
12638
				"    return new Object();\n" +
12639
				"  }\n" +
12640
				"  @NonNullByDefault Object hoo(Object o2) {\n" + // redundant
12641
				"    if (o2 == null)\n" +
12642
				"	    return null;\n" +
12643
				"    return this;\n" +
12644
				"  }\n" +
12645
				"}\n",
12646
				"org/eclipse/jdt/annotation/NonNull.java",
12647
				NONNULL_ANNOTATION_CONTENT,
12648
				"org/eclipse/jdt/annotation/Nullable.java",
12649
				NULLABLE_ANNOTATION_CONTENT,
12650
				"org/eclipse/jdt/annotation/NonNullByDefault.java",				
12651
				NONNULL_BY_DEFAULT_ANNOTATION_CONTENT
12652
		},
12653
		"\"" + OUTPUT_DIR +  File.separator + "p" + File.separator + "X.java\""
12654
		+ " -sourcepath \"" + OUTPUT_DIR + "\""
12655
		+ " -1.5"
12656
		+ " -warn:+nullAnnot -warn:+null -nonNullByDefault -proc:none -d \"" + OUTPUT_DIR + "\"",
12657
		"",
12658
		"----------\n" + 
12659
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 6)\n" + 
12660
		"	if (o.toString() == \"\"){ return null;}\n" + 
12661
		"	    ^\n" + 
12662
		"Potential null pointer access: The variable o may be null at this location\n" + 
12663
		"----------\n" + 
12664
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 6)\n" + 
12665
		"	if (o.toString() == \"\"){ return null;}\n" + 
12666
		"	                                ^^^^\n" + 
12667
		"Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + 
12668
		"----------\n" + 
12669
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 7)\n" + 
12670
		"	if (o2 == null) {}\n" + 
12671
		"	    ^^\n" + 
12672
		"Null comparison always yields false: The variable o2 cannot be null at this location\n" + 
12673
		"----------\n" + 
12674
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 8)\n" + 
12675
		"	goo(null).toString();\n" + 
12676
		"	^^^^^^^^^\n" + 
12677
		"Potential null pointer access: The method goo(Object) may return null\n" + 
12678
		"----------\n" + 
12679
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 8)\n" + 
12680
		"	goo(null).toString();\n" + 
12681
		"	    ^^^^\n" + 
12682
		"Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + 
12683
		"----------\n" + 
12684
		"6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + 
12685
		"	return null;\n" + 
12686
		"	       ^^^^\n" + 
12687
		"Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + 
12688
		"----------\n" + 
12689
		"7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 14)\n" + 
12690
		"	@NonNullByDefault Object hoo(Object o2) {\n" + 
12691
		"	^^^^^^^^^^^^^^^^^\n" + 
12692
		"Nullness default is redundant with the global default\n" + 
12693
		"----------\n" + 
12694
		"8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 15)\n" + 
12695
		"	if (o2 == null)\n" + 
12696
		"	    ^^\n" + 
12697
		"Null comparison always yields false: The variable o2 cannot be null at this location\n" + 
12698
		"----------\n" + 
12699
		"8 problems (8 warnings)", 
12700
		true);
12701
}
12702
12703
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342
12704
// -warn option - regression tests to check option nullAnnot
12705
// option syntax error
12706
public void test316_warn_options() {
12707
	this.runNegativeTest(
12708
		new String[] {
12709
				"p/X.java",
12710
				"package p;\n" +
12711
				"import org.eclipse.jdt.annotation.*;\n" +
12712
				"@SuppressWarnings(\"unused\")\n" +
12713
				"public class X {}\n",
12714
				"org/eclipse/jdt/annotation/NonNull.java",
12715
				NONNULL_ANNOTATION_CONTENT,
12716
				"org/eclipse/jdt/annotation/Nullable.java",
12717
				NULLABLE_ANNOTATION_CONTENT,
12718
				"org/eclipse/jdt/annotation/NonNullByDefault.java",				
12719
				NONNULL_BY_DEFAULT_ANNOTATION_CONTENT
12720
		},
12721
		"\"" + OUTPUT_DIR +  File.separator + "p" + File.separator + "X.java\""
12722
		+ " -sourcepath \"" + OUTPUT_DIR + "\""
12723
		+ " -1.5"
12724
		+ " -warn:+nullAnnot(foo|bar) -warn:+null -nonNullByDefault -proc:none -d \"" + OUTPUT_DIR + "\"",
12725
		"",
12726
		"Token nullAnnot(foo|bar) is not in the expected format \"nullAnnot(<non null annotation name> | <nullable annotation name> | <non-null by default annotation name>)\"\n", 
12727
		true);
12728
}
12387
}
12729
}
(-)a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java (-1 / +36 lines)
Lines 14-19 Link Here
14
 *     							bug 236385 - [compiler] Warn for potential programming problem if an object is created but not used
14
 *     							bug 236385 - [compiler] Warn for potential programming problem if an object is created but not used
15
 *     							bug 295551 - Add option to automatically promote all warnings to errors
15
 *     							bug 295551 - Add option to automatically promote all warnings to errors
16
 *     							bug 359721 - [options] add command line option for new warning token "resource"
16
 *     							bug 359721 - [options] add command line option for new warning token "resource"
17
 *								bug 365208 - [compiler][batch] command line options for annotation based null analysis
17
 *******************************************************************************/
18
 *******************************************************************************/
18
package org.eclipse.jdt.internal.compiler.batch;
19
package org.eclipse.jdt.internal.compiler.batch;
19
20
Lines 2379-2384 Link Here
2379
					mode = INSIDE_WARNINGS_PROPERTIES;
2380
					mode = INSIDE_WARNINGS_PROPERTIES;
2380
					continue;
2381
					continue;
2381
				}
2382
				}
2383
				if (currentArg.equals("-nonNullByDefault")) { //$NON-NLS-1$
2384
					this.options.put(CompilerOptions.OPTION_NonNullIsDefault, CompilerOptions.ENABLED);
2385
					continue;
2386
				}
2382
				break;
2387
				break;
2383
			case INSIDE_TARGET :
2388
			case INSIDE_TARGET :
2384
				if (this.didSpecifyTarget) {
2389
				if (this.didSpecifyTarget) {
Lines 3409-3415 Link Here
3409
						CompilerOptions.OPTION_IncludeFieldsInNullAnalysis,
3414
						CompilerOptions.OPTION_IncludeFieldsInNullAnalysis,
3410
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3415
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3411
				return;
3416
				return;
3412
			} 
3417
			} else if (token.startsWith("nullAnnot")) { //$NON-NLS-1$
3418
				String annotationNames = Util.EMPTY_STRING;
3419
				int start = token.indexOf('(');
3420
				int end = token.indexOf(')');
3421
				String nonNullAnnotName = null, nullableAnnotName = null, nonNullByDefaultAnnotName = null;
3422
				if (isEnabling && start >= 0 && end >= 0 && start < end){
3423
					annotationNames = token.substring(start+1, end).trim();
3424
					int separator1 = annotationNames.indexOf('|');
3425
					if (separator1 == -1) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$
3426
					nonNullAnnotName = annotationNames.substring(0, separator1).trim();
3427
					if (nonNullAnnotName.length() == 0) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$
3428
					int separator2 = annotationNames.indexOf('|', separator1 + 1);
3429
					if (separator2 == -1) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$
3430
					nullableAnnotName = annotationNames.substring(separator1 + 1, separator2).trim();
3431
					if (nullableAnnotName.length() == 0) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$
3432
					nonNullByDefaultAnnotName = annotationNames.substring(separator2 + 1).trim();
3433
					if (nonNullByDefaultAnnotName.length() == 0) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$
3434
					this.options.put(CompilerOptions.OPTION_NonNullAnnotationName, nonNullAnnotName);
3435
					this.options.put(CompilerOptions.OPTION_NullableAnnotationName, nullableAnnotName);
3436
					this.options.put(CompilerOptions.OPTION_NonNullByDefaultAnnotationName, nonNullByDefaultAnnotName);
3437
				}
3438
				this.options.put(
3439
						CompilerOptions.OPTION_AnnotationBasedNullAnalysis,
3440
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3441
				setSeverity(CompilerOptions.OPTION_ReportNullSpecViolation, severity, isEnabling);
3442
				setSeverity(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, severity, isEnabling);
3443
				setSeverity(CompilerOptions.OPTION_ReportNullSpecInsufficientInfo, severity, isEnabling);
3444
				setSeverity(CompilerOptions.OPTION_ReportRedundantNullAnnotation, severity, isEnabling);
3445
				return;
3446
			}
3447
			
3413
			break;
3448
			break;
3414
		case 'o' :
3449
		case 'o' :
3415
			if (token.equals("over-sync") /*|| token.equals("syncOverride")*/) { //$NON-NLS-1$ 
3450
			if (token.equals("over-sync") /*|| token.equals("syncOverride")*/) { //$NON-NLS-1$ 
(-)a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (+9 lines)
Lines 12-17 Link Here
12
#								bug 236385 - [compiler] Warn for potential programming problem if an object is created but not used
12
#								bug 236385 - [compiler] Warn for potential programming problem if an object is created but not used
13
#								bug 295551 - Add option to automatically promote all warnings to errors
13
#								bug 295551 - Add option to automatically promote all warnings to errors
14
#								bug 359721 - [options] add command line option for new warning token "resource"
14
#								bug 359721 - [options] add command line option for new warning token "resource"
15
#								bug 365208 - [compiler][batch] command line options for annotation based null analysis
15
###############################################################################
16
###############################################################################
16
### JavaBatchCompiler messages.
17
### JavaBatchCompiler messages.
17
18
Lines 102-107 Link Here
102
configure.multipleencodings=Multiple encoding specified: {1}. The default encoding has been set to {0}
103
configure.multipleencodings=Multiple encoding specified: {1}. The default encoding has been set to {0}
103
configure.differentencodings=Found encoding {0}. Different encodings were specified: {1}
104
configure.differentencodings=Found encoding {0}. Different encodings were specified: {1}
104
configure.differentencoding=Found encoding {0}. A different encoding was specified: {1}
105
configure.differentencoding=Found encoding {0}. A different encoding was specified: {1}
106
107
### null annotations
108
configure.invalidNullAnnot = Token {0} is not in the expected format "nullAnnot(<non null annotation name> | <nullable annotation name> | <non-null by default annotation name>)"
105
109
106
### requestor
110
### requestor
107
requestor.error = {0}. ERROR in {1}
111
requestor.error = {0}. ERROR in {1}
Lines 247-252 Link Here
247
\    -enableJavadoc     consider references in javadoc\n\
251
\    -enableJavadoc     consider references in javadoc\n\
248
\    -Xemacs            used to enable emacs-style output in the console.\n\
252
\    -Xemacs            used to enable emacs-style output in the console.\n\
249
\                       It does not affect the xml log output\n\
253
\                       It does not affect the xml log output\n\
254
\    -nonNullByDefault  for annotation based null analysis assume nonnull\n\
255
\                       as the global default\n\
250
\ \n\
256
\ \n\
251
\    -? -help           print this help message\n\
257
\    -? -help           print this help message\n\
252
\    -v -version        print compiler version\n\
258
\    -v -version        print compiler version\n\
Lines 306-311 Link Here
306
\      nls                  string literal lacking non-nls tag //$NON-NLS-<n>$\n\
312
\      nls                  string literal lacking non-nls tag //$NON-NLS-<n>$\n\
307
\      noEffectAssign     + assignment without effect\n\
313
\      noEffectAssign     + assignment without effect\n\
308
\      null                 potential missing or redundant null check\n\
314
\      null                 potential missing or redundant null check\n\
315
\      nullAnnot(<annot. names separated by |>) + annotation based null analysis,\n\
316
\                           nonnull|nullable|nonnullbydefault annotation types\n\
317
\                           optionally specified using fully qualified names\n\
309
\      nullDereference    + missing null check\n\
318
\      nullDereference    + missing null check\n\
310
\      nullFields    	  + null analysis for fields\n\
319
\      nullFields    	  + null analysis for fields\n\
311
\      over-ann             missing @Override annotation (superclass)\n\
320
\      over-ann             missing @Override annotation (superclass)\n\

Return to bug 365208