Package edu.umd.cs.findbugs.ba
Class Hierarchy
java.lang.Object
edu.umd.cs.findbugs.ba.Hierarchy
Facade for class hierarchy queries. These typically access the class
hierarchy using the
Repository
class. Callers should
generally expect to handle ClassNotFoundException for when referenced classes
can't be found.- Author:
- David Hovemeyer
-
Field Summary
Modifier and TypeFieldDescriptionstatic final JavaClassAndMethodChooser
JavaClassAndMethodChooser which accepts any method.static final JavaClassAndMethodChooser
JavaClassAndMethodChooser which accepts only concrete (not abstract or native) methods.protected static final boolean
static final ClassDescriptor
static final org.apache.bcel.generic.ObjectType
Type of java.lang.Error.static final ClassDescriptor
static final org.apache.bcel.generic.ObjectType
Type of java.lang.Exception.static final JavaClassAndMethodChooser
JavaClassAndMethodChooser which accepts only instance methods.static final ClassDescriptor
static final org.apache.bcel.generic.ObjectType
Type of java.lang.RuntimeException.static final JavaClassAndMethodChooser
JavaClassAndMethodChooser which accepts only static methods. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
accessFlagsAreConcrete
(int accessFlags) static JavaClassAndMethod
findConcreteMethod
(org.apache.bcel.classfile.JavaClass javaClass, String methodName, String methodSig) Deprecated.static org.apache.bcel.generic.ObjectType[]
findDeclaredExceptions
(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg) Deprecated.static JavaClassAndMethod
findExactMethod
(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg) Look up the method referenced by given InvokeInstruction.static JavaClassAndMethod
findExactMethod
(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg, JavaClassAndMethodChooser chooser) Look up the method referenced by given InvokeInstruction.static org.apache.bcel.classfile.Field
Find a field with given name defined in given class.static JavaClassAndMethod
findInvocationLeastUpperBound
(org.apache.bcel.classfile.JavaClass jClass, String methodName, String methodSig, JavaClassAndMethodChooser methodChooser, boolean invokeInterface) static JavaClassAndMethod
findInvocationLeastUpperBound
(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg) Find the least upper bound method in the class hierarchy which could be called by the given InvokeInstruction.static JavaClassAndMethod
findInvocationLeastUpperBound
(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg, JavaClassAndMethodChooser methodChooser) static XMethod
findMethod
(ClassDescriptor classDesc, String methodName, String methodSig, boolean isStatic) Find a method in given class.static JavaClassAndMethod
findMethod
(org.apache.bcel.classfile.JavaClass[] classList, String methodName, String methodSig) Deprecated.static JavaClassAndMethod
findMethod
(org.apache.bcel.classfile.JavaClass[] classList, String methodName, String methodSig, JavaClassAndMethodChooser chooser) Find a method in given list of classes, searching the classes in order.static JavaClassAndMethod
findMethod
(org.apache.bcel.classfile.JavaClass javaClass, String methodName, String methodSig) Find a method in given class.static JavaClassAndMethod
findMethod
(org.apache.bcel.classfile.JavaClass javaClass, String methodName, String methodSig, JavaClassAndMethodChooser chooser) static XField
findXField
(String className, String fieldName, String fieldSig, boolean isStatic) Look up a field with given name and signature in given class, returning it as anXField
object.static XField
findXField
(org.apache.bcel.generic.FieldInstruction fins, org.apache.bcel.generic.ConstantPoolGen cpg) Look up the field referenced by given FieldInstruction, returning it as anXField
object.static XMethod
findXMethod
(org.apache.bcel.classfile.JavaClass[] classList, String methodName, String methodSig) Deprecated.static XMethod
findXMethod
(org.apache.bcel.classfile.JavaClass[] classList, String methodName, String methodSig, JavaClassAndMethodChooser chooser) Deprecated.static XMethod
findXMethod
(org.apache.bcel.classfile.JavaClass javaClass, String methodName, String methodSig, JavaClassAndMethodChooser chooser) Deprecated.static InnerClassAccess
getInnerClassAccess
(org.apache.bcel.generic.INVOKESTATIC inv, org.apache.bcel.generic.ConstantPoolGen cpg) Get the InnerClassAccess for access method called by given INVOKESTATIC.static boolean
isConcrete
(XMethod xmethod) Deprecated.static boolean
isInnerClassAccess
(org.apache.bcel.generic.INVOKESTATIC inv, org.apache.bcel.generic.ConstantPoolGen cpg) Determine whether the given INVOKESTATIC instruction is an inner-class field accessor method.static boolean
isMonitorNotify
(String methodName, String methodSig) Determine if method whose name and signature is specified is a monitor notify operation.static boolean
isMonitorNotify
(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg) Determine if given Instruction is a monitor wait.static boolean
isMonitorWait
(String methodName, String methodSig) Determine if method whose name and signature is specified is a monitor wait operation.static boolean
isMonitorWait
(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg) Determine if given Instruction is a monitor wait.static boolean
Determine whether one class (or reference type) is a subtype of another.static boolean
isSubtype
(org.apache.bcel.generic.ReferenceType t, org.apache.bcel.generic.ReferenceType possibleSupertype) Determine if one reference type is a subtype of another.static boolean
isUncheckedException
(org.apache.bcel.generic.ObjectType type) Determine if the given ObjectType refers to an unchecked exception (RuntimeException or Error).static boolean
isUniversalExceptionHandler
(org.apache.bcel.generic.ObjectType catchType) Determine if the given ObjectType reference represents a universal exception handler.static Set<JavaClassAndMethod>
resolveMethodCallTargets
(org.apache.bcel.generic.InvokeInstruction invokeInstruction, TypeFrame typeFrame, org.apache.bcel.generic.ConstantPoolGen cpg) Resolve possible method call targets.static Set<JavaClassAndMethod>
resolveMethodCallTargets
(org.apache.bcel.generic.ReferenceType receiverType, org.apache.bcel.generic.InvokeInstruction invokeInstruction, org.apache.bcel.generic.ConstantPoolGen cpg) Resolve possible instance method call targets.static Set<JavaClassAndMethod>
resolveMethodCallTargets
(org.apache.bcel.generic.ReferenceType receiverType, org.apache.bcel.generic.InvokeInstruction invokeInstruction, org.apache.bcel.generic.ConstantPoolGen cpg, boolean receiverTypeIsExact) Resolve possible instance method call targets.static JavaClassAndMethod
visitSuperClassMethods
(JavaClassAndMethod method, JavaClassAndMethodChooser chooser) Visit all superclass methods which the given method overrides.static JavaClassAndMethod
visitSuperInterfaceMethods
(JavaClassAndMethod method, JavaClassAndMethodChooser chooser) Visit all superinterface methods which the given method implements.
-
Field Details
-
DEBUG_METHOD_LOOKUP
protected static final boolean DEBUG_METHOD_LOOKUP -
RUNTIME_EXCEPTION
-
EXCEPTION
-
ERROR
-
EXCEPTION_TYPE
public static final org.apache.bcel.generic.ObjectType EXCEPTION_TYPEType of java.lang.Exception. -
ERROR_TYPE
public static final org.apache.bcel.generic.ObjectType ERROR_TYPEType of java.lang.Error. -
RUNTIME_EXCEPTION_TYPE
public static final org.apache.bcel.generic.ObjectType RUNTIME_EXCEPTION_TYPEType of java.lang.RuntimeException. -
ANY_METHOD
JavaClassAndMethodChooser which accepts any method. -
CONCRETE_METHOD
JavaClassAndMethodChooser which accepts only concrete (not abstract or native) methods. -
STATIC_METHOD
JavaClassAndMethodChooser which accepts only static methods. -
INSTANCE_METHOD
JavaClassAndMethodChooser which accepts only instance methods.
-
-
Constructor Details
-
Hierarchy
public Hierarchy()
-
-
Method Details
-
isSubtype
public static boolean isSubtype(@DottedClassName String clsName, @DottedClassName String possibleSupertypeClassName) throws ClassNotFoundException Determine whether one class (or reference type) is a subtype of another.- Parameters:
clsName
- the name of the class or reference typepossibleSupertypeClassName
- the name of the possible superclass- Returns:
- true if clsName is a subtype of possibleSupertypeClassName, false if not
- Throws:
ClassNotFoundException
-
isSubtype
public static boolean isSubtype(org.apache.bcel.generic.ReferenceType t, org.apache.bcel.generic.ReferenceType possibleSupertype) throws ClassNotFoundException Determine if one reference type is a subtype of another.- Parameters:
t
- a reference typepossibleSupertype
- the possible supertype- Returns:
- true if t is a subtype of possibleSupertype, false if not
- Throws:
ClassNotFoundException
-
isUniversalExceptionHandler
public static boolean isUniversalExceptionHandler(org.apache.bcel.generic.ObjectType catchType) Determine if the given ObjectType reference represents a universal exception handler. That is, one that will catch any kind of exception.- Parameters:
catchType
- the ObjectType of the exception handler- Returns:
- true if catchType is null, or if catchType is java.lang.Throwable
-
isUncheckedException
public static boolean isUncheckedException(org.apache.bcel.generic.ObjectType type) throws ClassNotFoundException Determine if the given ObjectType refers to an unchecked exception (RuntimeException or Error).- Throws:
ClassNotFoundException
-
isMonitorWait
Determine if method whose name and signature is specified is a monitor wait operation.- Parameters:
methodName
- name of the methodmethodSig
- signature of the method- Returns:
- true if the method is a monitor wait, false if not
-
isMonitorWait
public static boolean isMonitorWait(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg) Determine if given Instruction is a monitor wait.- Parameters:
ins
- the Instructioncpg
- the ConstantPoolGen for the Instruction- Returns:
- true if the instruction is a monitor wait, false if not
-
isMonitorNotify
Determine if method whose name and signature is specified is a monitor notify operation.- Parameters:
methodName
- name of the methodmethodSig
- signature of the method- Returns:
- true if the method is a monitor notify, false if not
-
isMonitorNotify
public static boolean isMonitorNotify(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg) Determine if given Instruction is a monitor wait.- Parameters:
ins
- the Instructioncpg
- the ConstantPoolGen for the Instruction- Returns:
- true if the instruction is a monitor wait, false if not
-
findExactMethod
public static JavaClassAndMethod findExactMethod(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg) throws ClassNotFoundException Look up the method referenced by given InvokeInstruction. This method does not look for implementations in super or subclasses according to the virtual dispatch rules.- Parameters:
inv
- the InvokeInstructioncpg
- the ConstantPoolGen used by the class the InvokeInstruction belongs to- Returns:
- the JavaClassAndMethod, or null if no such method is defined in the class
- Throws:
ClassNotFoundException
-
findExactMethod
public static JavaClassAndMethod findExactMethod(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg, JavaClassAndMethodChooser chooser) throws ClassNotFoundException Look up the method referenced by given InvokeInstruction. This method does not look for implementations in super or subclasses according to the virtual dispatch rules.- Parameters:
inv
- the InvokeInstructioncpg
- the ConstantPoolGen used by the class the InvokeInstruction belongs tochooser
- JavaClassAndMethodChooser to use to pick the method from among the candidates- Returns:
- the JavaClassAndMethod, or null if no such method is defined in the class
- Throws:
ClassNotFoundException
-
visitSuperClassMethods
public static JavaClassAndMethod visitSuperClassMethods(JavaClassAndMethod method, JavaClassAndMethodChooser chooser) throws ClassNotFoundException Visit all superclass methods which the given method overrides.- Parameters:
method
- the methodchooser
- chooser which visits each superclass method- Returns:
- the chosen method, or null if no method is chosen
- Throws:
ClassNotFoundException
-
visitSuperInterfaceMethods
public static JavaClassAndMethod visitSuperInterfaceMethods(JavaClassAndMethod method, JavaClassAndMethodChooser chooser) throws ClassNotFoundException Visit all superinterface methods which the given method implements.- Parameters:
method
- the methodchooser
- chooser which visits each superinterface method- Returns:
- the chosen method, or null if no method is chosen
- Throws:
ClassNotFoundException
-
findInvocationLeastUpperBound
@CheckForNull public static JavaClassAndMethod findInvocationLeastUpperBound(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg) throws ClassNotFoundException Find the least upper bound method in the class hierarchy which could be called by the given InvokeInstruction. One reason this method is useful is that it indicates which declared exceptions are thrown by the called methods.
- For invokespecial, this is simply an exact lookup.
- For invokestatic and invokevirtual, the named class is searched, followed by superclasses up to the root of the object hierarchy (java.lang.Object). Yes, invokestatic really is declared to check superclasses. See VMSpec, 2nd ed, sec. 5.4.3.3.
- For invokeinterface, the named class is searched, followed by all interfaces transitively declared by the class. (Question: is the order important here? Maybe the VM spec requires that the actual interface desired is given, so the extended lookup will not be required. Should check.)
- Parameters:
inv
- the InvokeInstructioncpg
- the ConstantPoolGen used by the class the InvokeInstruction belongs to- Returns:
- the JavaClassAndMethod, or null if no matching method can be found
- Throws:
ClassNotFoundException
-
findInvocationLeastUpperBound
@CheckForNull public static JavaClassAndMethod findInvocationLeastUpperBound(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg, JavaClassAndMethodChooser methodChooser) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
findInvocationLeastUpperBound
@CheckForNull public static JavaClassAndMethod findInvocationLeastUpperBound(org.apache.bcel.classfile.JavaClass jClass, String methodName, String methodSig, JavaClassAndMethodChooser methodChooser, boolean invokeInterface) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
findDeclaredExceptions
@Deprecated public static org.apache.bcel.generic.ObjectType[] findDeclaredExceptions(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg) Deprecated.Find the declared exceptions for the method called by given instruction.- Parameters:
inv
- the InvokeInstructioncpg
- the ConstantPoolGen used by the class the InvokeInstruction belongs to- Returns:
- array of ObjectTypes of thrown exceptions, or null if we can't find the list of declared exceptions
-
findMethod
@CheckForNull public static JavaClassAndMethod findMethod(org.apache.bcel.classfile.JavaClass javaClass, String methodName, String methodSig) Find a method in given class.- Parameters:
javaClass
- the classmethodName
- the name of the methodmethodSig
- the signature of the method- Returns:
- the JavaClassAndMethod, or null if no such method exists in the class
-
findMethod
@CheckForNull public static JavaClassAndMethod findMethod(org.apache.bcel.classfile.JavaClass javaClass, String methodName, String methodSig, JavaClassAndMethodChooser chooser) -
findMethod
@CheckForNull public static XMethod findMethod(ClassDescriptor classDesc, String methodName, String methodSig, boolean isStatic) Find a method in given class.- Parameters:
classDesc
- the class descriptormethodName
- the name of the methodmethodSig
- the signature of the methodisStatic
- are we looking for a static method?- Returns:
- the JavaClassAndMethod, or null if no such method exists in the class
-
findConcreteMethod
@Deprecated @CheckForNull public static JavaClassAndMethod findConcreteMethod(org.apache.bcel.classfile.JavaClass javaClass, String methodName, String methodSig) Deprecated.Find a method in given class.- Parameters:
javaClass
- the classmethodName
- the name of the methodmethodSig
- the signature of the method- Returns:
- the JavaClassAndMethod, or null if no such method exists in the class
-
findXMethod
@Deprecated @CheckForNull public static XMethod findXMethod(org.apache.bcel.classfile.JavaClass javaClass, String methodName, String methodSig, JavaClassAndMethodChooser chooser) Deprecated.Find a method in given class.- Parameters:
javaClass
- the classmethodName
- the name of the methodmethodSig
- the signature of the methodchooser
- the JavaClassAndMethodChooser to use to screen possible candidates- Returns:
- the XMethod, or null if no such method exists in the class
-
accessFlagsAreConcrete
public static boolean accessFlagsAreConcrete(int accessFlags) -
findMethod
@Deprecated public static JavaClassAndMethod findMethod(org.apache.bcel.classfile.JavaClass[] classList, String methodName, String methodSig) Deprecated.Find a method in given list of classes, searching the classes in order.- Parameters:
classList
- list of classes in which to searchmethodName
- the name of the methodmethodSig
- the signature of the method- Returns:
- the JavaClassAndMethod, or null if no such method exists in the class
-
findMethod
public static JavaClassAndMethod findMethod(org.apache.bcel.classfile.JavaClass[] classList, String methodName, String methodSig, JavaClassAndMethodChooser chooser) Find a method in given list of classes, searching the classes in order.- Parameters:
classList
- list of classes in which to searchmethodName
- the name of the methodmethodSig
- the signature of the methodchooser
- JavaClassAndMethodChooser to select which methods are considered; it must return true for a method to be returned- Returns:
- the JavaClassAndMethod, or null if no such method exists in the class
-
findXMethod
@Deprecated public static XMethod findXMethod(org.apache.bcel.classfile.JavaClass[] classList, String methodName, String methodSig) Deprecated.Find XMethod for method in given list of classes, searching the classes in order.- Parameters:
classList
- list of classes in which to searchmethodName
- the name of the methodmethodSig
- the signature of the method- Returns:
- the XMethod, or null if no such method exists in the class
-
findXMethod
@Deprecated public static XMethod findXMethod(org.apache.bcel.classfile.JavaClass[] classList, String methodName, String methodSig, JavaClassAndMethodChooser chooser) Deprecated.Find XMethod for method in given list of classes, searching the classes in order.- Parameters:
classList
- list of classes in which to searchmethodName
- the name of the methodmethodSig
- the signature of the methodchooser
- JavaClassAndMethodChooser to select which methods are considered; it must return true for a method to be returned- Returns:
- the XMethod, or null if no such method exists in the class
-
resolveMethodCallTargets
public static Set<JavaClassAndMethod> resolveMethodCallTargets(org.apache.bcel.generic.InvokeInstruction invokeInstruction, TypeFrame typeFrame, org.apache.bcel.generic.ConstantPoolGen cpg) throws DataflowAnalysisException, ClassNotFoundException Resolve possible method call targets. This works for both static and instance method calls.- Parameters:
invokeInstruction
- the InvokeInstructiontypeFrame
- the TypeFrame containing the types of stack valuescpg
- the ConstantPoolGen- Returns:
- Set of methods which might be called
- Throws:
DataflowAnalysisException
ClassNotFoundException
-
resolveMethodCallTargets
public static Set<JavaClassAndMethod> resolveMethodCallTargets(org.apache.bcel.generic.ReferenceType receiverType, org.apache.bcel.generic.InvokeInstruction invokeInstruction, org.apache.bcel.generic.ConstantPoolGen cpg) throws ClassNotFoundException Resolve possible instance method call targets. Assumes that invokevirtual and invokeinterface methods may call any subtype of the receiver class.- Parameters:
receiverType
- type of the receiver objectinvokeInstruction
- the InvokeInstructioncpg
- the ConstantPoolGen- Returns:
- Set of methods which might be called
- Throws:
ClassNotFoundException
-
resolveMethodCallTargets
public static Set<JavaClassAndMethod> resolveMethodCallTargets(org.apache.bcel.generic.ReferenceType receiverType, org.apache.bcel.generic.InvokeInstruction invokeInstruction, org.apache.bcel.generic.ConstantPoolGen cpg, boolean receiverTypeIsExact) throws ClassNotFoundException Resolve possible instance method call targets.- Parameters:
receiverType
- type of the receiver objectinvokeInstruction
- the InvokeInstructioncpg
- the ConstantPoolGenreceiverTypeIsExact
- if true, the receiver type is known exactly, which should allow a precise result- Returns:
- Set of methods which might be called
- Throws:
ClassNotFoundException
-
isConcrete
Deprecated.Return whether or not the given method is concrete.- Parameters:
xmethod
- the method- Returns:
- true if the method is concrete, false otherwise
-
findField
public static org.apache.bcel.classfile.Field findField(String className, String fieldName) throws ClassNotFoundException Find a field with given name defined in given class.- Parameters:
className
- the name of the classfieldName
- the name of the field- Returns:
- the Field, or null if no such field could be found
- Throws:
ClassNotFoundException
-
findXField
public static XField findXField(String className, String fieldName, String fieldSig, boolean isStatic) Look up a field with given name and signature in given class, returning it as anXField
object. If a field can't be found in the immediate class, its superclass is search, and so forth.- Parameters:
className
- name of the class through which the field is referencedfieldName
- name of the fieldfieldSig
- signature of the fieldisStatic
- true if field is static, false otherwise- Returns:
- an XField object representing the field, or null if no such field could be found
-
findXField
@CheckForNull public static XField findXField(org.apache.bcel.generic.FieldInstruction fins, @Nonnull org.apache.bcel.generic.ConstantPoolGen cpg) Look up the field referenced by given FieldInstruction, returning it as anXField
object.- Parameters:
fins
- the FieldInstructioncpg
- the ConstantPoolGen used by the class containing the instruction- Returns:
- an XField object representing the field, or null if no such field could be found
-
isInnerClassAccess
public static boolean isInnerClassAccess(org.apache.bcel.generic.INVOKESTATIC inv, org.apache.bcel.generic.ConstantPoolGen cpg) Determine whether the given INVOKESTATIC instruction is an inner-class field accessor method.- Parameters:
inv
- the INVOKESTATIC instructioncpg
- the ConstantPoolGen for the method- Returns:
- true if the instruction is an inner-class field accessor, false if not
-
getInnerClassAccess
public static InnerClassAccess getInnerClassAccess(org.apache.bcel.generic.INVOKESTATIC inv, org.apache.bcel.generic.ConstantPoolGen cpg) throws ClassNotFoundException Get the InnerClassAccess for access method called by given INVOKESTATIC.- Parameters:
inv
- the INVOKESTATIC instructioncpg
- the ConstantPoolGen for the method- Returns:
- the InnerClassAccess, or null if the instruction is not an inner-class access
- Throws:
ClassNotFoundException
-
Hierarchy2.findDeclaredExceptions(InvokeInstruction,ConstantPoolGen)
instead