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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java (+2 lines)
Lines 62-67 Link Here
62
			default:
62
			default:
63
				flowInfo.markAsDefinitelyUnknown(this.binding);
63
				flowInfo.markAsDefinitelyUnknown(this.binding);
64
		}
64
		}
65
		if (isNonNullAnnotated(currentScope, binding.getAnnotations()) && nullStatus != FlowInfo.NON_NULL)
66
			binding.declaringScope.problemReporter().localCannotBeAssignedWithPotentiallyNull(binding, initialization);
65
		// no need to inform enclosing try block since its locals won't get
67
		// no need to inform enclosing try block since its locals won't get
66
		// known by the finally block
68
		// known by the finally block
67
	}
69
	}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java (+23 lines)
Lines 28-37 Link Here
28
		if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) {
28
		if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) {
29
			checkVariableComparison(scope, flowContext, flowInfo, initsWhenTrue, initsWhenFalse, local, right.nullStatus(flowInfo), this.left);
29
			checkVariableComparison(scope, flowContext, flowInfo, initsWhenTrue, initsWhenFalse, local, right.nullStatus(flowInfo), this.left);
30
		}
30
		}
31
		// TODO: if allowed, simpler check would be for left and right nullStatus equality (for != UNKNOW)
32
		Expression tmp = left;
33
		while (tmp instanceof CastExpression)
34
			tmp = ((CastExpression)tmp).expression;
35
		if (tmp instanceof MessageSend) {
36
			MessageSend ms = (MessageSend)tmp;
37
			int rightNullStatus = right.nullStatus(flowInfo);
38
			if ((rightNullStatus == FlowInfo.NULL
39
					|| rightNullStatus == FlowInfo.NON_NULL)
40
					&& isNonNullAnnotated(scope, ms.binding.getAnnotations()))
41
				scope.problemReporter().cannotReturnPotentiallyNullExpression(left);
42
		}
31
		local = this.right.localVariableBinding();
43
		local = this.right.localVariableBinding();
32
		if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) {
44
		if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) {
33
			checkVariableComparison(scope, flowContext, flowInfo, initsWhenTrue, initsWhenFalse, local, left.nullStatus(flowInfo), this.right);
45
			checkVariableComparison(scope, flowContext, flowInfo, initsWhenTrue, initsWhenFalse, local, left.nullStatus(flowInfo), this.right);
34
		}
46
		}
47
		tmp = right;
48
		while (tmp instanceof CastExpression)
49
			tmp = ((CastExpression)tmp).expression;
50
		if (tmp instanceof MessageSend) {
51
			MessageSend ms = (MessageSend)tmp;
52
			int rightNullStatus = left.nullStatus(flowInfo);
53
			if ((rightNullStatus == FlowInfo.NULL
54
					|| rightNullStatus == FlowInfo.NON_NULL)
55
					&& isNonNullAnnotated(scope, ms.binding.getAnnotations()))
56
				scope.problemReporter().cannotReturnPotentiallyNullExpression(right);
57
		}
35
	}
58
	}
