[Soot-list] Help!! Analysis a class with throws statement

hxj hxj163 at gmail.com
Thu Mar 15 18:38:20 EDT 2012


Dear developer,

I have a class with a throw exception statement:

package testers;

public class test1  {

     public void test1(int a) {
             if (a==0) {
               throw new IllegalArgumentException("avcde");
             }
     }
}


And I want to analysis each statement in this class. So I created a 
simple class:

public class RunIt
{
     public static void main(String[] args) {
         args = new String[] {"testers.test1"};
         SootClass sClass = Scene.v().loadClassAndSupport(args[0]);
         sClass.setApplicationClass();

         Iterator methodIt = sClass.getMethods().iterator();
         while (methodIt.hasNext()) {
             SootMethod m = (SootMethod)methodIt.next();

Body b = m.retrieveActiveBody();
             UnitGraph g = new ExceptionalUnitGraph(b);

             Iterator unitIt = g.iterator();
             while (unitIt.hasNext()) {
                      Unit s = (Unit) unitIt.next();
                      Stmt tmp = (Stmt) s;
                      System.out.println(tmp.toString());
             }
         }
     }
}

Then I got the following exception:

Exception in thread "main" java.lang.IllegalStateException: RefType 
java.lang.ArithmeticException not loaded. If you tried to get the 
RefType of a library class, did you call loadNecessaryClasses()? 
Otherwise please check Soot's classpath.
     at soot.Scene.getRefType(Scene.java:444)
     at 
soot.toolkits.exceptions.ThrowableSet$Manager.<init>(ThrowableSet.java:193)
     at 
soot.Singletons.soot_toolkits_exceptions_ThrowableSet_Manager(Singletons.java:765)
     at 
soot.toolkits.exceptions.ThrowableSet$Manager.v(ThrowableSet.java:275)
     at 
soot.toolkits.exceptions.PedanticThrowAnalysis.mightThrow(PedanticThrowAnalysis.java:67)
     at 
soot.toolkits.graph.ExceptionalUnitGraph.buildExceptionDests(ExceptionalUnitGraph.java:342)
     at 
soot.toolkits.graph.ExceptionalUnitGraph.initialize(ExceptionalUnitGraph.java:263)
     at 
soot.toolkits.graph.ExceptionalUnitGraph.<init>(ExceptionalUnitGraph.java:149)
     at 
soot.toolkits.graph.ExceptionalUnitGraph.<init>(ExceptionalUnitGraph.java:181)
     at 
soot.toolkits.scalar.LocalSplitter.internalTransform(LocalSplitter.java:77)
     at soot.BodyTransformer.transform(BodyTransformer.java:51)
     at soot.Transform.apply(Transform.java:104)
     at soot.JimpleBodyPack.applyPhaseOptions(JimpleBodyPack.java:57)
     at soot.JimpleBodyPack.internalApply(JimpleBodyPack.java:89)
     at soot.Pack.apply(Pack.java:124)
     at soot.coffi.CoffiMethodSource.getBody(CoffiMethodSource.java:117)
     at soot.SootMethod.getBodyFromMethodSource(SootMethod.java:82)
     at soot.SootMethod.retrieveActiveBody(SootMethod.java:315)
     at dk.brics.soot.RunIt.main(RunIt.java:22)


I know this RunIt class could be used to print out all of statements in 
a class without throws statement. But I don't know how to change the 
code to analysis a class with throws. So I need your help!

Thanks very much!

Best regards,
Eve



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20120315/05cd996c/attachment.html 


More information about the Soot-list mailing list