Community
Participate
Working Groups
Question & scenario described at http://aspectj.2085585.n4.nabble.com/AbstractMethodError-calling-method-defined-on-class-receiving-ITD-of-same-method-tp4650821.html, but gist is this: ===== @Go public class Foo { public void go() { System.out.println("go"); } } ===== public aspect Go { public interface I {} declare parents: (@Go *) implements I; public void I.go() { System.out.println("aspect-go"); } } ===== public void TestFoo { @Test public void testGo() { new Foo().go(); } // throws AbstractMethodError } ===== AspectJ compiler issues no warnings or errors. When invoking the method at runtime, an AbstractMethodError is raised. Andy Clement, this is reproducible in our private foundation repository; branch & commit to follow.
Foundation repo branch is ajc-404601, commit is 2ba1d874c80f518dc25e81fba0bfc4137d132d36. To reproduce, in the foundation directory off of the root of the repo, issue the command mvn clean install -P datanucleus,derby After that, you can cd into the domain module after that and issue mvn clean test -Dtest=YouserTest to reproduce. Error is in ./foundation/domain/target/surefire-reports/com.scispike.foundation.domain.test.unit.aspectj.user.YouserTest.txt: ------------------------------------------------------------------------------- Test set: com.scispike.foundation.domain.test.unit.aspectj.user.YouserTest ------------------------------------------------------------------------------- Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.442 sec <<< FAILURE! testBasics(com.scispike.foundation.domain.test.unit.aspectj.user.YouserTest) Time elapsed: 0.181 sec <<< FAILURE! java.lang.AbstractMethodError: com.scispike.foundation.domain.test.unit.aspectj.user.Youser.ajc$interMethodDispatch2$com_scispike_foundation_domain_trait_user_UserTrait$testSetUsername(Ljava/lang/String;)V at com.scispike.foundation.domain.trait.user.UserTrait.ajc$interMethodDispatch1$com_scispike_foundation_domain_trait_user_UserTrait$com_scispike_foundation_domain_trait_user_UserTrait$I$testSetUsername(UserTrait.aj) at com.scispike.foundation.domain.trait.user.UserTrait.ajc$interMethod$com_scispike_foundation_domain_trait_user_UserTrait$com_scispike_foundation_domain_trait_user_UserTrait$I$setUsername(UserTrait.aj:40) at com.scispike.foundation.domain.test.unit.aspectj.user.Youser.setUsername(Youser.java:1) at com.scispike.foundation.domain.trait.user.UserTrait.ajc$interMethodDispatch1$com_scispike_foundation_domain_trait_user_UserTrait$com_scispike_foundation_domain_trait_user_UserTrait$I$setUsername(UserTrait.aj) at com.scispike.foundation.domain.test.unit.aspectj.user.Youser.<init>(Youser.java:11) at com.scispike.foundation.domain.test.unit.aspectj.user.YouserTest.testBasics(YouserTest.java:35) testShape(com.scispike.foundation.domain.test.unit.aspectj.user.YouserTest) Time elapsed: 0 sec <<< FAILURE! java.lang.AbstractMethodError: com.scispike.foundation.domain.test.unit.aspectj.user.Youser.ajc$interMethodDispatch2$com_scispike_foundation_domain_trait_user_UserTrait$testSetUsername(Ljava/lang/String;)V at com.scispike.foundation.domain.trait.user.UserTrait.ajc$interMethodDispatch1$com_scispike_foundation_domain_trait_user_UserTrait$com_scispike_foundation_domain_trait_user_UserTrait$I$testSetUsername(UserTrait.aj) at com.scispike.foundation.domain.trait.user.UserTrait.ajc$interMethod$com_scispike_foundation_domain_trait_user_UserTrait$com_scispike_foundation_domain_trait_user_UserTrait$I$setUsername(UserTrait.aj:40) at com.scispike.foundation.domain.test.unit.aspectj.user.Youser.setUsername(Youser.java:1) at com.scispike.foundation.domain.trait.user.UserTrait.ajc$interMethodDispatch1$com_scispike_foundation_domain_trait_user_UserTrait$com_scispike_foundation_domain_trait_user_UserTrait$I$setUsername(UserTrait.aj) at com.scispike.foundation.domain.test.unit.aspectj.user.Youser.<init>(Youser.java:11) at com.scispike.foundation.domain.test.unit.aspectj.user.YouserTest.testShape(YouserTest.java:26)
Matthew created a smaller sample, then I made it even smaller. Attached here.
Created attachment 229210 [details] minimal test files
the ITD being private is what makes a mess here: private void I.testSetUsername(String username) { } if that is public, then it works.
Matthew, what do you expect to happen if you make a private ITD and the target type already has a public method? starting to feel like an error situation to me. Just like you couldn't create a type with both public and private methods of the same name/signature in it?
Created attachment 229213 [details] Reproducible test case Adding this attachment for the record to reproduce the AbstractMethodError. As long as you have ajc in your path & aspectjrt.jar on your $CLASSPATH, the repro.sh script should work to reproduce the AbstractMethodError w/JDK 1.6 & AspectJ 1.7.2.
Oops. Didn't see your comments, Andy. (In reply to comment #6) > Created attachment 229213 [details] > Reproducible test case > > Adding this attachment for the record to reproduce the AbstractMethodError. > As long as you have ajc in your path & aspectjrt.jar on your $CLASSPATH, the > repro.sh script should work to reproduce the AbstractMethodError w/JDK 1.6 & > AspectJ 1.7.2.
(In reply to comment #5) > Matthew, what do you expect to happen if you make a private ITD and the > target type already has a public method? > I expected either a compile-time error or for the ajc compiler to continue to ignore the method. > starting to feel like an error situation to me. Just like you couldn't > create a type with both public and private methods of the same > name/signature in it? > I agree that this is an probably an error situation and would prefer that the compiler to emit an error in this case.