Skip to content

Commit

Permalink
NullnessAnalysis improvements
Browse files Browse the repository at this point in the history
Visit field initializers in nullness analysis if available to improve precision.

Also:
- handle array initializers and conditional expressions
- add some more built-in knowledge of non-null methods and fields

RELNOTES: improved NullnessAnalysis precision using field initializers and other improvements
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=108300064
  • Loading branch information
kevin1e100 authored and cushon committed Dec 3, 2015
1 parent 0ea2e84 commit 10d21b1
Show file tree
Hide file tree
Showing 8 changed files with 629 additions and 209 deletions.
Expand Up @@ -717,14 +717,14 @@ Nullness visitGreaterThanOrEqual() {
@Override
public final TransferResult<Nullness, LocalStore<Nullness>> visitTernaryExpression(
TernaryExpressionNode node, TransferInput<Nullness, LocalStore<Nullness>> input) {
ReadableLocalVariableUpdates updates = new ReadableLocalVariableUpdates();
Nullness result = visitTernaryExpression(node, values(input), updates);
return updateRegularStore(result, input, updates);
Nullness result = visitTernaryExpression(node, values(input));
// TODO(kmb): Return conditional result if node itself is of boolean type, as for method calls
return noStoreChanges(result, input);
}

Nullness visitTernaryExpression(TernaryExpressionNode node, SubNodeValues inputs,
LocalVariableUpdates updates) {
return NULLABLE;
Nullness visitTernaryExpression(TernaryExpressionNode node, SubNodeValues inputs) {
return inputs.valueOfSubNode(node.getThenOperand())
.leastUpperBound(inputs.valueOfSubNode(node.getElseOperand()));
}

@Override
Expand Down
Expand Up @@ -68,6 +68,11 @@ public NullnessAnalysis(Predicate<MethodInfo> additionalNonNullReturningMethods)
* that, in those cases, it will always return {@code NONNULL}.
*/
public Nullness getNullness(TreePath exprPath, Context context) {
return DataFlow.expressionDataflow(exprPath, context, nullnessPropagation);
try {
nullnessPropagation.setContext(context).setCompilationUnit(exprPath.getCompilationUnit());
return DataFlow.expressionDataflow(exprPath, context, nullnessPropagation);
} finally {
nullnessPropagation.setContext(null).setCompilationUnit(null);
}
}
}

0 comments on commit 10d21b1

Please sign in to comment.