How to check if ClassType inherits from java.util.Collection in JDI?

61 Views Asked by At

I can get all the interfaces of a ClassType with allInterfaces() but this results in many JDWP calls to the debuggee which is slow. Another approach would be to check this:

Collection.class.isAssignableFrom(classType)

but the method isAssignableFrom() is in java.lang.Class and so I have to call this method with invokeMethod like this:

javaLangClassReference.invokeMethod(threadRef, isAssignableFromMethod,
                        Arrays.asList(myClassType),
                        ObjectReference.INVOKE_SINGLE_THREADED);

But there are two issues here:

  1. classType cannot be used as parameter for the method call, it is not a Value
  2. How do I provide the java.util.Collection as a param to the Method (Arrays.asList(myClassType, ...))?

Also, is there a simpler way to check if a given ClassType is a java.util.Collection?

0

There are 0 best solutions below