MCPcopy Create free account
hub / github.com/LFYSec/MScan / CatchResult

Class CatchResult

src/main/java/pascal/taie/analysis/exception/CatchResult.java:35–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33import java.util.Set;
34
35public class CatchResult {
36
37 private final Map<Stmt, MultiMap<Stmt, ClassType>> caughtImplicit = Maps.newHybridMap();
38
39 private final MultiMap<Stmt, ClassType> uncaughtImplicit
40 = Maps.newMultiMap(Maps.newHybridMap());
41
42 private final Map<Stmt, MultiMap<Stmt, ClassType>> caughtExplicit = Maps.newHybridMap();
43
44 private final MultiMap<Stmt, ClassType> uncaughtExplicit
45 = Maps.newMultiMap(Maps.newHybridMap());
46
47 void addCaughtImplicit(Stmt stmt, Catch catcher, ClassType exceptionType) {
48 caughtImplicit.computeIfAbsent(stmt, s -> Maps.newMultiMap(Maps.newHybridMap()))
49 .put(catcher, exceptionType);
50 }
51
52 void addUncaughtImplicit(Stmt stmt, ClassType exceptionType) {
53 uncaughtImplicit.put(stmt, exceptionType);
54 }
55
56 /**
57 * @return all exception types that may be implicitly thrown by given Stmt
58 * and caught by its containing method. The result of the call is a map
59 * from Catch statements to set of exception types that are caught
60 * by the Catches.
61 */
62 public MultiMap<Stmt, ClassType> getCaughtImplicitOf(Stmt stmt) {
63 return caughtImplicit.getOrDefault(stmt, Maps.newMultiMap(Map.of()));
64 }
65
66 /**
67 * @return the set of exception types that may be implicitly thrown
68 * by given Stmt but not caught by its containing method.
69 */
70 public Set<ClassType> getUncaughtImplicitOf(Stmt stmt) {
71 return uncaughtImplicit.get(stmt);
72 }
73
74 void addCaughtExplicit(Stmt stmt, Catch catcher, ClassType exceptionType) {
75 caughtExplicit.computeIfAbsent(stmt, s -> Maps.newMultiMap())
76 .put(catcher, exceptionType);
77 }
78
79 void addUncaughtExplicit(Stmt stmt, ClassType exceptionType) {
80 uncaughtExplicit.put(stmt, exceptionType);
81 }
82
83 /**
84 * @return all exception types that may be explicitly thrown by given Stmt
85 * and caught by its containing method. The result of the call is a map
86 * from Catch statements to set of exception types that are caught
87 * by the Catches.
88 */
89 public MultiMap<Stmt, ClassType> getCaughtExplicitOf(Stmt stmt) {
90 return caughtExplicit.getOrDefault(stmt, Maps.newMultiMap());
91 }
92

Callers

nothing calls this directly

Calls 2

newHybridMapMethod · 0.95
newMultiMapMethod · 0.95

Tested by

no test coverage detected