Re: inner class problem

Arvid Svensson <[email protected]>
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
There's a key difference between the inner classes in your examples. In your second (working) example the inner class is static as opposed to non-static in your first less working example. Instances of non-static inner classes gets a synthetic reference to the enclosing object when instantiated. Could your instrumentation miss something there?

/Arvid

On 9 dec 2010, at 17:33, Nikolas Nehmer <[email protected]> wrote:

> Hi all,
> 
> I have a problem regarding the following example:
> 
> public class Demo2 {
> 
>    InnerClass i;
>    int x;
> 
>    Demo2() {
>        i = new InnerClass();
>    }
> 
>    public static void main(String[] args) {
>        Demo2 demo = new Demo2();
>    }
> 
>    class InnerClass {
> 
>        InnerClass() {
>        }
>    }
> }
> 
> 
> My instrumentation adds some logging calls, i.e. in case of variable assignments like i = new InnerClass(); it calls a static logging facility. So far so good, but ins this special case, the inner class is just not instrumented. I'm using load-time instrumentation based on a Java agent. If I just add some debug System.out.printlns to the agent (instead of the instrumentation calls), either Demo2 and Demo2$InnerClass are passed to the agent. If I add the instrumentation, only the outer class is instrumented, the inner class is not even passed to the agent! Nevertheless the app is running - i.e. Demo2 is instantiated, the inner class is instantiated and for the outer class my logging calls are executed. The application terminates normally.
> To sumarize:
> - The instrumented app runs without exception!
> - For the outer class the instrumentation works! i.e. for i = new InnerClass(); a logging call is added
> - For the inner class there is NO call to the agent's transform(...) method!
> 
> Any ideas why the transform method might not be called for the inner class?
> 
> Btw. the following example works completely!!! The only difference is splitting up the example in two classes!
> 
> public class Demo {
>   public static void main(String[] args) {
>       MyComponent comp = new MyComponent();
>   }
> }
> 
> public class MyComponent {
>   InnerClass i;
> 
>   public MyComponent() {
>        i = new InnerClass();
>   }
> 
>   static class InnerClass {}
> }
> 
> 
> Best regards
> Nikolas
> 
> -- 
> Dipl.-Inf. Nikolas Nehmer,
> Dept. of Computer Science. University of Kaiserslautern
> P.O. Box 3049, 67653 Kaiserslautern, Germany.
> room 36/308, phone: +49 (0) 631 - 205 2644, fax: +49 (0) 631 - 205 3299
> mail: [email protected]
> 
> 
> -- 
> You receive this message as a subscriber of the [email protected] mailing list.
> To unsubscribe: mailto:[email protected]
> For general help: mailto:[email protected]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
message-footer.txt (text/plain, 238 B)
-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.