36
	private void checkVariableComparison(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo, FlowInfo initsWhenTrue, FlowInfo initsWhenFalse, LocalVariableBinding local, int nullStatus, Expression reference) {
59
	private void checkVariableComparison(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo, FlowInfo initsWhenTrue, FlowInfo initsWhenFalse, LocalVariableBinding local, int nullStatus, Expression reference) {
37
		switch (nullStatus) {
60
		switch (nullStatus) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java (+26 lines)
Lines 15-21 Link Here
15
import org.eclipse.jdt.core.compiler.CharOperation;
15
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
16
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
17
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
17
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
18
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
18
import org.eclipse.jdt.internal.compiler.lookup.*;
19
import org.eclipse.jdt.internal.compiler.lookup.*;
20
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
19
import org.eclipse.jdt.internal.compiler.ASTVisitor;
21
import org.eclipse.jdt.internal.compiler.ASTVisitor;
20
22
21
public abstract class ASTNode implements TypeConstants, TypeIds {
23
public abstract class ASTNode implements TypeConstants, TypeIds {
Lines 711-716 Link Here
711
	}
713
	}
712
}
714
}
713
715
716
/** 
717
 * Return <code>true</code> if <code>ab</code> contains
718
 * a non-null annotation.
719
 */
720
public static boolean isNonNullAnnotated(Scope currentScope, AnnotationBinding[] ab) {
721
	if (ab == null || ab.length == 0)
722
		return false;
723
	if (currentScope.compilerOptions().getSeverity(CompilerOptions.NullReference) != ProblemSeverities.Ignore) {
724
		// TODO: use lazy creation
725
		char[][] annotations = CharOperation.splitOn(';', currentScope.compilerOptions().nonNullAnnotations.toCharArray());
726
		for (int i = 0; i < ab.length; i++) {
727
			if (ab[i] != null) {
728
				for (int j = 0; j < annotations.length; j++) {
729
					char[] annotation = ab[i].getAnnotationType().readableName();
730
					if (CharOperation.compareTo(annotation, annotations[j]) == 0) {
731
						return true;
732
					}
733
				}
734
			}
735
		}
736
	}
737
	return false;
738
}
739
714
	public int sourceStart() {
740
	public int sourceStart() {
715
		return this.sourceStart;
741
		return this.sourceStart;
716
	}
742
	}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java (+13 lines)
Lines 55-60 Link Here
55
	public TypeReference[] typeArguments;
55
	public TypeReference[] typeArguments;
56
	public TypeBinding[] genericTypeArguments;
56
	public TypeBinding[] genericTypeArguments;
57
	
57
	
58
	private boolean isReturnValueNonNull = false;
59
	
58
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
60
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
59
61
60
	boolean nonStatic = !this.binding.isStatic();
62
	boolean nonStatic = !this.binding.isStatic();
Lines 67-72 Link Here
67
		int length = this.arguments.length;
69
		int length = this.arguments.length;
68
		for (int i = 0; i < length; i++) {
70
		for (int i = 0; i < length; i++) {
69
			flowInfo = this.arguments[i].analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
71
			flowInfo = this.arguments[i].analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
72
73
			if (arguments[i].nullStatus(flowInfo) != FlowInfo.NON_NULL
74
					&& isNonNullAnnotated(currentScope, binding.getParameterAnnotations(i))) {
75
				currentScope.problemReporter().cannotPassPotentiallyNullExpressionAsArgument(binding, arguments[i]);
76
			}
70
		}
77
		}
71
	}
78
	}
72
	ReferenceBinding[] thrownExceptions;
79
	ReferenceBinding[] thrownExceptions;
Lines 254-259 Link Here
254
	}
261
	}
255
}
262
}
256
public int nullStatus(FlowInfo flowInfo) {
263
public int nullStatus(FlowInfo flowInfo) {
264
	if (isReturnValueNonNull)
265
		return FlowInfo.NON_NULL;
257
	return FlowInfo.UNKNOWN;
266
	return FlowInfo.UNKNOWN;
258
}
267
}
259
268
Lines 513-518 Link Here
513
			}
522
			}
514
		}
523
		}
515
	}
524
	}
525
526
	if (isNonNullAnnotated(scope, binding.getAnnotations()))
527
		isReturnValueNonNull = true;
528
	
516
	return this.resolvedType;
529
	return this.resolvedType;
517
}
530
}
518
531
(-)compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java (+106 lines)
Lines 20-25 Link Here
20
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
20
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
21
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
21
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
22
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
22
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
23
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
24
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
23
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
25
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
24
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
26
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
25
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
27
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
Lines 67-72 Link Here
67
			if (binding.isAbstract() || binding.isNative())
69
			if (binding.isAbstract() || binding.isNative())
68
				return;
70
				return;
69
			
71
			
72
			boolean[] argumentIsNonNull = null;
73
			if (arguments != null)
74
				argumentIsNonNull = new boolean[arguments.length];
