How to compute, for each method, the set of exceptions that method may throw, including runtime exceptions?

StackOverflow https://stackoverflow.com/questions/18325936

문제

I'm trying to implement an intra-procedural analysis that computes, for each method, the set of exceptions that method may throw, including runtime exceptions that are explicitly thrown by means of a throw statement.

So far, I'm completely lost on how to start it with SOOT. Anyone can give me a first hint?

도움이 되었습니까?

해결책

You should look at implementations of ThrowsAnalysis. The analyses can be parameterized to make different assumptions about which statement can throw which exceptions. This analysis is intra-procedural, however, i.e., will have to make coarse assumptions about method calls. If you want to model method calls precisely then I recommend crafting an inter-procedural analysis with Heros.

Cheers, Eric

다른 팁

  1. Index the classes and interfaces in your body of source and .class files, according to what they extend or implement. If A extends B which extends C which implements D, A should appear in the set of classes for all of B, C, and D.
  2. Starting from each method, initializer, static initializer block etc., find each constructor or method it might call. Create a set of called methods that includes the corresponding method in each subclass. If you call D's get(int) method you must include the corresponding methods in A, B, and C. You can find them using the index from Step 1.
  3. Starting from a method of interest, such as the main method or methods, form the list of all methods and constructors that might be called directly or indirectly. In effect, "indirectly calls" is the transitive closure of the relation build in step 2.
  4. Examine each possibly called method or constructor in the result of step 3. For each throw statement, report the type of the operand.

I will be very, very surprised if there is a benefit from this that justifies the cost.

Here's one example of a problem area. If you use the HashMap get() method, you use the Object equals() and hashCode() methods. Every class directly or indirectly extends Object, so the argument type for any throw statement in any equals() or hashCode() method is on the list.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top