示例#1
0
  /**
   * Partitions the exceptions in this <code>ThrowableSet</code> into those which would be caught by
   * a handler with the passed <code>catch</code> parameter type and those which would not.
   *
   * @param catcher type of the handler parameter to be tested.
   * @return a pair of <code>ThrowableSet</code>s, one containing the types in this <code>
   *     ThrowableSet</code> which would be be caught as <code>catcher</code> and the other
   *     containing the types in this <code>ThrowableSet</code> which would not be caught as <code>
   *     catcher</code>.
   */
  public Pair whichCatchableAs(RefType catcher) {
    if (INSTRUMENTING) {
      Manager.v().removesOfAnySubType++;
    }

    FastHierarchy h = Scene.v().getOrMakeFastHierarchy();
    Set caughtIncluded = null;
    Set caughtExcluded = null;
    Set uncaughtIncluded = null;
    Set uncaughtExcluded = null;

    if (INSTRUMENTING) {
      Manager.v().removesFromSearch++;
    }

    for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
      AnySubType exclusion = (AnySubType) i.next();
      RefType exclusionBase = exclusion.getBase();
      if (h.canStoreType(catcher, exclusionBase)) {
        // Because the add() operations ban additions to sets
        // with exclusions, we can be sure no types in this are
        // caught by catcher.
        return new Pair(ThrowableSet.Manager.v().EMPTY, this);
      } else if (h.canStoreType(exclusionBase, catcher)) {
        // exclusion wouldn't be in exceptionsExcluded if one
        // of its supertypes were not in exceptionsIncluded,
        // so we know the next loop will add either that supertype
        // or catcher to caughtIncluded.  Thus:
        caughtExcluded = addExceptionToSet(exclusion, caughtExcluded);
      } else {
        uncaughtExcluded = addExceptionToSet(exclusion, uncaughtExcluded);
      }
    }

    for (Iterator i = exceptionsIncluded.iterator(); i.hasNext(); ) {
      RefLikeType inclusion = (RefLikeType) i.next();
      if (inclusion instanceof RefType) {
        if (h.canStoreType(inclusion, catcher)) {
          caughtIncluded = addExceptionToSet(inclusion, caughtIncluded);
        } else {
          uncaughtIncluded = addExceptionToSet(inclusion, uncaughtIncluded);
        }
      } else {
        RefType base = ((AnySubType) inclusion).getBase();
        if (h.canStoreType(base, catcher)) {
          // All subtypes of base will be caught.  Any exclusions
          // will already have been copied to caughtExcluded by
          // the preceding loop.
          caughtIncluded = addExceptionToSet(inclusion, caughtIncluded);
        } else if (h.canStoreType(catcher, base)) {
          // Some subtypes of base will be caught, and
          // we know that not all of those catchable subtypes
          // are among exceptionsExcluded, since in that case we
          // would already have returned from within the
          // preceding loop.  So, remove AnySubType(catcher)
          // from the uncaught types.
          uncaughtIncluded = addExceptionToSet(inclusion, uncaughtIncluded);
          uncaughtExcluded = addExceptionToSet(AnySubType.v(catcher), uncaughtExcluded);
          caughtIncluded = addExceptionToSet(AnySubType.v(catcher), caughtIncluded);
          // Any already excluded subtypes of inclusion
          // which are subtypes of catcher will have been
          // added to caughtExcluded by the previous loop.
        } else {
          uncaughtIncluded = addExceptionToSet(inclusion, uncaughtIncluded);
        }
      }
    }
    ThrowableSet caughtSet = Manager.v().registerSetIfNew(caughtIncluded, caughtExcluded);
    ThrowableSet uncaughtSet = Manager.v().registerSetIfNew(uncaughtIncluded, uncaughtExcluded);
    return new Pair(caughtSet, uncaughtSet);
  }