75
			
76
			ReferenceBinding declaringClassRef = binding.declaringClass;
77
			
78
			if ((returnType.bits & TagBits.IsBaseType) == 0) {
79
				
80
				ReferenceBinding type = isOverriddenMethodNonNullAnnotated(declaringClassRef, -1, classScope); 
81
				if (type != null && !isNonNullAnnotated(classScope, binding.getAnnotations()))
82
					classScope.problemReporter().nonNullAnnotationIsMissingForOverridingMethod(type, binding, this);
83
			}
84
			
85
			if (arguments != null) {
86
				for (int i = 0; i < arguments.length; i++) {
87
					ReferenceBinding type = isOverriddenMethodNonNullAnnotated(declaringClassRef, i, classScope); 
88
					boolean argIsNonNull = isNonNullAnnotated(classScope, binding.getParameterAnnotations(i));
89
					if (type != null && !argIsNonNull)
90
						classScope.problemReporter().nonNullAnnotationIsMissingForArgumentInOverridingMethod(type, binding, arguments[i]);
91
92
					argumentIsNonNull[i] = type != null || argIsNonNull;
93
				}
94
			}
95
			
96
			if (argumentIsNonNull != null) {
97
				for (int i = 0; i < argumentIsNonNull.length; i++) {
98
					if (!argumentIsNonNull[i] && isNonNullAnnotated(classScope, binding.getParameterAnnotations(i)))
99
						argumentIsNonNull[i] = true;
100
				}
101
			}
102
			
70
			ExceptionHandlingFlowContext methodContext =
103
			ExceptionHandlingFlowContext methodContext =
71
				new ExceptionHandlingFlowContext(
104
				new ExceptionHandlingFlowContext(
72
					initializationContext,
105
					initializationContext,
Lines 79-84 Link Here
79
			if (this.arguments != null) {
112
			if (this.arguments != null) {
80
				for (int i = 0, count = this.arguments.length; i < count; i++) {
113
				for (int i = 0, count = this.arguments.length; i < count; i++) {
81
					flowInfo.markAsDefinitelyAssigned(this.arguments[i].binding);
114
					flowInfo.markAsDefinitelyAssigned(this.arguments[i].binding);
115
					if (argumentIsNonNull[i])
116
						flowInfo.markAsDefinitelyNonNull(this.arguments[i].binding);
82
				}
117
				}
83
			}
118
			}
84
			// propagate to statements
119
			// propagate to statements
Lines 111-116 Link Here
111
		}
146
		}
112
	}
147
	}
113
148
149
150
	/**
151
	 * Check all the overridden methods (super classes and interfaces)
152
	 * searching for NonNull annotation. Return the first type which
153
	 * contains an annotated overridden method.
154
	 * 
155
	 * @param declaringClassRef the base type
156
	 * @param argument if positive, search annotations on parameters, else
157
	 * search on method
158
	 * @param classScope 
159
	 * @return the type containing the overridden and annotated method
160
	 * or null 
161
	 */
