Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] ITD constructor access methods defined in super class

There seems to be a bug in the AspectJ compiler.

With your code as is, I see the same error, but there is also a warning ("- inter-type constructor does not contain explicit constructor call: field initializers in the target type will not be executed [Xlint:noExplicitConstructorCall]". Then I modified the ITD declaration as follows:

    public Child.new(String name, int age) {
        this(name);
        super.getJob();//This seems to cause issues at runtime
    }

The causes another error:
Exception in thread "main" java.lang.ClassCastException: java.lang.String can not be converted to int
at org.aspectj.runtime.internal.Conversions.intValue(Conversions.java:57)
at example.Child.<init>(Parent.java:1)
at example.Main.main(Main.java:5)

BTW, my Main class is as follows:

public class Main {
public static void main(String[] args) {
new Child("myname", 5);
}
}


Can you file a bug so that it may be addressed? I am using the 1.7.3.20130613 version.

-Ramnivas


On Wed, Jul 17, 2013 at 7:17 AM, pai <pikapai@xxxxxxxxx> wrote:
It seems *super.someMethod()* can not be correctly resolved in the
constructor added by ITD

It can be compiled with no problem, but* at runtime, exception is raised.*


The class which I'll add a new constructor to:

*    public class Child extends Parent{

        public String name = "John";

        public Child(String name) {
            this.name = name;
        }
    } *

As we can see, *Child * extends *Parent*

class Parent has a method *getJob()*

*public class Parent {
        private int mJob = 0;

        public int getJob() {
            return mJob;
        }

    }*

If I add a new constructor for the *Child * in my aspect.

*    public aspect MyTest {
        public Child.new(String name, int age) {
            super.getJob();//This seems to cause issues at runtime
        }
    }*

The above aspect code will trigger an exception.

*    Exception in thread "main" java.lang.NoSuchMethodError:
com.test2.Child.ajc$superDispatch$com_test2_Child$init()V
        at MyTest.ajc$postInterConstructor$MyTest$com_test2_Child(MyTest.aj:19)
        at com.test2.Child.<init>(Child.java:1)
        at MainProgram.main(MainProgram.java:11)*

*Is this a limitation of AspectJ? Is this the only way to resolve this
issue?*

*My workaround:*
Define* another wrapper method* for class *Child*, and indirectly call the
*super.getJob() * via that wrapper method


For example, use ITD to add a new method for class *Child*

    public int Child.getJobWrapper()
    {
        super.getJob();
    }

Now, I can call *getJobWrapper*() from the newly added constructor like
below:

    public aspect MyTest {
        public Child.new(String desc, int num) {
            *this.getJobWrapper();* //This will help me call the getJob() in
super class
        }
    }



Thank you all for your time :)



--
View this message in context: http://aspectj.2085585.n4.nabble.com/ITD-constructor-access-methods-defined-in-super-class-tp4651029.html
Sent from the AspectJ - users mailing list archive at Nabble.com.
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top