diff --git a/com.ibm.wala.cast.java/src/com/ibm/wala/cast/java/ipa/callgraph/JavaScopeMappingInstanceKeys.java b/com.ibm.wala.cast.java/src/com/ibm/wala/cast/java/ipa/callgraph/JavaScopeMappingInstanceKeys.java index b6b8b949c..1398a36a5 100644 --- a/com.ibm.wala.cast.java/src/com/ibm/wala/cast/java/ipa/callgraph/JavaScopeMappingInstanceKeys.java +++ b/com.ibm.wala.cast.java/src/com/ibm/wala/cast/java/ipa/callgraph/JavaScopeMappingInstanceKeys.java @@ -23,10 +23,8 @@ import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.ipa.callgraph.propagation.InstanceKey; import com.ibm.wala.ipa.callgraph.propagation.InstanceKeyFactory; import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder; -import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.util.collections.HashSetFactory; -import com.ibm.wala.util.debug.Assertions; public class JavaScopeMappingInstanceKeys extends ScopeMappingInstanceKeys { @@ -38,29 +36,26 @@ public class JavaScopeMappingInstanceKeys extends ScopeMappingInstanceKeys { protected LexicalParent[] getParents(InstanceKey base) { IClass cls = base.getConcreteType(); if (isPossiblyLexicalClass(cls)) { - try { - Set result = HashSetFactory.make(); + Set result = HashSetFactory.make(); - for (Iterator MS = cls.getAllMethods().iterator(); MS.hasNext();) { - IMethod m = (IMethod) MS.next(); - if ((m instanceof AstMethod) && !m.isStatic()) { - AstMethod M = (AstMethod) m; - LexicalParent[] parents = M.getParents(); - for (int i = 0; i < parents.length; i++) { - result.add(parents[i]); - } + for (Iterator MS = cls.getAllMethods().iterator(); MS.hasNext();) { + IMethod m = (IMethod) MS.next(); + if ((m instanceof AstMethod) && !m.isStatic()) { + AstMethod M = (AstMethod) m; + LexicalParent[] parents = M.getParents(); + for (int i = 0; i < parents.length; i++) { + result.add(parents[i]); } } - - if (!result.isEmpty()) { - if (AstTranslator.DEBUG_LEXICAL) - System.err.println((base + " has parents: " + result)); - - return (LexicalParent[]) result.toArray(new LexicalParent[result.size()]); - } - } catch (ClassHierarchyException e) { - Assertions.UNREACHABLE(); } + + if (!result.isEmpty()) { + if (AstTranslator.DEBUG_LEXICAL) + System.err.println((base + " has parents: " + result)); + + return (LexicalParent[]) result.toArray(new LexicalParent[result.size()]); + } + } if (AstTranslator.DEBUG_LEXICAL) diff --git a/com.ibm.wala.cast/source/java/com/ibm/wala/cast/loader/AstClass.java b/com.ibm.wala.cast/source/java/com/ibm/wala/cast/loader/AstClass.java index 70221ae2d..ed04e5224 100644 --- a/com.ibm.wala.cast/source/java/com/ibm/wala/cast/loader/AstClass.java +++ b/com.ibm.wala.cast/source/java/com/ibm/wala/cast/loader/AstClass.java @@ -202,7 +202,7 @@ abstract public class AstClass implements IClass, ClassConstants { return result; } - public Collection getAllMethods() throws ClassHierarchyException { + public Collection getAllMethods() { Collection result = HashSetFactory.make(); for (Iterator ms = getDeclaredMethods().iterator(); ms.hasNext();) { result.add(ms.next()); diff --git a/com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/JavaLangClassContextInterpreter.java b/com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/JavaLangClassContextInterpreter.java index ff0441b8f..a1155ed78 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/JavaLangClassContextInterpreter.java +++ b/com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/JavaLangClassContextInterpreter.java @@ -23,7 +23,6 @@ import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.NewSiteReference; import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter; -import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.summaries.SyntheticIR; import com.ibm.wala.ssa.ConstantValue; import com.ibm.wala.ssa.DefUse; @@ -45,19 +44,19 @@ import com.ibm.wala.util.collections.NonNullSingletonIterator; import com.ibm.wala.util.debug.Assertions; /** - * An {@link SSAContextInterpreter} specialized to interpret methods on java.lang.Class in a {@link JavaTypeContext} - * which represents the point-type of the class object created by the call. + * An {@link SSAContextInterpreter} specialized to interpret methods on java.lang.Class in a {@link JavaTypeContext} which + * represents the point-type of the class object created by the call. * * Currently supported methods: *
    - *
  • getConstructor - *
  • getConstructors - *
  • getMethod - *
  • getMethods - *
  • getDeclaredConstructor - *
  • getDeclaredConstructors - *
  • getDeclaredMethod - *
  • getDeclaredMethods + *
  • getConstructor + *
  • getConstructors + *
  • getMethod + *
  • getMethods + *
  • getDeclaredConstructor + *
  • getDeclaredConstructors + *
  • getDeclaredMethod + *
  • getDeclaredMethods *
* * @author pistoia @@ -67,28 +66,28 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { public final static MethodReference GET_CONSTRUCTOR = MethodReference.findOrCreate(TypeReference.JavaLangClass, "getConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;"); - + public final static MethodReference GET_CONSTRUCTORS = MethodReference.findOrCreate(TypeReference.JavaLangClass, "getConstructors", "()[Ljava/lang/reflect/Constructor;"); - + public final static MethodReference GET_METHOD = MethodReference.findOrCreate(TypeReference.JavaLangClass, "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); - + public final static MethodReference GET_METHODS = MethodReference.findOrCreate(TypeReference.JavaLangClass, "getMethods", "()[Ljava/lang/reflect/Method;"); - + public final static MethodReference GET_DECLARED_CONSTRUCTOR = MethodReference.findOrCreate(TypeReference.JavaLangClass, "getDeclaredConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;"); - + public final static MethodReference GET_DECLARED_CONSTRUCTORS = MethodReference.findOrCreate(TypeReference.JavaLangClass, "getDeclaredConstructors", "()[Ljava/lang/reflect/Constructor;"); public final static MethodReference GET_DECLARED_METHOD = MethodReference.findOrCreate(TypeReference.JavaLangClass, "getDeclaredMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); - + public final static MethodReference GET_DECLARED_METHODS = MethodReference.findOrCreate(TypeReference.JavaLangClass, "getDeclaredMethods", "()[Ljava/lang/reflect/Method;"); - + private static final boolean DEBUG = false; /* @@ -172,10 +171,9 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { return false; } MethodReference mRef = node.getMethod().getReference(); - return mRef.equals(GET_CONSTRUCTOR) || mRef.equals(GET_CONSTRUCTORS) - || mRef.equals(GET_METHOD) || mRef.equals(GET_METHODS) - || mRef.equals(GET_DECLARED_CONSTRUCTOR) || mRef.equals(GET_DECLARED_CONSTRUCTORS) - || mRef.equals(GET_DECLARED_METHOD) || mRef.equals(GET_DECLARED_METHODS); + return mRef.equals(GET_CONSTRUCTOR) || mRef.equals(GET_CONSTRUCTORS) || mRef.equals(GET_METHOD) || mRef.equals(GET_METHODS) + || mRef.equals(GET_DECLARED_CONSTRUCTOR) || mRef.equals(GET_DECLARED_CONSTRUCTORS) || mRef.equals(GET_DECLARED_METHOD) + || mRef.equals(GET_DECLARED_METHODS); } public Iterator iterateNewSites(CGNode node) { @@ -212,19 +210,14 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { } return result; } - + /** * Get all non-constructor, non-class-initializer methods declared by a class and all its superclasses */ private Collection getAllNormalPublicMethods(IClass cls) { Collection result = HashSetFactory.make(); Collection allMethods = null; - try { - allMethods = cls.getAllMethods(); - } catch (ClassHierarchyException e) { - Assertions.UNREACHABLE(); - e.printStackTrace(); - } + allMethods = cls.getAllMethods(); for (IMethod m : allMethods) { if (!m.isInit() && !m.isClinit() && m.isPublic()) { result.add(m); @@ -232,7 +225,6 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { } return result; } - /** * Get all the constructors of a class @@ -246,7 +238,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { } return result; } - + /** * Get all the public constructors of a class */ @@ -287,8 +279,8 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { int index = i++; int indexVn = nextLocal++; constants.put(indexVn, new ConstantValue(index)); - SSAArrayStoreInstruction store = insts.ArrayStoreInstruction(retValue, indexVn, c, - TypeReference.JavaLangReflectConstructor); + SSAArrayStoreInstruction store = insts + .ArrayStoreInstruction(retValue, indexVn, c, TypeReference.JavaLangReflectConstructor); statements.add(store); } SSAReturnInstruction R = insts.ReturnInstruction(retValue, false); @@ -307,9 +299,8 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { } /** - * create statements for methods like getConstructor() and getDeclaredMethod(), which return a single method. This - * creates a return statement for each possible return value, each of which is a {@link ConstantValue} for an - * {@link IMethod}. + * create statements for methods like getConstructor() and getDeclaredMethod(), which return a single method. This creates a + * return statement for each possible return value, each of which is a {@link ConstantValue} for an {@link IMethod}. * * @param returnValues the possible return values for this method. */ @@ -338,7 +329,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { } return result; } - + /** * create statements for getConstructor() */ @@ -350,8 +341,8 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { return getParticularMethodStatements(GET_CONSTRUCTOR, getPublicConstructors(cls), context, constants); } } - - //TODO + + // TODO private SSAInstruction[] makeGetCtorsStatements(JavaTypeContext context, Map constants) { IClass cls = context.getType().getType(); if (cls == null) { @@ -360,7 +351,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { return getMethodArrayStatements(GET_DECLARED_CONSTRUCTORS, getPublicConstructors(cls), context, constants); } } - + private SSAInstruction[] makeGetMethodStatements(JavaTypeContext context, Map constants) { IClass cls = context.getType().getType(); if (cls == null) { @@ -369,7 +360,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { return getParticularMethodStatements(GET_METHOD, getAllNormalPublicMethods(cls), context, constants); } } - + private SSAInstruction[] makeGetMethodsStatments(JavaTypeContext context, Map constants) { IClass cls = context.getType().getType(); if (cls == null) { @@ -390,7 +381,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { return getParticularMethodStatements(GET_DECLARED_CONSTRUCTOR, getConstructors(cls), context, constants); } } - + private SSAInstruction[] makeGetDeclCtorsStatements(JavaTypeContext context, Map constants) { IClass cls = context.getType().getType(); if (cls == null) { @@ -399,7 +390,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { return getMethodArrayStatements(GET_DECLARED_CONSTRUCTORS, getConstructors(cls), context, constants); } } - + /** * create statements for getDeclaredMethod() */ @@ -411,7 +402,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { return getParticularMethodStatements(GET_DECLARED_METHOD, getDeclaredNormalMethods(cls), context, constants); } } - + /** * create statements for getDeclaredMethod() */ @@ -423,7 +414,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter { return getMethodArrayStatements(GET_DECLARED_METHODS, getDeclaredNormalMethods(cls), context, constants); } } - + public boolean recordFactoryType(CGNode node, IClass klass) { return false; } diff --git a/com.ibm.wala.core/src/com/ibm/wala/classLoader/ArrayClass.java b/com.ibm.wala.core/src/com/ibm/wala/classLoader/ArrayClass.java index 3ef1ef2db..edb6caede 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/classLoader/ArrayClass.java +++ b/com.ibm.wala.core/src/com/ibm/wala/classLoader/ArrayClass.java @@ -295,7 +295,7 @@ public class ArrayClass implements IClass, Constants { /* * @see com.ibm.wala.classLoader.IClass#getAllMethods() */ - public Collection getAllMethods() throws UnimplementedError, ClassHierarchyException { + public Collection getAllMethods() { return loader.lookupClass(getClassLoader().getLanguage().getRootType().getName()).getAllMethods(); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/classLoader/BytecodeClass.java b/com.ibm.wala.core/src/com/ibm/wala/classLoader/BytecodeClass.java index 53c5fc689..b39ee0511 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/classLoader/BytecodeClass.java +++ b/com.ibm.wala.core/src/com/ibm/wala/classLoader/BytecodeClass.java @@ -317,7 +317,7 @@ public abstract class BytecodeClass implements IClass { /* * @see com.ibm.wala.classLoader.IClass#getAllMethods() */ - public Collection getAllMethods() throws ClassHierarchyException { + public Collection getAllMethods() { Collection result = new LinkedList(); Iterator declaredMethods = getDeclaredMethods().iterator(); while (declaredMethods.hasNext()) { diff --git a/com.ibm.wala.core/src/com/ibm/wala/classLoader/IClass.java b/com.ibm.wala.core/src/com/ibm/wala/classLoader/IClass.java index 37bdb20f0..5ad07b843 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/classLoader/IClass.java +++ b/com.ibm.wala.core/src/com/ibm/wala/classLoader/IClass.java @@ -134,7 +134,7 @@ public interface IClass extends IClassHierarchyDweller { /** * Compute the methods declared by this class or any of its superclasses. */ - Collection getAllMethods() throws ClassHierarchyException; + Collection getAllMethods(); /** * Compute the instance fields declared by this class. diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/FakeRootClass.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/FakeRootClass.java index 18b29cfef..a0e853450 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/FakeRootClass.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/FakeRootClass.java @@ -219,7 +219,7 @@ public class FakeRootClass extends SyntheticClass { /* * @see com.ibm.wala.classLoader.IClass#getAllMethods() */ - public Collection getAllMethods() throws UnsupportedOperationException, ClassHierarchyException { + public Collection getAllMethods() { throw new UnsupportedOperationException(); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/summaries/BypassSyntheticClass.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/summaries/BypassSyntheticClass.java index 0abb11ea0..07a7555a8 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/summaries/BypassSyntheticClass.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/summaries/BypassSyntheticClass.java @@ -221,7 +221,7 @@ public class BypassSyntheticClass extends SyntheticClass { /* * @see com.ibm.wala.classLoader.IClass#getAllMethods() */ - public Collection getAllMethods() throws ClassHierarchyException { + public Collection getAllMethods() { return realType.getAllMethods(); } diff --git a/com.ibm.wala.j2ee/src/com/ibm/wala/j2ee/ActionFormFactoryMethod.java b/com.ibm.wala.j2ee/src/com/ibm/wala/j2ee/ActionFormFactoryMethod.java index 0ddcf70ee..28c5f85d1 100644 --- a/com.ibm.wala.j2ee/src/com/ibm/wala/j2ee/ActionFormFactoryMethod.java +++ b/com.ibm.wala.j2ee/src/com/ibm/wala/j2ee/ActionFormFactoryMethod.java @@ -77,7 +77,7 @@ public class ActionFormFactoryMethod extends SummarizedMethod { return Collections.emptySet(); } - public Collection getAllMethods() throws ClassHierarchyException { + public Collection getAllMethods() { // TODO Auto-generated method stub assert false; return null;