162
	public ReferenceBinding isOverriddenMethodNonNullAnnotated(ReferenceBinding declaringClassRef, int argument, ClassScope classScope) {
163
		if (declaringClassRef == null)
164
			return null;
165
		
166
		if (binding.isPrivate() || binding.isConstructor())
167
			return null;
168
169
		ReferenceBinding superClassRef = declaringClassRef.superclass();
170
		if (superClassRef != null) {
171
			MethodBinding mb = superClassRef.getExactMethod(selector, binding.parameters, classScope.compilationUnitScope());
172
173
			if (mb != null) {
174
				boolean nonNullAnnotated;
175
				if (argument < 0)
176
					nonNullAnnotated = isNonNullAnnotated(classScope, mb.getAnnotations());
177
				else
178
					nonNullAnnotated = isNonNullAnnotated(classScope, mb.getParameterAnnotations(argument));
179
				
180
				// if an annotation is found, returns
181
				if (nonNullAnnotated)
182
					return superClassRef;
183
			} else {
184
				ReferenceBinding type = isOverriddenMethodNonNullAnnotated(superClassRef, argument, classScope);
185
				if (type != null)
186
					return type;
187
			}
188
		}
189
		
190
		// if an overridden method have been found, but it was not annotated
191
		// the check continues through the interfaces
192
		
193
		ReferenceBinding[] superInterfacesRef = declaringClassRef.superInterfaces();
194
		if (superInterfacesRef != null) {
195
			for (int i = 0; i < superInterfacesRef.length; i++) {
196
				if (superInterfacesRef[i] != null) {
197
					MethodBinding mb = superInterfacesRef[i].getExactMethod(selector, binding.parameters, classScope.compilationUnitScope());
198
					
199
					if (mb != null) {
200
						boolean nonNullAnnotated;
201
						if (argument < 0)
202
							nonNullAnnotated = isNonNullAnnotated(classScope, mb.getAnnotations());
203
						else
204
							nonNullAnnotated = isNonNullAnnotated(classScope, mb.getParameterAnnotations(argument));
205
						
206
						if (nonNullAnnotated)
207
							return superInterfacesRef[i];
208
					} else {
209
						ReferenceBinding type = isOverriddenMethodNonNullAnnotated(superInterfacesRef[i], argument, classScope);
210
						if (type != null)
211
							return type;
212
					}
213
				}
214
			}
215
		}
216
		
217
		return null;
218
	}
219
	
114
	public boolean isMethod() {
220
	public boolean isMethod() {
115
221
116
		return true;
222
		return true;
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java (+8 lines)
Lines 37-42 Link Here
37
37
38
	if (this.expression != null) {
38
	if (this.expression != null) {
39
		flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo);
39
		flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo);
40
		
41
		AbstractMethodDeclaration methodDecl = currentScope.methodScope().referenceMethod();
42
		MethodBinding methodBinding = methodDecl.binding;
43
44
		if ((methodBinding.returnType.tagBits & TagBits.IsBaseType) == 0
45
				&& expression.nullStatus(flowInfo) != FlowInfo.NON_NULL
46
				&& isNonNullAnnotated(currentScope, methodBinding.getAnnotations()))
47
			currentScope.problemReporter().cannotReturnPotentiallyNullExpression(expression);
40
	}
48
	}
41
	this.initStateIndex =
49
	this.initStateIndex =
42
		currentScope.methodScope().recordInitializationStates(flowInfo);
50
		currentScope.methodScope().recordInitializationStates(flowInfo);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java (-3 / +23 lines)
Lines 22-28 Link Here
22
22
23
	public Expression lhs;
23
	public Expression lhs;
24
	public Expression expression;
24
	public Expression expression;
25
		
25
	private boolean isNonNull;
26
	
26
public Assignment(Expression lhs, Expression expression, int sourceEnd) {
27
public Assignment(Expression lhs, Expression expression, int sourceEnd) {
27
	//lhs is always a reference by construction ,
28
	//lhs is always a reference by construction ,
28
	//but is build as an expression ==> the checkcast cannot fail
29
	//but is build as an expression ==> the checkcast cannot fail
Lines 31-38 Link Here
31
	this.expression = expression;
32
	this.expression = expression;
32
	this.sourceStart = lhs.sourceStart;
33
	this.sourceStart = lhs.sourceStart;
33
	this.sourceEnd = sourceEnd;
34
	this.sourceEnd = sourceEnd;
35
	this.isNonNull = false;
34
}
36
}
35
37
38
36
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
39
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
37
	// record setting a variable: various scenarii are possible, setting an array reference, 
40
	// record setting a variable: various scenarii are possible, setting an array reference, 
38
// a field reference, a blank final field reference, a field of an enclosing instance or 
41
// a field reference, a blank final field reference, a field of an enclosing instance or 
Lines 44-49 Link Here
44
			flowContext.recordUsingNullReference(currentScope, local, this.lhs, 
47
			flowContext.recordUsingNullReference(currentScope, local, this.lhs, 
45
				FlowContext.CAN_ONLY_NULL | FlowContext.IN_ASSIGNMENT, flowInfo);
48
				FlowContext.CAN_ONLY_NULL | FlowContext.IN_ASSIGNMENT, flowInfo);
