Class ThrowableSet
- java.lang.Object
-
- soot.toolkits.exceptions.ThrowableSet
-
public class ThrowableSet extends Object
A class for representing the set of exceptions that an instruction may throw.
ThrowableSetdoes not implement theSetinterface, so perhaps it is misnamed. Instead, it provides only the operations that we require for determining whether a given statement might throw an exception that would be caught by a given handler.There is a limitation on the combinations of operations permitted on a
ThrowableSet. TheThrowableSets returned bywhichCatchableAs(RefType)cannot be involved in subsequentadd()orwhichCatchableAs()operations. That is, given
for anyp = s.whichCatchableAs(r)ThrowableSetsandRefTyper, and
then calls tot == p.getUncaught()ort == p.getCaught()t.add(r),t.add(a), ands.add(t), will throw anThrowableSet.AlreadyHasExclusionsException, for anyRefTyper,AnySubTypea, andThrowableSett.Actually the restrictions implemented are not quite so strict (there are some combinations of
whichCatchableAs()followed byadd()which will not raise an exception), but a more accurate description would require reference to the internals of the current implementation. The restrictions should not be too onerous forThrowableSet's anticipated uses: we expectThrowableSets to grow by accumulating all the exception types that a givenUnitmay throw, then, shrink as the types caught by different exception handlers are removed to yield the sets representing exceptions which escape those handlers.The
ThrowableSetclass is intended to be immutable (hence thefinalmodifier on its declaration). It does not take the step of guaranteeing immutability by cloning theRefLikeTypeobjects it contains, though, because we trustSceneto enforce the existence of only oneRefLikeTypeinstance with a given name.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classThrowableSet.AlreadyHasExclusionsExceptionstatic classThrowableSet.ManagerSingleton class for fields and initializers common to all ThrowableSet objects (i.e., these would be static fields and initializers, in the absence of soot'sGandSingletonsclasses).static classThrowableSet.PairThe return type forwhichCatchableAs(RefType), consisting of a pair of ThrowableSets.
-
Field Summary
Fields Modifier and Type Field Description protected Set<AnySubType>exceptionsExcludedSet of exception types which, though members of exceptionsIncluded, are to be excluded from the types represented by thisThrowableSet.protected Set<RefLikeType>exceptionsIncludedSet of exception types included within the set.protected Map<Object,ThrowableSet>memoizedAdds
-
Constructor Summary
Constructors Modifier Constructor Description protectedThrowableSet(Set<RefLikeType> include, Set<AnySubType> exclude)Constructs aThrowableSetwhich contains the exception types represented ininclude, except for those which are also inexclude.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThrowableSetadd(AnySubType e)Returns aThrowableSetwhich containseand all of its subclasses as well as the exceptions in this set.ThrowableSetadd(RefType e)Returns aThrowableSetwhich containsein addition to the exceptions in thisThrowableSet.ThrowableSetadd(ThrowableSet s)Returns aThrowableSetwhich contains all the exceptions insin addition to those in thisThrowableSet.booleancatchableAs(RefType catcher)Indicates whether this ThrowableSet includes some exception that might be caught by a handler argument of the typecatcher.booleanequals(Object obj)inthashCode()booleanisEmpty()Returns true if the throwable set is empty and false otherwise.ThrowableSetremove(ThrowableSet s)Returns aThrowableSetwhich contains all the exceptions from the current set except for those in the givenThrowableSet.StringtoAbbreviatedString()Produce an abbreviated representation of thisThrowableSet, suitable for human consumption.StringtoBriefString()Returns a cryptic identifier for thisThrowableSet, used to identify a set when it appears in a collection.StringtoString()Returns a string representation of thisThrowableSet.ThrowableSet.PairwhichCatchableAs(RefType catcher)Partitions the exceptions in thisThrowableSetinto those which would be caught by a handler with the passedcatchparameter type and those which would not.
-
-
-
Field Detail
-
exceptionsIncluded
protected final Set<RefLikeType> exceptionsIncluded
Set of exception types included within the set.
-
exceptionsExcluded
protected final Set<AnySubType> exceptionsExcluded
Set of exception types which, though members of exceptionsIncluded, are to be excluded from the types represented by thisThrowableSet. To simplify the implementation, once aThrowableSethas any excluded types, the variousadd()methods of this class must bar additions of subtypes of those excluded types.
-
memoizedAdds
protected Map<Object,ThrowableSet> memoizedAdds
A map from (RefLikeType\\unionThrowableSet) toThrowableSet. If the mapping (k,v) is inmemoizedAddsand k is aThrowableSet, then v is the set that results from adding all elements in k tothis. If (k,v) is inmemoizedAddsand k is aRefLikeType, then v is the set that results from adding k tothis.
-
-
Constructor Detail
-
ThrowableSet
protected ThrowableSet(Set<RefLikeType> include, Set<AnySubType> exclude)
Constructs aThrowableSetwhich contains the exception types represented ininclude, except for those which are also inexclude. The constructor is private to ensure that the only way to get a newThrowableSetis by adding elements to or removing them from an existing set.- Parameters:
include- The set ofRefTypeandAnySubTypeobjects representing the types to be included in the set.exclude- The set ofAnySubTypeobjects representing the types to be excluded from the set.
-
-
Method Detail
-
add
public ThrowableSet add(RefType e) throws ThrowableSet.AlreadyHasExclusionsException
Returns aThrowableSetwhich containsein addition to the exceptions in thisThrowableSet.Add
eas aRefTypewhen you know that the run-time class of the exception you are representing is necessarilyeand cannot be a subclass ofe.For example, if you were recording the type of the exception thrown by
throw new IOException("Permission denied");you would call
since the class of the exception is necessarilyadd(Scene.v().getRefType("java.lang.Exception.IOException"))IOException.- Parameters:
e- the exception class- Returns:
- a set containing
eas well as the exceptions in this set. - Throws:
ThrowableSet.AlreadyHasExclusionsException
-
add
public ThrowableSet add(AnySubType e) throws ThrowableSet.AlreadyHasExclusionsException
Returns aThrowableSetwhich containseand all of its subclasses as well as the exceptions in this set.eshould be an instance ofAnySubTypeif you know that the compile-time type of the exception you are representing ise, but the exception may be instantiated at run-time by a subclass ofe.For example, if you were recording the type of the exception thrown by
catch (IOException e) { throw e; }you would call
since the handler might rethrow any subclass ofadd(AnySubtype.v(Scene.v().getRefType("java.lang.Exception.IOException")))IOException.- Parameters:
e- represents a subtree of the exception class hierarchy to add to this set.- Returns:
- a set containing
eand all its subclasses, as well as the exceptions represented by this set. - Throws:
ThrowableSet.AlreadyHasExclusionsException- if thisThrowableSetis the result of awhichCatchableAs(RefType)operation and, thus, unable to represent the addition ofe.
-
add
public ThrowableSet add(ThrowableSet s) throws ThrowableSet.AlreadyHasExclusionsException
Returns aThrowableSetwhich contains all the exceptions insin addition to those in thisThrowableSet.- Parameters:
s- set of exceptions to add to this set.- Returns:
- the union of this set with
s - Throws:
ThrowableSet.AlreadyHasExclusionsException- if thisThrowableSetorsis the result of awhichCatchableAs(RefType)operation, so that it is not possible to represent the addition ofsto thisThrowableSet.
-
isEmpty
public boolean isEmpty()
Returns true if the throwable set is empty and false otherwise.- Returns:
- true if the throwable set is empty.
-
remove
public ThrowableSet remove(ThrowableSet s)
Returns aThrowableSetwhich contains all the exceptions from the current set except for those in the givenThrowableSet.- Parameters:
s- The set containing the exceptions to exclude from the new set- Returns:
- The exceptions that are only in this set, but not in the given set
- Throws:
ThrowableSet.AlreadyHasExclusionsException- if thisThrowableSetorsis the result of awhichCatchableAs(RefType)operation, so that it is not possible to represent the addition ofsto thisThrowableSet.
-
catchableAs
public boolean catchableAs(RefType catcher)
Indicates whether this ThrowableSet includes some exception that might be caught by a handler argument of the typecatcher.- Parameters:
catcher- type of the handler parameter to be tested.- Returns:
trueif this set contains an exception type that might be caught bycatcher, false if it does not.
-
whichCatchableAs
public ThrowableSet.Pair whichCatchableAs(RefType catcher)
Partitions the exceptions in thisThrowableSetinto those which would be caught by a handler with the passedcatchparameter type and those which would not.- Parameters:
catcher- type of the handler parameter to be tested.- Returns:
- a pair of
ThrowableSets, one containing the types in thisThrowableSetwhich would be be caught ascatcherand the other containing the types in thisThrowableSetwhich would not be caught ascatcher.
-
toString
public String toString()
Returns a string representation of thisThrowableSet.
-
toBriefString
public String toBriefString()
Returns a cryptic identifier for thisThrowableSet, used to identify a set when it appears in a collection.
-
toAbbreviatedString
public String toAbbreviatedString()
Produce an abbreviated representation of this
ThrowableSet, suitable for human consumption. The abbreviations include:- The strings “
java.lang.” is stripped from the beginning of exception names. - The string “
Exception” is stripped from the ends of exception names. - Instances of
AnySubTypeare indicated by surrounding the base type name with parentheses, rather than with the string “Any_subtype_of_” - If this
ThrowableSetincludes all the elements ofVM_ERRORS, they are abbreviated as “vmErrors” rather than listed individually.
- Returns:
- An abbreviated representation of the contents of this set.
- The strings “
-
-