[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] constructor problem in inner class
|
Hello,
maybe, I mixed something, but I had a problem with my NullPointerTrap,
which forbids null args. But back to your example (regarding only a
inner static class):
public class InnerClassExample {
public static void main(String[] args) {
new Inner0();
}
private static class Inner0 {
}
}
This is the aspect:
public aspect InnerClassAspect {
before() : execution(*..new(*, ..)) {
System.err.println(thisJoinPoint);
}
}
When I start the main programm with the call of the Inner0 constructor I
got the following output:
execution(patterntesting.sample.InnerClassExample.Inner0(InnerClassExample.Inner0))
I'm a little confused here - the constructor of Inner0 was called with
an additonal parameter? And this parameter is null (which was the origin
of my trouble with my NullPointerTrap aspect).
Is this a problem of the Java compiler and how it handles inner classes
or is it a problem of the AspectJ compiler? Who knows it?
regards
Oliver
Thomas Richard Darimont schrieb:
Hello,
hmmm ... strange if I try to reproduce you problem it looks like the
opposite to me.
The given pointcut matches the inner class "Inner" but not the static
inner class "Inner0".
This is the behavior I would expect.
May be you or I ;-) mixed up something.
have a look at this:
Aspect:
[code]
package de.tutorials.training.aspects;
public aspect ExampleAspect1 {
before() : execution(*..new(*, ..)){}
}
[/code]
Example:
[code]
package de.tutorials.training;
public class InnerClassExample {
public static void main(String[] args) {}
class Inner{ //Advised case1
}
static class Inner0{ //Not Advised case2
}
}
[/code]
Decompiled:
[code]
package de.tutorials.training;
import de.tutorials.training.aspects.ExampleAspect1;
public class InnerClassExample{
public static void main(String[] args){}
class Inner{
private Inner(){
ExampleAspect1.aspectOf().ajc$before$de_tutorials_training_aspects_ExampleAspect1$1$8d2f7ddc();
}
}
static class Inner0{}
}
[/code]
I *think* the given pointcut matches case1 because an instance of the
inner class Inner can only be created in the
context of an instance of the outer class (InnerClassExample) -> new
InnerClassExample().new Inner();
A static inner class is NOT bound to the context of the outer class and
thus doesn't require an Instance of the outer class
and thus doesn't need to be advised.
So in case of an (non static) inner class there must be an instance of
the outer class. I think this implicitly triggers
the match here (some how..)
Please correct me if I'm wrong :)
Best regards,
Thomas
Oliver Böhm schrieb:
Hello,
I want to know if there are known problems with inner classes. I have
an (empty) inner class:
private static class InnerClass {
}
It seems that my pointcut
execution(*..new(*, ..))
matches also the constructor of this inner class. Is this possible?
If I put an (empty) constructor inside it works as expected (the
pointcut does not match)
private static class InnerClass {
public InnerClass() {}
}
And how can I exclude the inner classes from the pointcut?
regards,
Oliver
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
--
Oliver Böhm
http://www.javatux.de