46
		}
49
		}
50
		if (isNonNull && nullStatus != FlowInfo.NON_NULL)
51
			local.declaringScope.problemReporter().localCannotBeAssignedWithPotentiallyNull(local, expression);
47
	}
52
	}
48
	flowInfo = ((Reference) lhs)
53
	flowInfo = ((Reference) lhs)
49
		.analyseAssignment(currentScope, flowContext, flowInfo, this, false)
54
		.analyseAssignment(currentScope, flowContext, flowInfo, this, false)
Lines 57-63 Link Here
57
				flowInfo.markAsDefinitelyNonNull(local);
62
				flowInfo.markAsDefinitelyNonNull(local);
58
				break;
63
				break;
59
			default:
64
			default:
60
				flowInfo.markAsDefinitelyUnknown(local);
65
				if (isNonNull)
66
					flowInfo.markAsDefinitelyNonNull(local);
67
				else
68
					flowInfo.markAsDefinitelyUnknown(local);
61
		}
69
		}
62
		if (flowContext.initsOnFinally != null) {
70
		if (flowContext.initsOnFinally != null) {
63
			switch(nullStatus) {
71
			switch(nullStatus) {
Lines 68-74 Link Here
68
					flowContext.initsOnFinally.markAsDefinitelyNonNull(local);
76
					flowContext.initsOnFinally.markAsDefinitelyNonNull(local);
69
					break;
77
					break;
70
				default:
78
				default:
71
					flowContext.initsOnFinally.markAsDefinitelyUnknown(local);
79
					if (isNonNull)
80
						flowContext.initsOnFinally.markAsDefinitelyNonNull(local);
81
					else
82
						flowContext.initsOnFinally.markAsDefinitelyUnknown(local);
72
			}
83
			}
73
		}
84
		}
74
	}		
85
	}		
Lines 146-151 Link Here
146
}	
157
}	
147
158
148
public int nullStatus(FlowInfo flowInfo) {
159
public int nullStatus(FlowInfo flowInfo) {
160
	if (isNonNull)
161
		return FlowInfo.NON_NULL;
149
	return this.expression.nullStatus(flowInfo);
162
	return this.expression.nullStatus(flowInfo);
150
}
163
}
151
164
Lines 192-197 Link Here
192
		scope.problemReporter().assignmentHasNoEffect(this, left.shortReadableName());
205
		scope.problemReporter().assignmentHasNoEffect(this, left.shortReadableName());
193
	}
206
	}
194
207
208
	// check for NonNull annotation
209
	LocalVariableBinding local = this.lhs.localVariableBinding();
210
	if (local != null && local.kind() == Binding.LOCAL
211
			&& (local.type.tagBits & TagBits.IsBaseType) == 0) {
212
		isNonNull = isNonNullAnnotated(scope, local.getAnnotations());
213
	}
214
	
195
	// Compile-time conversion of base-types : implicit narrowing integer into byte/short/character
215
	// Compile-time conversion of base-types : implicit narrowing integer into byte/short/character
196
	// may require to widen the rhs expression at runtime
216
	// may require to widen the rhs expression at runtime
197
	if (lhsType != rhsType) // must call before computeConversion() and typeMismatchError()
217
	if (lhsType != rhsType) // must call before computeConversion() and typeMismatchError()
(-)compiler/org/eclipse/jdt/core/compiler/IProblem.java (+7 lines)
Lines 1275-1278 Link Here
1275
	// associated with it
1275
	// associated with it
1276
	/** @since 3.2 */
1276
	/** @since 3.2 */
1277
	int ExternalProblemFixable = 901;
1277
	int ExternalProblemFixable = 901;
1278
	
1279
	int LocalCannotBeAssignedPotentiallyNull = Internal + 903;
