[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Soot bugs when first Unit is a target



Hi,

There is a rare (?) but plausible situation where the first Jimple
statement in a body is also a target of a branch. This causes
problems because there is some code that assumes that for targets,
target.getPredOf() always returns non-null, which of course is not
the case when the target is also the first Unit.

I've found and fixed a couple of these with the patch below.
Please review and commit to SVN.

However, having fixed those bugs, I get a little further but then
my same method with the first statement target also triggers
this exception:

    java.lang.NullPointerException
	at soot.jimple.toolkits.annotation.arraycheck.ArrayBoundsCheckerAnalysis.doAnalysis(ArrayBoundsCheckerAnalysis.java:381)
	at soot.jimple.toolkits.annotation.arraycheck.ArrayBoundsCheckerAnalysis.<init>(ArrayBoundsCheckerAnalysis.java:148)
	at soot.jimple.toolkits.annotation.arraycheck.ArrayBoundsChecker.internalTransform(ArrayBoundsChecker.java:87)
	at soot.BodyTransformer.transform(BodyTransformer.java:51)
	at soot.Transform.apply(Transform.java:88)
	at soot.BodyPack.internalApply(BodyPack.java:44)
	at soot.Pack.apply(Pack.java:113)

Most likely this bug is also triggered by the fact that the first
statement is also a target, but this one is more difficult for me
to decipher. All other methods are handled fine by the same code.

I'd love some help from the experts in this code; any suggestions
appreciated.

Thanks,
-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

diff -ur src.orig/soot/toolkits/graph/BlockGraph.java src/soot/toolkits/graph/BlockGraph.java
--- src.orig/soot/toolkits/graph/BlockGraph.java	Sat Nov 22 14:16:09 2003
+++ src/soot/toolkits/graph/BlockGraph.java	Wed Jul 14 21:48:26 2004
@@ -120,7 +120,9 @@
             // Get the leaders that bound exception contexts.
             if(type == ZONED) {              
               List predList = new ArrayList();
-              predList.add(mUnits.getPredOf(someTrap.getBeginUnit()));
+              if(mUnits.getPredOf(someTrap.getBeginUnit()) != null) {
+		  predList.add(mUnits.getPredOf(someTrap.getBeginUnit()));
+	      }
               leaders.put(someTrap.getBeginUnit(), predList);
 
               predList = new ArrayList();
@@ -189,7 +191,7 @@
                             predecessors= new LinkedList();
                             predecessors.add(currentUnit);
                             Unit targetPred = (Unit) mUnits.getPredOf(target);
-                            if(targetPred.fallsThrough())
+                            if(targetPred != null && targetPred.fallsThrough())
                                 predecessors.add(targetPred);
                                 
                             leaders.put(target, predecessors);
@@ -264,7 +266,7 @@
                                 predecessors= new LinkedList();
                                 predecessors.add(currentUnit);
                                 Unit targetPred = (Unit) mUnits.getPredOf(target);
-                                if(targetPred.fallsThrough())
+                                if(targetPred != null && targetPred.fallsThrough())
                                     predecessors.add(targetPred);
                             
                                 leaders.put(target, predecessors);