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 / +70 lines)
Lines 52-58 Link Here
52
	private static final Main MAIN = new Main(null/*outWriter*/, null/*errWriter*/, false/*systemExit*/, null/*options*/, null/*progress*/);
52
	private static final Main MAIN = new Main(null/*outWriter*/, null/*errWriter*/, false/*systemExit*/, null/*options*/, null/*progress*/);
53
53
54
	static {
54
	static {
55
//		TESTS_NAMES = new String[] { "test295_warn_options" };
55
		TESTS_NAMES = new String[] { "test312_warn_options" };
56
//		TESTS_NUMBERS = new int[] { 306 };
56
//		TESTS_NUMBERS = new int[] { 306 };
57
//		TESTS_RANGE = new int[] { 298, -1 };
57
//		TESTS_RANGE = new int[] { 298, -1 };
58
	}
58
	}
Lines 12384-12387 Link Here
12384
		"1 problem (1 warning)", 
12384
		"1 problem (1 warning)", 
12385
		true);
12385
		true);
12386
}
12386
}
12387
12388
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342
12389
// -warn option - regression tests to check option nullAnnot
12390
// Null warnings because of annotations
12391
public void test312_warn_options() {
12392
	this.runConformTest(
12393
		new String[] {
12394
				"X.java",
12395
				"import static java.lang.annotation.ElementType.CONSTRUCTOR;\n" +
12396
				"import static java.lang.annotation.ElementType.METHOD;\n" +
12397
				"import static java.lang.annotation.ElementType.PACKAGE;\n" +
12398
				"import static java.lang.annotation.ElementType.PARAMETER;\n" +
12399
				"import static java.lang.annotation.ElementType.TYPE;\n" +
12400
				"import java.lang.annotation.Documented;\n" +
12401
				"import java.lang.annotation.Retention;\n" +
12402
				"import java.lang.annotation.RetentionPolicy;\n" +
12403
				"import java.lang.annotation.Target;\n" +
12404
				"public class X {\n" +
12405
				"	public void test() { Object o = null; o.toString();}\n" +
12406
				"  @NonNull Object foo(@Nullable Object o, @NonNull Object o2) {\n" +
12407
				"    if (o.toString() == \"\"){ return null;}\n" +
12408
				"    if (o2 == null) {}\n" +
12409
				"    goo(null).toString();\n" +
12410
				"	 Object local = null;\n" +
12411
				"	 o.toString();\n" +
12412
				"    Zork z;\n" +
12413
				"	 return null;\n" +
12414
				"  }\n" +
12415
				"  @Nullable Object goo(@NonNull Object o2) {\n" +
12416
				"    return new Object();\n" +
12417
				"  }\n" +
12418
				"  @NonNullByDefault Object hoo(Object o2) {\n" +
12419
				"    if (o2 == null){}\n" +
12420
				"    if (o2 == null){\n" +
12421
				"	    return null;\n" +
12422
				"	 }\n" +
12423
				"	 return new Object();\n" +
12424
				"  }\n" +
12425
				"}\n"+
12426
				"@Documented\n" +
12427
				"@Retention(RetentionPolicy.CLASS)\n" +
12428
				"@Target({ METHOD, PARAMETER })\n" +
12429
				"@interface NonNull{\n" +
12430
				"}\n" +
12431
				"@Documented\n" +
12432
				"@Retention(RetentionPolicy.CLASS)\n" +
12433
				"@Target({ METHOD, PARAMETER })\n" +
12434
				"@interface Nullable{\n" +
12435
				"}\n" +
12436
				"@Documented\n" +
12437
				"@Retention(RetentionPolicy.CLASS)\n" +
12438
				"@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })\n" +
12439
				"@interface NonNullByDefault{\n" +
12440
				"}"
12441
		},
12442
		"\"" + OUTPUT_DIR +  File.separator + "X.java\""
12443
//		+ " -sourcepath \"" + OUTPUT_DIR + "\""
12444
		+ " -1.5"
12445
		+ " -warn:+nullAnnot(p.NonNull|p.Nullable|p.NonNullByDefault) -proc:none -d \"" + OUTPUT_DIR + "\"",
12446
		"",
12447
		"----------\n" + 
12448
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + 
12449
		"	if (o == null && o.toString() == \"\"){}\n" + 
12450
		"	                 ^\n" + 
12451
		"Potential null pointer access: The field o may be null at this location\n" + 
12452
		"----------\n" + 
12453
		"1 problem (1 warning)", 
12454
		true);
12455
}
12387
}
12456
}
(-)a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java (-1 / +34 lines)
Lines 3409-3415 Link Here
3409
						CompilerOptions.OPTION_IncludeFieldsInNullAnalysis,
