Community
Participate
Working Groups
Build: I20030611 Given the following class that contains an anonymous inner-class: public class Foo { public void bar() { Runnable runnable = new Runnable() { public void run() { Foo.this.process(); } }; Thread thread = new Thread(runnable); thread.start(); } private void process() { System.out.println("Processing..."); } } Creating a Call Tree for the process() methods yields the following "Caller Hierarchy": ^process() - tree.Foo ^bar() - tree.Foo This is INCORRECT since it claims that the bar() method is called from the process() method, when in fact the bar() method is called from the Thread's run () method, which is obviously executed on a separate thread. Certainly the method bar() is referenced in the code inside the process() method, but I don't think that this should shown by a call tree.
Refactoring the code to use a nested inner-class, rather than an anonymous inner-class causes things to work much better: public class Foo { private final class MyRunnable implements Runnable { public void run() { Foo.this.process(); } } public void bar() { Runnable runnable = new MyRunnable() { Thread thread = new Thread(runnable); thread.start(); } private void process() { System.out.println("Processing..."); } } Creating a Call Tree for the process() methods yields the following "Caller Hierarchy": ^process() - tree.Foo ^run() - tree.Foo.MyRunnable
JDT/Core currently has no representation of elements inside methods (e.g. anonymous types, local variables). We are planning to impove this for the 3.0 release.
*** This bug has been marked as a duplicate of 8613 ***
Reopening as even after adding contructs for local types, the problem is still there.
Verified this now works with I20031029.