[Soot-list] exception in soot when throwing a null (resend)

John Jorgensen jorgnsn at lcd.uregina.ca
Thu Sep 15 00:34:36 EDT 2005


I'm embarrassed to admit that it never occurred to me when I
wrote AbstractThowAnalysis that there might be code where an
athrow's argument could be deduced at compile-time to be null. It
should have occurred to me, though, since the JVM specification
says clearly what athrow should do in that case: throw a
NullPointerException.

I'll attach a patch here for your immediate use, but it might not
be what gets committed to Soot.  First, even with the attached
patch, your example produces a later exception when I use Soot's
--dump-body argument (unlikely to be employed by most users, but
too useful in finding Soot bugs to leave broken).

Second, but maybe more fundamental, it occurs to me that since the
JLS says that null is assignment compatible with all reference
types, there might be an argument that soot.NullType _should_ be
made a subtype of soot.RefType, in which case the existing code in
AbstractThrowAnalysis would work.  No doubt there are all sorts
of reasons why NullType should not be a subclass of RefType, but I
want to give people who understand type theory the chance to
tell me those reasons.

>>>>> "jasencarro" == Jasen Carrol <jasencarro at yahoo.com> writes:

    jasencarro> I tried retrieving the active body of a method
    jasencarro> that contained the following code. This caused
    jasencarro> AbstractThrowAnalysis to throw:
    jasencarro> "java.lang.IllegalStateException:
    jasencarro> UnitThrowAnalysis StmtSwitch: type of throw
    jasencarro> argument is not a RefType!"

    jasencarro> void testException()
    jasencarro> {
    jasencarro>    RuntimeException x = null;
    jasencarro>    try
    jasencarro>    {
    jasencarro>       throw x;
    jasencarro>    }
    jasencarro>    catch(RuntimeException e)
    jasencarro>    {
    jasencarro>    }
    jasencarro> }

-------------- next part --------------
Index: src/soot/toolkits/exceptions/AbstractThrowAnalysis.java
===================================================================
--- src/soot/toolkits/exceptions/AbstractThrowAnalysis.java     (revision 2135)
+++ src/soot/toolkits/exceptions/AbstractThrowAnalysis.java     (working copy)
@@ -25,6 +25,7 @@
 import soot.Type;
 import soot.Unit;
 import soot.UnknownType;
+import soot.NullType;
 import soot.Value;
 import soot.Singletons;
 import soot.toolkits.exceptions.*;
@@ -59,6 +60,10 @@
        if (thrownType == null || thrownType instanceof UnknownType) {
            // We can't identify the type of thrownExpression, so...
            return ThrowableSet.Manager.v().ALL_THROWABLES;
+       } else if (thrownType instanceof NullType) {
+         ThrowableSet result = ThrowableSet.Manager.v().EMPTY;
+         result = result.add(ThrowableSet.Manager.v().NULL_POINTER_EXCEPTION);
+          return result;
        } else if (! (thrownType instanceof RefType)) {
            throw new IllegalStateException("UnitThrowAnalysis StmtSwitch: type of throw argument is not a RefType!");
        } else {


More information about the Soot-list mailing list