1280
	int CannotPassPotentiallyNullExpressionAsArgument = Internal + 904;
1281
	int CannotReturnPotentiallyNullExpression = Internal + 905;
1282
	int NonNullAnnotationIsMissingForOverridingMethod = Internal + 906;
1283
	int NonNullAnnotationIsMissingForArgumentInOverridingMethod = Internal + 907;
1284
	
1278
}
1285
}
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (+7 lines)
Lines 587-589 Link Here
587
857 = Incorrect number of type arguments for generic constructor <{3}>{0}({1}) of type {2}; it cannot be parameterized with arguments <{4}>
587
857 = Incorrect number of type arguments for generic constructor <{3}>{0}({1}) of type {2}; it cannot be parameterized with arguments <{4}>
588
858 = The parameterized constructor <{3}>{0}({1}) of type {2} is not applicable for the arguments ({4})
588
858 = The parameterized constructor <{3}>{0}({1}) of type {2} is not applicable for the arguments ({4})
589
859 = The constructor {0}({1}) of raw type {2} is no longer generic; it cannot be parameterized with arguments <{3}>
589
859 = The constructor {0}({1}) of raw type {2} is no longer generic; it cannot be parameterized with arguments <{3}>
590
591
### @NonNull annotation
592
903 = Cannot assign null or potentially null expression to {0} because of @NonNull annotation
593
904 = Cannot pass null or potentially null expression as argument for method {0} because of @NonNull annotation
594
905 = Cannot return null or potentially null expression because of @NonNull annotation
595
906 = Method {1} isn't NonNull annotated while overridden method in {0} is
596
907 = Argument {2} in method {1} isn't NonNull annotated while overridden method in type {0} is
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+67 lines)
Lines 293-298 Link Here
293
			
293
			
294
		case IProblem.OverridingMethodWithoutSuperInvocation:
294
		case IProblem.OverridingMethodWithoutSuperInvocation:
295
			return CompilerOptions.OverridingMethodWithoutSuperInvocation;
295
			return CompilerOptions.OverridingMethodWithoutSuperInvocation;
296
			
297
		case IProblem.LocalCannotBeAssignedPotentiallyNull:
298
		case IProblem.CannotReturnPotentiallyNullExpression:
299
		case IProblem.CannotPassPotentiallyNullExpressionAsArgument:
300
		case IProblem.NonNullAnnotationIsMissingForOverridingMethod:
301
		case IProblem.NonNullAnnotationIsMissingForArgumentInOverridingMethod:
302
			return CompilerOptions.NullReference;
296
	}
303
	}
297
	return 0;
304
	return 0;
298
}
305
}
Lines 4460-4465 Link Here
4460
		nodeSourceStart(local, location),
4467
		nodeSourceStart(local, location),
4461
		nodeSourceEnd(local, location));
4468
		nodeSourceEnd(local, location));
