Reputation: 3269
I'm not terribly good with Java reflection, and I'm trying to debug an ugly piece of code that uses a good amount of reflection. I placed a breakpoint on some methods that should be called, but the code never pauses when I execute the program. So, this has led me to believe that running a method using reflection ignores breakpoints when running in Eclipse (Indigo on Windows 7).
Can anyone confirm this? I've provided an example below, although since I don't know how to execute a method particular to a class using reflection, it doesn't work, but I hope it clarifies what I'm asking in my question:
public static void main(String[] args)
{
try
{
Class test = Class.forName("Test");
test.runMethodDoSomething();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
public static class Test
{
public void doSomething()
{
// Place breakpoint here.
}
}
Upvotes: 0
Views: 4685
Reputation: 115368
First, reflection does not conflict with debugger. Typically you can put breakpoint in method, then invoke it using reflection and debugger will stop there.
Second, there is not reflection in your code snippet. Class.forName()
is dynamic class loading. Reflection is when you are using obj.getClass().getMethod("myMethod").invoke()
.
So, if your code snippet does not work try to understand problem in either your environment or probably in your code. Is there a chance that some kind of exception is thrown before you are calling the method but the exception is caught without notifications?
Upvotes: 4