示例#2
0
    /**
     * Constructs a <code>ThrowableSet.Manager</code> for inclusion in Soot's global variable
     * manager, {@link G}.
     *
     * @param g guarantees that the constructor may only be called from {@link Singletons}.
     */
    public Manager(Singletons.Global g) {
      // First ensure the Exception classes are represented in Soot.

      // Runtime errors:
      RUNTIME_EXCEPTION = Scene.v().getRefType("java.lang.RuntimeException");
      ARITHMETIC_EXCEPTION = Scene.v().getRefType("java.lang.ArithmeticException");
      ARRAY_STORE_EXCEPTION = Scene.v().getRefType("java.lang.ArrayStoreException");
      CLASS_CAST_EXCEPTION = Scene.v().getRefType("java.lang.ClassCastException");
      ILLEGAL_MONITOR_STATE_EXCEPTION =
          Scene.v().getRefType("java.lang.IllegalMonitorStateException");
      INDEX_OUT_OF_BOUNDS_EXCEPTION = Scene.v().getRefType("java.lang.IndexOutOfBoundsException");
      ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION =
          Scene.v().getRefType("java.lang.ArrayIndexOutOfBoundsException");
      NEGATIVE_ARRAY_SIZE_EXCEPTION = Scene.v().getRefType("java.lang.NegativeArraySizeException");
      NULL_POINTER_EXCEPTION = Scene.v().getRefType("java.lang.NullPointerException");

      INSTANTIATION_ERROR = Scene.v().getRefType("java.lang.InstantiationError");

      EMPTY = registerSetIfNew(null, null);

      Set allThrowablesSet = new HashSet();
      allThrowablesSet.add(AnySubType.v(Scene.v().getRefType("java.lang.Throwable")));
      ALL_THROWABLES = registerSetIfNew(allThrowablesSet, null);

      Set vmErrorSet = new HashSet();
      vmErrorSet.add(Scene.v().getRefType("java.lang.InternalError"));
      vmErrorSet.add(Scene.v().getRefType("java.lang.OutOfMemoryError"));
      vmErrorSet.add(Scene.v().getRefType("java.lang.StackOverflowError"));
      vmErrorSet.add(Scene.v().getRefType("java.lang.UnknownError"));

      // The Java library's deprecated Thread.stop(Throwable) method
      // would actually allow _any_ Throwable to be delivered
      // asynchronously, not just java.lang.ThreadDeath.
      vmErrorSet.add(Scene.v().getRefType("java.lang.ThreadDeath"));

      VM_ERRORS = registerSetIfNew(vmErrorSet, null);

      Set resolveClassErrorSet = new HashSet();
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.ClassCircularityError"));
      // We add AnySubType(ClassFormatError) so that we can
      // avoid adding its subclass,
      // UnsupportedClassVersionError, explicitly.  This is a
      // hack to allow Soot to analyze older class libraries
      // (UnsupportedClassVersionError was added in JDK 1.2).

      // TODO: The class "ClassFormatError" does not exist in TakaTuka so our best guess is that
      // 			commenting the following line out won't affect the analysis in any way. But this
      //			is a "fault point" to look at if any problems arise in the future.
      // resolveClassErrorSet.add(AnySubType.v(Scene.v().getRefType("java.lang.ClassFormatError")));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.IllegalAccessError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.IncompatibleClassChangeError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.LinkageError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.NoClassDefFoundError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.VerifyError"));
      RESOLVE_CLASS_ERRORS = registerSetIfNew(resolveClassErrorSet, null);

      Set resolveFieldErrorSet = new HashSet(resolveClassErrorSet);
      resolveFieldErrorSet.add(Scene.v().getRefType("java.lang.NoSuchFieldError"));
      RESOLVE_FIELD_ERRORS = registerSetIfNew(resolveFieldErrorSet, null);

      Set resolveMethodErrorSet = new HashSet(resolveClassErrorSet);
      resolveMethodErrorSet.add(Scene.v().getRefType("java.lang.AbstractMethodError"));
      resolveMethodErrorSet.add(Scene.v().getRefType("java.lang.NoSuchMethodError"));
      resolveMethodErrorSet.add(Scene.v().getRefType("java.lang.UnsatisfiedLinkError"));
      RESOLVE_METHOD_ERRORS = registerSetIfNew(resolveMethodErrorSet, null);

      // The static initializers of a newly loaded class might
      // throw any Error (if they threw an Exception---even a
      // RuntimeException---it would be replaced by an
      // ExceptionInInitializerError):
      //
      Set initializationErrorSet = new HashSet();
      initializationErrorSet.add(AnySubType.v(Scene.v().getRefType("java.lang.Error")));
      INITIALIZATION_ERRORS = registerSetIfNew(initializationErrorSet, null);
    }