4462
}
4469
}
4470
public void localCannotBeAssignedWithPotentiallyNull(LocalVariableBinding local, ASTNode location) {
4471
	int severity = computeSeverity(IProblem.LocalCannotBeAssignedPotentiallyNull);
4472
	if (severity == ProblemSeverities.Ignore) return;
4473
	String[] arguments = new String[] { new String(local.name) };
4474
	this.handle(
4475
		IProblem.LocalCannotBeAssignedPotentiallyNull,
4476
		arguments,
4477
		arguments,
4478
		severity,
4479
		nodeSourceStart(local, location),
4480
		nodeSourceEnd(local, location));
4481
}
4482
public void cannotReturnPotentiallyNullExpression(ASTNode location) {
4483
	int severity = computeSeverity(IProblem.CannotReturnPotentiallyNullExpression);
4484
	if (severity == ProblemSeverities.Ignore) return;
4485
	String[] arguments = new String[] { };
4486
	this.handle(
4487
		IProblem.CannotReturnPotentiallyNullExpression,
4488
		arguments,
4489
		arguments,
4490
		severity,
4491
		location.sourceStart,
4492
		location.sourceEnd);
4493
}
4494
public void nonNullAnnotationIsMissingForOverridingMethod(ReferenceBinding type, MethodBinding method, ASTNode location) {
4495
	int severity = computeSeverity(IProblem.NonNullAnnotationIsMissingForOverridingMethod);
4496
	if (severity == ProblemSeverities.Ignore) return;
4497
	String[] arguments = new String[] { new String(type.readableName()), new String(method.readableName()) };
4498
	this.handle(
4499
		IProblem.NonNullAnnotationIsMissingForOverridingMethod,
4500
		arguments,
4501
		arguments,
4502
		severity,
4503
		location.sourceStart,
4504
		location.sourceEnd);
4505
}
4506
public void nonNullAnnotationIsMissingForArgumentInOverridingMethod(ReferenceBinding type, MethodBinding method, Argument arg) {
4507
	int severity = computeSeverity(IProblem.NonNullAnnotationIsMissingForArgumentInOverridingMethod);
4508
	if (severity == ProblemSeverities.Ignore) return;
4509
	String[] arguments = new String[] { new String(type.readableName()), new String(method.readableName()), new String(arg.name) };
4510
	this.handle(
4511
		IProblem.NonNullAnnotationIsMissingForArgumentInOverridingMethod,
4512
		arguments,
4513
		arguments,
4514
		severity,
4515
		arg.sourceStart,
4516
		arg.sourceEnd);
4517
}
4518
public void cannotPassPotentiallyNullExpressionAsArgument(MethodBinding method, ASTNode location) {
4519
	int severity = computeSeverity(IProblem.CannotPassPotentiallyNullExpressionAsArgument);
4520
	if (severity == ProblemSeverities.Ignore) return;
4521
	String[] arguments = new String[] { new String(method.readableName()) };
4522
	this.handle(
4523
		IProblem.CannotPassPotentiallyNullExpressionAsArgument,
4524
		arguments,
4525
		arguments,
4526
		severity,
4527
		nodeSourceStart(method, location),
4528
		nodeSourceEnd(method, location));
4529
}
4463
public void localVariableNullComparedToNonNull(LocalVariableBinding local, ASTNode location) {
4530
public void localVariableNullComparedToNonNull(LocalVariableBinding local, ASTNode location) {
4464
	int severity = computeSeverity(IProblem.NullLocalVariableComparisonYieldsFalse);
4531
	int severity = computeSeverity(IProblem.NullLocalVariableComparisonYieldsFalse);
4465
	if (severity == ProblemSeverities.Ignore) return;
4532
	if (severity == ProblemSeverities.Ignore) return;
(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (-1 / +10 lines)
Lines 113-118 Link Here
113
	public static final String OPTION_ReportOverridingMethodWithoutSuperInvocation =  "org.eclipse.jdt.core.compiler.problem.overridingMethodWithoutSuperInvocation"; //$NON-NLS-1$
113
	public static final String OPTION_ReportOverridingMethodWithoutSuperInvocation =  "org.eclipse.jdt.core.compiler.problem.overridingMethodWithoutSuperInvocation"; //$NON-NLS-1$
114
	public static final String OPTION_GenerateClassFiles = "org.eclipse.jdt.core.compiler.generateClassFiles"; //$NON-NLS-1$
114
	public static final String OPTION_GenerateClassFiles = "org.eclipse.jdt.core.compiler.generateClassFiles"; //$NON-NLS-1$
115
	public static final String OPTION_Process_Annotations = "org.eclipse.jdt.core.compiler.processAnnotations"; //$NON-NLS-1$
115
	public static final String OPTION_Process_Annotations = "org.eclipse.jdt.core.compiler.processAnnotations"; //$NON-NLS-1$
116
	public static final String OPTION_NonNullAnnotations = "org.eclipse.jdt.core.compiler.nonNullAnnotations"; //$NON-NLS-1$
116
117
117
	// Backward compatibility
118
	// Backward compatibility
118
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
119
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
Lines 199-205 Link Here
199
	public static final long OverridingMethodWithoutSuperInvocation = ASTNode.Bit50L;
200
	public static final long OverridingMethodWithoutSuperInvocation = ASTNode.Bit50L;
200
	public static final long PotentialNullReference = ASTNode.Bit51L;
201
	public static final long PotentialNullReference = ASTNode.Bit51L;
201
	public static final long RedundantNullCheck = ASTNode.Bit52L;
202
	public static final long RedundantNullCheck = ASTNode.Bit52L;
202
203
	
203
	// Map: String optionKey --> Long irritant>
204
	// Map: String optionKey --> Long irritant>
204
	private static Map OptionToIrritants;
205
	private static Map OptionToIrritants;
205
206
Lines 320-325 Link Here
320
	// Enable annotation processing by default only in batch mode
321
	// Enable annotation processing by default only in batch mode
321
	public boolean processAnnotations = false;
322
	public boolean processAnnotations = false;
322
323
324
	// annotations list for null checks (separator is ';')
325
	public String nonNullAnnotations = "org.NonNull;edu.umd.cs.findbugs.annotations.NonNull"; //$NON-NLS-1$
326
	
323
	/**
327
	/**
324
	 * Initializing the compiler options with defaults
328
	 * Initializing the compiler options with defaults
325
	 */
329
	 */
Lines 434-439 Link Here
434
		optionsMap.put(OPTION_ReportOverridingMethodWithoutSuperInvocation, getSeverityString(OverridingMethodWithoutSuperInvocation));
438
		optionsMap.put(OPTION_ReportOverridingMethodWithoutSuperInvocation, getSeverityString(OverridingMethodWithoutSuperInvocation));
435
		optionsMap.put(OPTION_GenerateClassFiles, this.generateClassFiles ? ENABLED : DISABLED);
439
		optionsMap.put(OPTION_GenerateClassFiles, this.generateClassFiles ? ENABLED : DISABLED);
436
		optionsMap.put(OPTION_Process_Annotations, this.processAnnotations ? ENABLED : DISABLED);
440
		optionsMap.put(OPTION_Process_Annotations, this.processAnnotations ? ENABLED : DISABLED);
441
		optionsMap.put(OPTION_NonNullAnnotations, this.nonNullAnnotations);
437
		return optionsMap;
442
		return optionsMap;
438
	}
443
	}
439
444
Lines 926-931 Link Here
926
				this.storeAnnotations = false;
931
				this.storeAnnotations = false;
927
			}
