[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Re: getting 'around' constructor execution

Not calling the super constructor is impossible, if A extends some class it 
has to call one super constructor or the other.
Now, assuming that you want to call the parameterless super constructor 
instead of the constructor with the Type parameter, you can use aspectj to do 
You are currently trying to use a constructor execution join point. This join 
point, according to The AspectJTM Programming Guide, matches 'When the body 
of code for an actual constructor executes, after its this or super 
constructor call'. Thus, you cannot use this construction.
You can, however, match constructor call join points, and call another 
constructor instead. You can define a new constructor in your aspect. Let me 
illustrate this with an example:

public abstract class ASuper {
	public ASuper() {
		System.out.println("Goodness has occurred");
	public ASuper(Type t) {
		System.out.println("Badness has occurred");

public class A extends ASuper {
	private Type var1;
	public A(Type arg) {
		var1 = arg;
	public static void main(String[] args) {
		new A(null);

public privileged aspect AAsp {
	pointcut constructorCall(Type arg):
		&& args(arg);
	private A.new(Type arg, AAsp a) {
		var1 = arg;
	A around(Type arg): constructorCall(arg) {
		System.out.println("advice A constructor");
		return new A(arg, this);

PS pre-initialization and initialization join points won't do you any good 
either, they respectively match the code before and after the super call.

 - Gijs

On Tuesday 18 September 2007 11:12:54 danny wrote:
> oops forgot the pointcut declaration :
> pointcut constructor(A instance, Type arg):
> 		execution (A.new (Type))
> 		&& this(instance)
> 		&& args(arg);
> the class to be woven is something like
> public class A {
>    private Type var1;
>    public A(Type arg) {
>       super(arg);
>       var1=arg;
>    }
> }
> the actual goal is to replace the constructor so that 'super(arg)' is
> not called.
> as before, all help much appreciated.
> danny wrote:
> > the advice -I just want to see if I enter the advice for now- :
> > A around(A instance, Type arg): constructor(instance, arg) {
> >   System.out.println("advice A constructor");
> >
> >   return instance ();
> > }
> >
> > I get the following error when weaving :
> > [WeavingURLClassLoader] error at.......incompatible return type applying
> > to constructor-execution(void A.<init>(Type))
> >
> > I've tried some other constructs, this is the only one I actually
> > trigger something, all other don't even try to weave :(
> >
> > What do do ?
> > All help appreciated
> >
> > Danny
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users


FIFTH is a precision mathematical language in which the data types
refer to quantity.  The data types range from CC, OUNCE, SHOT, and
JIGGER to FIFTH (hence the name of the language), LITER, MAGNUM and
BLOTTO.  Commands refer to ingredients such as CHABLIS, CHARDONNAY,

The many versions of the FIFTH language reflect the sophistication and
financial status of its users.  Commands in the ELITE dialect include
VSOP and LAFITE, while commands in the GUTTER dialect include HOOTCH
and RIPPLE. The latter is a favorite of frustrated FORTH programmers
who end up using this language.

Attachment: signature.asc
Description: This is a digitally signed message part.