1

Is there a way to change/define the value a methods is returning using the eclipse debugger if it has not been assigned to an intermediate variable before?

E.g. I have some third party closed source code that calls java.lang.Class.classForName, which looks like this

  public static Class<?> forName(String className)
              throws ClassNotFoundException {
      return forName0(className, true, ClassLoader.getCallerClassLoader());
  }

The classloader that is obtained by ClassLoader.getCallerClassLoader() fails to load the class so I want to try whether Thread.currentThread().contextClassLoader is more lucky. So virtually, I want something like:

   public static Class<?> forName(String className)
               throws ClassNotFoundException {
       return forName0(className, true, Thread.currentThread().contextClassLoader);
   }

Is this possible somehow? Note that forName0 is a native method.

Jose Luis
  • 3,307
  • 3
  • 36
  • 53
user462982
  • 1,635
  • 1
  • 16
  • 26

2 Answers2

0

You can use AspectJ's run-time weaving to apply your own custom aspect around ClassLoader.getCallerClassLoader() to replace return value.

You can also try Bugdel.

Eugene Kuleshov
  • 31,461
  • 5
  • 66
  • 67
  • Hi, I solved my problem by other means, so I didn't investigate your proposals much further. It looks though, they seem to do what I wanted so I'll marks yours as the accepted answer. – user462982 Oct 20 '12 at 09:52
-1

What purpose does Class.forName() serve if you don't use the return value?

step into the static methods and see if you can tweak it there. it's probably loading static stuff

Modify/view static variables while debugging in Eclipse

Community
  • 1
  • 1
  • The return value is indeed used by the third party app (the purpose here is to get the class by its string name, not to do initialization), it complains that is is null (because the original classloader fails to load it) – user462982 Oct 11 '12 at 16:05