932
			}
928
		}
933
		}
934
		if ((optionValue = optionsMap.get(OPTION_NonNullAnnotations)) != null) {
935
			this.nonNullAnnotations = (String)optionValue;
936
		}		
929
	}
937
	}
930
938
931
	public String toString() {
939
	public String toString() {
Lines 1010-1015 Link Here
1010
		buf.append("\n\t- parameter assignment: ").append(getSeverityString(ParameterAssignment)); //$NON-NLS-1$
1018
		buf.append("\n\t- parameter assignment: ").append(getSeverityString(ParameterAssignment)); //$NON-NLS-1$
1011
		buf.append("\n\t- generate class files: ").append(this.generateClassFiles ? ENABLED : DISABLED); //$NON-NLS-1$
1019
		buf.append("\n\t- generate class files: ").append(this.generateClassFiles ? ENABLED : DISABLED); //$NON-NLS-1$
1012
		buf.append("\n\t- process annotations: ").append(this.processAnnotations ? ENABLED : DISABLED); //$NON-NLS-1$
1020
		buf.append("\n\t- process annotations: ").append(this.processAnnotations ? ENABLED : DISABLED); //$NON-NLS-1$
1021
		buf.append("\n\t- non null annotations list (';'): ").append(this.nonNullAnnotations); //$NON-NLS-1$
1013
		return buf.toString();
1022
		return buf.toString();
1014
	}
1023
	}
1015
1024

Return to bug 186342