Lines 55-61
Link Here
|
55 |
BranchLabel continueLabel, |
55 |
BranchLabel continueLabel, |
56 |
Scope associatedScope) { |
56 |
Scope associatedScope) { |
57 |
super(parent, associatedNode, breakLabel); |
57 |
super(parent, associatedNode, breakLabel); |
58 |
this.preemptNullDiagnostic = true; |
58 |
this.tagBits |= FlowContext.PREEMPT_NULL_DIAGNOSTIC; |
59 |
// children will defer to this, which may defer to its own parent |
59 |
// children will defer to this, which may defer to its own parent |
60 |
this.continueLabel = continueLabel; |
60 |
this.continueLabel = continueLabel; |
61 |
this.associatedScope = associatedScope; |
61 |
this.associatedScope = associatedScope; |
Lines 116-122
Link Here
|
116 |
this.innerFlowContextsCount = 0; |
116 |
this.innerFlowContextsCount = 0; |
117 |
UnconditionalFlowInfo flowInfo = this.upstreamNullFlowInfo. |
117 |
UnconditionalFlowInfo flowInfo = this.upstreamNullFlowInfo. |
118 |
addPotentialNullInfoFrom(callerFlowInfo.unconditionalInitsWithoutSideEffect()); |
118 |
addPotentialNullInfoFrom(callerFlowInfo.unconditionalInitsWithoutSideEffect()); |
119 |
if (this.deferNullDiagnostic) { |
119 |
if ((this.tagBits & FlowContext.DEFER_NULL_DIAGNOSTIC) != 0) { |
120 |
// check only immutable null checks on innermost looping context |
120 |
// check only immutable null checks on innermost looping context |
121 |
for (int i = 0; i < this.nullCount; i++) { |
121 |
for (int i = 0; i < this.nullCount; i++) { |
122 |
LocalVariableBinding local = this.nullLocals[i]; |
122 |
LocalVariableBinding local = this.nullLocals[i]; |
Lines 128-138
Link Here
|
128 |
if (flowInfo.isDefinitelyNonNull(local)) { |
128 |
if (flowInfo.isDefinitelyNonNull(local)) { |
129 |
this.nullReferences[i] = null; |
129 |
this.nullReferences[i] = null; |
130 |
if (this.nullCheckTypes[i] == (CAN_ONLY_NON_NULL | IN_COMPARISON_NON_NULL)) { |
130 |
if (this.nullCheckTypes[i] == (CAN_ONLY_NON_NULL | IN_COMPARISON_NON_NULL)) { |
131 |
if (!this.hideNullComparisonWarnings) { |
131 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
132 |
scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression); |
132 |
scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression); |
133 |
} |
133 |
} |
134 |
} else { |
134 |
} else { |
135 |
if (!this.hideNullComparisonWarnings) { |
135 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
136 |
scope.problemReporter().localVariableNonNullComparedToNull(local, expression); |
136 |
scope.problemReporter().localVariableNonNullComparedToNull(local, expression); |
137 |
} |
137 |
} |
138 |
} |
138 |
} |
Lines 144-154
Link Here
|
144 |
if (flowInfo.isDefinitelyNonNull(local)) { |
144 |
if (flowInfo.isDefinitelyNonNull(local)) { |
145 |
this.nullReferences[i] = null; |
145 |
this.nullReferences[i] = null; |
146 |
if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { |
146 |
if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { |
147 |
if (!this.hideNullComparisonWarnings) { |
147 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
148 |
scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression); |
148 |
scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression); |
149 |
} |
149 |
} |
150 |
} else { |
150 |
} else { |
151 |
if (!this.hideNullComparisonWarnings) { |
151 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
152 |
scope.problemReporter().localVariableNonNullComparedToNull(local, expression); |
152 |
scope.problemReporter().localVariableNonNullComparedToNull(local, expression); |
153 |
} |
153 |
} |
154 |
} |
154 |
} |
Lines 157-167
Link Here
|
157 |
if (flowInfo.isDefinitelyNull(local)) { |
157 |
if (flowInfo.isDefinitelyNull(local)) { |
158 |
this.nullReferences[i] = null; |
158 |
this.nullReferences[i] = null; |
159 |
if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) { |
159 |
if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) { |
160 |
if (!this.hideNullComparisonWarnings) { |
160 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
161 |
scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); |
161 |
scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); |
162 |
} |
162 |
} |
163 |
} else { |
163 |
} else { |
164 |
if (!this.hideNullComparisonWarnings) { |
164 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
165 |
scope.problemReporter().localVariableNullComparedToNonNull(local, expression); |
165 |
scope.problemReporter().localVariableNullComparedToNonNull(local, expression); |
166 |
} |
166 |
} |
167 |
} |
167 |
} |
Lines 180-186
Link Here
|
180 |
scope.problemReporter().localVariableNullReference(local, expression); |
180 |
scope.problemReporter().localVariableNullReference(local, expression); |
181 |
continue; |
181 |
continue; |
182 |
} |
182 |
} |
183 |
if (!this.hideNullComparisonWarnings) { |
183 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
184 |
scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); |
184 |
scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); |
185 |
} |
185 |
} |
186 |
continue; |
186 |
continue; |
Lines 189-195
Link Here
|
189 |
scope.problemReporter().localVariableNullReference(local, expression); |
189 |
scope.problemReporter().localVariableNullReference(local, expression); |
190 |
continue; |
190 |
continue; |
191 |
} |
191 |
} |
192 |
if (!this.hideNullComparisonWarnings) { |
192 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
193 |
scope.problemReporter().localVariableNullComparedToNonNull(local, expression); |
193 |
scope.problemReporter().localVariableNullComparedToNonNull(local, expression); |
194 |
} |
194 |
} |
195 |
continue; |
195 |
continue; |
Lines 245-255
Link Here
|
245 |
if (flowInfo.isDefinitelyNonNull(local)) { |
245 |
if (flowInfo.isDefinitelyNonNull(local)) { |
246 |
this.nullReferences[i] = null; |
246 |
this.nullReferences[i] = null; |
247 |
if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { |
247 |
if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { |
248 |
if (!this.hideNullComparisonWarnings) { |
248 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
249 |
scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression); |
249 |
scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression); |
250 |
} |
250 |
} |
251 |
} else { |
251 |
} else { |
252 |
if (!this.hideNullComparisonWarnings) { |
252 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
253 |
scope.problemReporter().localVariableNonNullComparedToNull(local, expression); |
253 |
scope.problemReporter().localVariableNonNullComparedToNull(local, expression); |
254 |
} |
254 |
} |
255 |
} |
255 |
} |
Lines 268-274
Link Here
|
268 |
scope.problemReporter().localVariableNullReference(local, expression); |
268 |
scope.problemReporter().localVariableNullReference(local, expression); |
269 |
continue; |
269 |
continue; |
270 |
} |
270 |
} |
271 |
if (!this.hideNullComparisonWarnings) { |
271 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
272 |
scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); |
272 |
scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); |
273 |
} |
273 |
} |
274 |
continue; |
274 |
continue; |
Lines 277-283
Link Here
|
277 |
scope.problemReporter().localVariableNullReference(local, expression); |
277 |
scope.problemReporter().localVariableNullReference(local, expression); |
278 |
continue; |
278 |
continue; |
279 |
} |
279 |
} |
280 |
if (!this.hideNullComparisonWarnings) { |
280 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
281 |
scope.problemReporter().localVariableNullComparedToNonNull(local, expression); |
281 |
scope.problemReporter().localVariableNullComparedToNonNull(local, expression); |
282 |
} |
282 |
} |
283 |
continue; |
283 |
continue; |
Lines 470-483
Link Here
|
470 |
case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL: |
470 |
case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL: |
471 |
if (flowInfo.isDefinitelyNonNull(local)) { |
471 |
if (flowInfo.isDefinitelyNonNull(local)) { |
472 |
if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { |
472 |
if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) { |
473 |
if (!this.hideNullComparisonWarnings) { |
473 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
474 |
scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); |
474 |
scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); |
475 |
} |
475 |
} |
476 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
476 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
477 |
flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); |
477 |
flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); |
478 |
} |
478 |
} |
479 |
} else { |
479 |
} else { |
480 |
if (!this.hideNullComparisonWarnings) { |
480 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
481 |
scope.problemReporter().localVariableNonNullComparedToNull(local, reference); |
481 |
scope.problemReporter().localVariableNonNullComparedToNull(local, reference); |
482 |
} |
482 |
} |
483 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
483 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
Lines 486-499
Link Here
|
486 |
} |
486 |
} |
487 |
} else if (flowInfo.isDefinitelyNull(local)) { |
487 |
} else if (flowInfo.isDefinitelyNull(local)) { |
488 |
if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) { |
488 |
if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) { |
489 |
if (!this.hideNullComparisonWarnings) { |
489 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
490 |
scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); |
490 |
scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); |
491 |
} |
491 |
} |
492 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
492 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
493 |
flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); |
493 |
flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); |
494 |
} |
494 |
} |
495 |
} else { |
495 |
} else { |
496 |
if (!this.hideNullComparisonWarnings) { |
496 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
497 |
scope.problemReporter().localVariableNullComparedToNonNull(local, reference); |
497 |
scope.problemReporter().localVariableNullComparedToNonNull(local, reference); |
498 |
} |
498 |
} |
499 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
499 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
Lines 502-515
Link Here
|
502 |
} |
502 |
} |
503 |
} 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 |
504 |
flowInfo.markAsDefinitelyNonNull(local); |
504 |
flowInfo.markAsDefinitelyNonNull(local); |
505 |
if (!this.hideNullComparisonWarnings) { |
505 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
506 |
recordNullReference(local, reference, checkType); |
506 |
recordNullReference(local, reference, checkType); |
507 |
} |
507 |
} |
508 |
} else if (! flowInfo.cannotBeDefinitelyNullOrNonNull(local)) { |
508 |
} else if (! flowInfo.cannotBeDefinitelyNullOrNonNull(local)) { |
509 |
if (flowInfo.isPotentiallyNonNull(local)) { |
509 |
if (flowInfo.isPotentiallyNonNull(local)) { |
510 |
recordNullReference(local, reference, CAN_ONLY_NON_NULL | checkType & CONTEXT_MASK); |
510 |
recordNullReference(local, reference, CAN_ONLY_NON_NULL | checkType & CONTEXT_MASK); |
511 |
} else { |
511 |
} else { |
512 |
if (!this.hideNullComparisonWarnings) { |
512 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
513 |
recordNullReference(local, reference, checkType); |
513 |
recordNullReference(local, reference, checkType); |
514 |
} |
514 |
} |
515 |
} |
515 |
} |
Lines 530-536
Link Here
|
530 |
scope.problemReporter().localVariableNullReference(local, reference); |
530 |
scope.problemReporter().localVariableNullReference(local, reference); |
531 |
return; |
531 |
return; |
532 |
} |
532 |
} |
533 |
if (!this.hideNullComparisonWarnings) { |
533 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
534 |
scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); |
534 |
scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); |
535 |
} |
535 |
} |
536 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
536 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
Lines 542-548
Link Here
|
542 |
scope.problemReporter().localVariableNullReference(local, reference); |
542 |
scope.problemReporter().localVariableNullReference(local, reference); |
543 |
return; |
543 |
return; |
544 |
} |
544 |
} |
545 |
if (!this.hideNullComparisonWarnings) { |
545 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { |
546 |
scope.problemReporter().localVariableNullComparedToNonNull(local, reference); |
546 |
scope.problemReporter().localVariableNullComparedToNonNull(local, reference); |
547 |
} |
547 |
} |
548 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
548 |
if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { |
Lines 574-580
Link Here
|
574 |
} |
574 |
} |
575 |
// if the contention is inside assert statement, we want to avoid null warnings only in case of |
575 |
// if the contention is inside assert statement, we want to avoid null warnings only in case of |
576 |
// comparisons and not in case of assignment and instanceof |
576 |
// comparisons and not in case of assignment and instanceof |
577 |
if (!this.hideNullComparisonWarnings |
577 |
if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0 |
578 |
|| (checkType & CONTEXT_MASK) == FlowContext.IN_ASSIGNMENT |
578 |
|| (checkType & CONTEXT_MASK) == FlowContext.IN_ASSIGNMENT |
579 |
|| (checkType & CONTEXT_MASK) == FlowContext.IN_INSTANCEOF) { |
579 |
|| (checkType & CONTEXT_MASK) == FlowContext.IN_INSTANCEOF) { |
580 |
recordNullReference(local, reference, checkType); |
580 |
recordNullReference(local, reference, checkType); |