Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nullaway/src/main/java/com/uber/nullaway/NullAway.java
Original file line number Diff line number Diff line change
Expand Up @@ -2711,7 +2711,7 @@ private boolean mayBeNullMethodCall(
// it will do so without an assignment context. If this becomes a problem, we can revisit
if (config.isJSpecifyMode()
&& genericsChecks
.getGenericReturnNullnessAtInvocation(exprSymbol, invocationTree, null, state)
.getGenericReturnNullnessAtInvocation(exprSymbol, invocationTree, null, state, false)
.equals(Nullness.NULLABLE)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,19 @@ public static AccessPathNullnessAnalysis instance(VisitorState state, NullAway a
* @return nullness info for expression, from dataflow
*/
public @Nullable Nullness getNullness(TreePath exprPath, Context context) {
return dataFlow.expressionDataflow(exprPath, context, nullnessPropagation);
return dataFlow.expressionDataflow(exprPath, context, nullnessPropagation, false);
}

/**
* Get the nullness info for an expression from the current running dataflow analysis (so it may
* not be the final result).
*
* @param exprPath tree path of expression
* @param context Javac context
* @return nullness info for expression, from running dataflow
*/
public @Nullable Nullness getNullnessFromRunning(TreePath exprPath, Context context) {
return dataFlow.expressionDataflow(exprPath, context, nullnessPropagation, true);
}

/**
Expand All @@ -125,7 +137,7 @@ public static AccessPathNullnessAnalysis instance(VisitorState state, NullAway a
*/
public @Nullable Nullness getNullnessForContractDataflow(TreePath exprPath, Context context) {
return dataFlow.expressionDataflow(
exprPath, context, castToNonNull(contractNullnessPropagation));
exprPath, context, castToNonNull(contractNullnessPropagation), false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ private boolean genericReturnIsNullable(MethodInvocationNode node) {
if (tree != null) {
Nullness nullness =
genericsChecks.getGenericReturnNullnessAtInvocation(
ASTHelpers.getSymbol(tree), tree, node.getTreePath(), state);
ASTHelpers.getSymbol(tree), tree, node.getTreePath(), state, true);
return nullness.equals(NULLABLE);
}
}
Expand Down
44 changes: 35 additions & 9 deletions nullaway/src/main/java/com/uber/nullaway/dataflow/DataFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ public final class DataFlow {
new CacheLoader<AnalysisParams, Analysis<?, ?, ?>>() {
@Override
public Analysis<?, ?, ?> load(AnalysisParams key) {
ControlFlowGraph cfg = key.cfg();
ForwardTransferFunction<?, ?> transfer = key.transferFunction();

@SuppressWarnings({"unchecked", "rawtypes"})
Analysis<?, ?, ?> analysis = new ForwardAnalysisImpl<>(transfer);
analysis.performAnalysis(cfg);
return analysis;
}
});
Expand Down Expand Up @@ -147,14 +145,25 @@ public ControlFlowGraph load(CfgParams key) {
* their control flow graph is the same. - if two transfer functions are {@code equal}, and are
* run over the same control flow graph, the analysis result is the same. - for all contexts, the
* analysis result is the same.
*
* @param path path to method, lambda or initializer
* @param context Javac context
* @param transfer transfer functions
* @param performAnalysis whether dataflow analysis should be initiated via a call to {@code
* performAnalysis}. If the analysis is already running, this parameter should be {@code
* false}; dataflow cannot be run recursively.
*/
private <A extends AbstractValue<A>, S extends Store<S>, T extends ForwardTransferFunction<A, S>>
Result<A, S, T> dataflow(TreePath path, Context context, T transfer) {
Result<A, S, T> dataflow(
TreePath path, Context context, T transfer, boolean performAnalysis) {
ProcessingEnvironment env = JavacProcessingEnvironment.instance(context);
ControlFlowGraph cfg = cfgCache.getUnchecked(CfgParams.create(path, env));
AnalysisParams aparams = AnalysisParams.create(transfer, cfg);
@SuppressWarnings("unchecked")
Analysis<A, S, T> analysis = (Analysis<A, S, T>) analysisCache.getUnchecked(aparams);
if (performAnalysis) {
analysis.performAnalysis(cfg);
}

return new Result<A, S, T>() {
@Override
Expand Down Expand Up @@ -187,7 +196,8 @@ ControlFlowGraph getControlFlowGraph(TreePath path, Context context, T transfer)
throw new IllegalArgumentException(
"Cannot get CFG for node outside a method, lambda, or initializer");
}
return dataflow(enclosingMethodOrLambdaOrInitializer, context, transfer).getControlFlowGraph();
return dataflow(enclosingMethodOrLambdaOrInitializer, context, transfer, true)
.getControlFlowGraph();
}

/**
Expand All @@ -197,15 +207,31 @@ ControlFlowGraph getControlFlowGraph(TreePath path, Context context, T transfer)
* @param exprPath expression
* @param context Javac context
* @param transfer transfer functions
* @param isRunning true if the dataflow analysis is currently running
* @param <A> values in abstraction
* @param <S> store type
* @param <T> transfer function type
* @return dataflow value for expression
*/
public <A extends AbstractValue<A>, S extends Store<S>, T extends ForwardTransferFunction<A, S>>
@Nullable A expressionDataflow(TreePath exprPath, Context context, T transfer) {
AnalysisResult<A, S> analysisResult = resultForExpr(exprPath, context, transfer);
return analysisResult == null ? null : analysisResult.getValue(exprPath.getLeaf());
@Nullable A expressionDataflow(
TreePath exprPath, Context context, T transfer, boolean isRunning) {
if (isRunning) {
// get the Analysis object from the cache, and get the current result from that
Analysis<A, S, T> analysis =
dataflow(
Preconditions.checkNotNull(
findEnclosingMethodOrLambdaOrInitializer(exprPath),
"expression is not inside a method, lambda or initializer block!"),
context,
transfer,
false)
.getAnalysis();
return analysis.getValue(exprPath.getLeaf());
} else {
AnalysisResult<A, S> analysisResult = resultForExpr(exprPath, context, transfer);
return analysisResult == null ? null : analysisResult.getValue(exprPath.getLeaf());
}
}

/**
Expand All @@ -230,7 +256,7 @@ ControlFlowGraph getControlFlowGraph(TreePath path, Context context, T transfer)
"Leaf of methodPath must be of type MethodTree, LambdaExpressionTree, BlockTree, or VariableTree, but was %s",
leaf.getClass().getName());

return dataflow(path, context, transfer).getAnalysis().getRegularExitStore();
return dataflow(path, context, transfer, true).getAnalysis().getRegularExitStore();
}

public <A extends AbstractValue<A>, S extends Store<S>, T extends ForwardTransferFunction<A, S>>
Expand Down Expand Up @@ -280,7 +306,7 @@ ControlFlowGraph getControlFlowGraph(TreePath path, Context context, T transfer)
// *before* any unboxing operations (like invoking intValue() on an Integer). This is
// important,
// e.g., for actually checking that the unboxing operation is legal.
return dataflow(enclosingPath, context, transfer).getAnalysis().getResult();
return dataflow(enclosingPath, context, transfer, true).getAnalysis().getResult();
}

/** clear the CFG and analysis caches */
Expand Down
Loading