Bug 404601 - AbstractMethodError when target class already has method trying to be introduced
Summary: AbstractMethodError when target class already has method trying to be introduced
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Runtime (show other bugs)
Version: 1.7.2   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-29 00:57 EDT by Matthew Adams CLA
Modified: 2013-04-01 16:00 EDT (History)
1 user (show)

See Also:


Attachments
minimal test files (850 bytes, application/zip)
2013-04-01 13:52 EDT, Andrew Clement CLA
no flags Details
Reproducible test case (1.78 KB, application/zip)
2013-04-01 15:54 EDT, Matthew Adams CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Adams CLA 2013-03-29 00:57:11 EDT
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.
Comment 1 Matthew Adams CLA 2013-03-29 01:10:34 EDT
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)
Comment 2 Andrew Clement CLA 2013-04-01 13:51:37 EDT
Matthew created a smaller sample, then I made it even smaller. Attached here.
Comment 3 Andrew Clement CLA 2013-04-01 13:52:26 EDT
Created attachment 229210 [details]
minimal test files
Comment 4 Andrew Clement CLA 2013-04-01 13:53:17 EDT
the ITD being private is what makes a mess here:

    private void I.testSetUsername(String username) { }

if that is public, then it works.
Comment 5 Andrew Clement CLA 2013-04-01 14:29:26 EDT
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?
Comment 6 Matthew Adams CLA 2013-04-01 15:54:25 EDT
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.
Comment 7 Matthew Adams CLA 2013-04-01 15:56:41 EDT
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.
Comment 8 Matthew Adams CLA 2013-04-01 16:00:39 EDT
(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.