Class NullnessAssumptionAnalysis
- java.lang.Object
-
- soot.toolkits.scalar.AbstractFlowAnalysis<N,A>
-
- soot.toolkits.scalar.FlowAnalysis<N,A>
-
- soot.toolkits.scalar.BackwardFlowAnalysis<Unit,NullnessAssumptionAnalysis.AnalysisInfo>
-
- soot.jimple.toolkits.annotation.nullcheck.NullnessAssumptionAnalysis
-
public class NullnessAssumptionAnalysis extends BackwardFlowAnalysis<Unit,NullnessAssumptionAnalysis.AnalysisInfo>
An intraprocedural nullness assumption analysis that computes for each location and each value in a method if the value (before or after that location) is treated as definitely null, definitely non-null or neither. This information could be useful in deciding whether or not to insert code that accesses a potentially null object. If the original program assumes a value is non-null, then adding a use of that value will not introduce any NEW nullness errors into the program. This code may be buggy, or just plain wrong. It has not been checked.- Author:
- Richard L. Halpert Adapted from Eric Bodden's NullnessAnalysis
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
NullnessAssumptionAnalysis.AnalysisInfo
The analysis info is a simple mapping of typeValue
to any of the constants BOTTOM, NON_NULL, NULL or TOP.-
Nested classes/interfaces inherited from class soot.toolkits.scalar.FlowAnalysis
FlowAnalysis.Flow
-
-
Field Summary
Fields Modifier and Type Field Description protected static Object
BOTTOM
protected static Object
NON_NULL
protected static Object
NULL
protected static Object
TOP
-
Fields inherited from class soot.toolkits.scalar.FlowAnalysis
filterUnitToAfterFlow, unitToAfterFlow
-
Fields inherited from class soot.toolkits.scalar.AbstractFlowAnalysis
filterUnitToBeforeFlow, graph, unitToBeforeFlow
-
-
Constructor Summary
Constructors Constructor Description NullnessAssumptionAnalysis(UnitGraph graph)
Creates a new analysis for the given graph/
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
copy(NullnessAssumptionAnalysis.AnalysisInfo source, NullnessAssumptionAnalysis.AnalysisInfo dest)
Creates a copy of thesource
flow object indest
.protected NullnessAssumptionAnalysis.AnalysisInfo
entryInitialFlow()
Returns the initial flow value for entry/exit graph nodes.protected void
flowThrough(NullnessAssumptionAnalysis.AnalysisInfo in, Unit unit, NullnessAssumptionAnalysis.AnalysisInfo outValue)
Given the merge of theout
sets, compute thein
set fors
(or in to out, depending on direction).protected boolean
isAlwaysNonNull(Value v)
This can be overridden by sublasses to mark a certain value as constantly non-null.boolean
isAssumedNonNullBefore(Unit s, Immediate i)
Returnstrue
if the analysis could determine that i is always treated as non-null after and including the statement s.boolean
isAssumedNullBefore(Unit s, Immediate i)
Returnstrue
if the analysis could determine that i is always treated as null after and including the statement s.protected void
merge(NullnessAssumptionAnalysis.AnalysisInfo in1, NullnessAssumptionAnalysis.AnalysisInfo in2, NullnessAssumptionAnalysis.AnalysisInfo out)
Compute the merge of thein1
andin2
sets, putting the result intoout
.protected NullnessAssumptionAnalysis.AnalysisInfo
newInitialFlow()
Returns the flow object corresponding to the initial values for each graph node.-
Methods inherited from class soot.toolkits.scalar.BackwardFlowAnalysis
doAnalysis, isForward
-
Methods inherited from class soot.toolkits.scalar.FlowAnalysis
copyFreshToExisting, getFlow, getFlowAfter, getFlowBefore, omissible
-
Methods inherited from class soot.toolkits.scalar.AbstractFlowAnalysis
merge, mergeInto, treatTrapHandlersAsEntries
-
-
-
-
Constructor Detail
-
NullnessAssumptionAnalysis
public NullnessAssumptionAnalysis(UnitGraph graph)
Creates a new analysis for the given graph/- Parameters:
graph
- any unit graph
-
-
Method Detail
-
flowThrough
protected void flowThrough(NullnessAssumptionAnalysis.AnalysisInfo in, Unit unit, NullnessAssumptionAnalysis.AnalysisInfo outValue)
Given the merge of theout
sets, compute thein
set fors
(or in to out, depending on direction). This function often causes confusion, because the same interface is used for both forward and backward flow analyses. The first parameter is always the argument to the flow function (i.e. it is the "in" set in a forward analysis and the "out" set in a backward analysis), and the third parameter is always the result of the flow function (i.e. it is the "out" set in a forward analysis and the "in" set in a backward analysis).- Specified by:
flowThrough
in classFlowAnalysis<Unit,NullnessAssumptionAnalysis.AnalysisInfo>
- Parameters:
in
- the input flowunit
- the current nodeoutValue
- the returned flow
-
isAlwaysNonNull
protected boolean isAlwaysNonNull(Value v)
This can be overridden by sublasses to mark a certain value as constantly non-null.- Parameters:
v
- any value- Returns:
- true if it is known that this value (e.g. a method return value) is never null
-
copy
protected void copy(NullnessAssumptionAnalysis.AnalysisInfo source, NullnessAssumptionAnalysis.AnalysisInfo dest)
Creates a copy of thesource
flow object indest
.- Specified by:
copy
in classAbstractFlowAnalysis<Unit,NullnessAssumptionAnalysis.AnalysisInfo>
-
entryInitialFlow
protected NullnessAssumptionAnalysis.AnalysisInfo entryInitialFlow()
Returns the initial flow value for entry/exit graph nodes. This is equal toAbstractFlowAnalysis.newInitialFlow()
- Overrides:
entryInitialFlow
in classAbstractFlowAnalysis<Unit,NullnessAssumptionAnalysis.AnalysisInfo>
-
merge
protected void merge(NullnessAssumptionAnalysis.AnalysisInfo in1, NullnessAssumptionAnalysis.AnalysisInfo in2, NullnessAssumptionAnalysis.AnalysisInfo out)
Compute the merge of thein1
andin2
sets, putting the result intoout
. The behavior of this function depends on the implementation ( it may be necessary to check whetherin1
andin2
are equal or aliased ). Used by the doAnalysis method.- Specified by:
merge
in classAbstractFlowAnalysis<Unit,NullnessAssumptionAnalysis.AnalysisInfo>
-
newInitialFlow
protected NullnessAssumptionAnalysis.AnalysisInfo newInitialFlow()
Returns the flow object corresponding to the initial values for each graph node.- Specified by:
newInitialFlow
in classAbstractFlowAnalysis<Unit,NullnessAssumptionAnalysis.AnalysisInfo>
-
isAssumedNullBefore
public boolean isAssumedNullBefore(Unit s, Immediate i)
Returnstrue
if the analysis could determine that i is always treated as null after and including the statement s.- Parameters:
s
- a statement of the respective bodyi
- a local or constant of that body- Returns:
- true if i is always null right before this statement
-
isAssumedNonNullBefore
public boolean isAssumedNonNullBefore(Unit s, Immediate i)
Returnstrue
if the analysis could determine that i is always treated as non-null after and including the statement s.- Parameters:
s
- a statement of the respective bodyi
- a local of that body- Returns:
- true if i is always non-null right before this statement
-
-