3409
						CompilerOptions.OPTION_IncludeFieldsInNullAnalysis,
3410
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3410
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3411
				return;
3411
				return;
3412
			} 
3412
			} else if (token.startsWith("nullAnnot")) { //$NON-NLS-1$
3413
				String unusedWarningExcludingAnnotations = Util.EMPTY_STRING;
3414
				int start = token.indexOf('(');
3415
				int end = token.indexOf(')');
3416
				String nonNullAnnotName = null, nullableAnnotName = null, nonNullByDefaultAnnotName = null;
3417
				if (isEnabling && start >= 0 && end >= 0 && start < end){
3418
					unusedWarningExcludingAnnotations = token.substring(start+1, end).trim();
3419
					int separator1 = unusedWarningExcludingAnnotations.indexOf('|');
3420
					if (separator1 == -1) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$
3421
					nonNullAnnotName = unusedWarningExcludingAnnotations.substring(0, separator1).trim();
3422
					if (nonNullAnnotName.length() == 0) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$
3423
					int separator2 = unusedWarningExcludingAnnotations.indexOf('|', separator1 + 1);
3424
					if (separator2 == -1) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$
3425
					nullableAnnotName = unusedWarningExcludingAnnotations.substring(separator1 + 1, separator2).trim();
3426
					if (nullableAnnotName.length() == 0) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$
3427
					nonNullByDefaultAnnotName = unusedWarningExcludingAnnotations.substring(separator2 + 1).trim();
3428
					if (nonNullByDefaultAnnotName.length() == 0) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$
3429
					this.options.put(
3430
							CompilerOptions.OPTION_NonNullAnnotationName, nonNullAnnotName);
3431
					this.options.put(
3432
							CompilerOptions.OPTION_NullableAnnotationName, nonNullAnnotName);
3433
					this.options.put(
3434
							CompilerOptions.OPTION_NonNullByDefaultAnnotationName, nonNullAnnotName);
3435
				}
3436
				this.options.put(
3437
						CompilerOptions.OPTION_AnnotationBasedNullAnalysis,
3438
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3439
				setSeverity(CompilerOptions.OPTION_ReportNullSpecViolation, severity, isEnabling);
3440
				setSeverity(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, severity, isEnabling);
3441
				setSeverity(CompilerOptions.OPTION_ReportNullSpecInsufficientInfo, severity, isEnabling);
3442
				setSeverity(CompilerOptions.OPTION_ReportRedundantNullAnnotation, severity, isEnabling);
3443
				return;
3444
			}  
3445
			
3413
			break;
3446
			break;
3414
		case 'o' :
3447
		case 'o' :
3415
			if (token.equals("over-sync") /*|| token.equals("syncOverride")*/) { //$NON-NLS-1$ 
3448
			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 (+4 lines)
Lines 103-108 Link Here
103
configure.differentencodings=Found encoding {0}. Different encodings were specified: {1}
103
configure.differentencodings=Found encoding {0}. Different encodings were specified: {1}
104
configure.differentencoding=Found encoding {0}. A different encoding was specified: {1}
104
configure.differentencoding=Found encoding {0}. A different encoding was specified: {1}
105
105
106
### null annotations
107
configure.invalidNullAnnot = Token {0} is not in the expected format "nullAnnot(<non null annotation name> | <nullable annotation name> | <non-null by default annotation name>)"
108
106
### requestor
109
### requestor
107
requestor.error = {0}. ERROR in {1}
110
requestor.error = {0}. ERROR in {1}
108
requestor.warning = {0}. WARNING in {1}
111
requestor.warning = {0}. WARNING in {1}
Lines 306-311 Link Here
306
\      nls                  string literal lacking non-nls tag //$NON-NLS-<n>$\n\
309
\      nls                  string literal lacking non-nls tag //$NON-NLS-<n>$\n\
307
\      noEffectAssign     + assignment without effect\n\
310
\      noEffectAssign     + assignment without effect\n\
308
\      null                 potential missing or redundant null check\n\
311
\      null                 potential missing or redundant null check\n\
312
\      nullAnnot(qualified annot. names separated by '|') + null analysis with annot.\n\
309
\      nullDereference    + missing null check\n\
313
\      nullDereference    + missing null check\n\
310
\      nullFields    	  + null analysis for fields\n\
314
\      nullFields    	  + null analysis for fields\n\
311
\      over-ann             missing @Override annotation (superclass)\n\
315
\      over-ann             missing @Override annotation (superclass)\n\
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (-1 / +4 lines)
Lines 846-856 Link Here
846
			case NullReference :
846
			case NullReference :
847
			case PotentialNullReference :
847
			case PotentialNullReference :
848
			case RedundantNullCheck :
848
			case RedundantNullCheck :
849
				return "null"; //$NON-NLS-1$
849
			case NullSpecViolation :
850
			case NullSpecViolation :
850
			case PotentialNullSpecViolation :
851
			case PotentialNullSpecViolation :
851
			case NullSpecInsufficientInfo :
852
			case NullSpecInsufficientInfo :
852
			case RedundantNullAnnotation :
853
			case RedundantNullAnnotation :
853
				return "null"; //$NON-NLS-1$
854
				return "nullAnnot"; //$NON-NLS-1$
854
			case FallthroughCase :
855
			case FallthroughCase :
855
				return "fallthrough"; //$NON-NLS-1$
856
				return "fallthrough"; //$NON-NLS-1$
856
			case OverridingMethodWithoutSuperInvocation :
857
			case OverridingMethodWithoutSuperInvocation :
Lines 917-922 Link Here
917
					return IrritantSet.NLS;
918
					return IrritantSet.NLS;
918
				if ("null".equals(warningToken)) //$NON-NLS-1$
919
				if ("null".equals(warningToken)) //$NON-NLS-1$
919
					return IrritantSet.NULL;
920
					return IrritantSet.NULL;
921
				if ("nullAnnot".equals(warningToken)) //$NON-NLS-1$
922
					return IrritantSet.NULLANNOT;
920
				break;
923
				break;
921
			case 'r' :
924
			case 'r' :
922
				if ("rawtypes".equals(warningToken)) //$NON-NLS-1$
925
				if ("rawtypes".equals(warningToken)) //$NON-NLS-1$
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java (-3 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 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 50-55 Link Here
50
	public static final IrritantSet INCOMPLETE_SWITCH = new IrritantSet(CompilerOptions.IncompleteEnumSwitch);
50
	public static final IrritantSet INCOMPLETE_SWITCH = new IrritantSet(CompilerOptions.IncompleteEnumSwitch);
51
	public static final IrritantSet NLS = new IrritantSet(CompilerOptions.NonExternalizedString);
51
	public static final IrritantSet NLS = new IrritantSet(CompilerOptions.NonExternalizedString);
52
	public static final IrritantSet NULL = new IrritantSet(CompilerOptions.NullReference);
52
	public static final IrritantSet NULL = new IrritantSet(CompilerOptions.NullReference);
53
	public static final IrritantSet NULLANNOT = new IrritantSet(CompilerOptions.NullSpecViolation);
53
	public static final IrritantSet RAW = new IrritantSet(CompilerOptions.RawTypeReference);
54
	public static final IrritantSet RAW = new IrritantSet(CompilerOptions.RawTypeReference);
54
	public static final IrritantSet RESTRICTION = new IrritantSet(CompilerOptions.ForbiddenReference);
55
	public static final IrritantSet RESTRICTION = new IrritantSet(CompilerOptions.ForbiddenReference);
55
	public static final IrritantSet SERIAL = new IrritantSet(CompilerOptions.MissingSerialVersion);
56
	public static final IrritantSet SERIAL = new IrritantSet(CompilerOptions.MissingSerialVersion);
Lines 119-126 Link Here
119
			.set(CompilerOptions.TypeHiding);
120
			.set(CompilerOptions.TypeHiding);
120
		NULL
121
		NULL
121
			.set(CompilerOptions.PotentialNullReference)
122
			.set(CompilerOptions.PotentialNullReference)
122
			.set(CompilerOptions.RedundantNullCheck)
123
			.set(CompilerOptions.RedundantNullCheck);
123
			.set(CompilerOptions.NullSpecViolation)
124
		
125
		NULLANNOT
124
			.set(CompilerOptions.PotentialNullSpecViolation)
126
			.set(CompilerOptions.PotentialNullSpecViolation)
125
			.set(CompilerOptions.NullSpecInsufficientInfo)
127
			.set(CompilerOptions.NullSpecInsufficientInfo)
126
			.set(CompilerOptions.RedundantNullAnnotation);
128
			.set(CompilerOptions.RedundantNullAnnotation);

Return to bug 365208