Bug 230075 - org.aspectj.weaver.BCException: bad bytecode in org.aspectj.weaver.bcel.BcelShadow.createMethodGen:3479
Summary: org.aspectj.weaver.BCException: bad bytecode in org.aspectj.weaver.bcel.BcelS...
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.0   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 1.6.1   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-03 12:45 EDT by Jacek Pospychala CLA
Modified: 2008-06-12 01:46 EDT (History)
1 user (show)

See Also:


Attachments
error log (5.45 KB, text/plain)
2008-05-03 12:45 EDT, Jacek Pospychala CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jacek Pospychala CLA 2008-05-03 12:45:22 EDT
Created attachment 98533 [details]
error log

I have a question to the following condition in org.aspectj.weaver.bcel.BcelShadow.createMethodGen(String, int):

if (resolvedMember != null && Modifier.isProtected(resolvedMember.getModifiers()) && 
!samePackage(targetType.getPackageName(), getEnclosingType().getPackageName()) &&
!resolvedMember.getName().equals("clone")) {


I understand that it's trying to check, if a protected method (resolvedMember) from type (targetType) can be shadowed by another method (aspect) in another type (enclosedType).

Suppose that
resolvedMember is "a.B.test()"
targetType is "a.a.A"
enclosingType is "a.C"

their source is:

--------------- a.a.A ---------------
public class A extends a.B {	
}

--------------- a.B ---------------
public abstract class B {
	protected boolean test() { return true; }
}

--------------- a.C ---------------
public class C {
    protected A a = new A();
    public void run() {
        a.test();
    }
}


then trying to weave something around a.test() call in a.C.run() following check is performed in above condition:

!samePackage(targetType.getPackageName(), getEnclosingType().getPackageName())

which resolves to:

!samePackage("a.a.A".getPackageName(), "a.C".getPackageName())

then 
!samePackage("a.a", "a") = true


It further causes "org.aspectj.weaver.BCException: bad bytecode", which I believe shouldn't happen, if condition was changed from 

!samePackage(targetType.getPackageName(), getEnclosingType().getPackageName())

to:

!samePackage(resolvedMember.getType.getPackageName(), getEnclosingType().getPackageName())




Sorry for such an abstract description but I have quite a difficult setup, hard to extract a self-contained testcase.
I'm attaching log of error that I'm getting right now.
Note, I'm not getting any error if targetType and enclosingType live in the same package.
Please let me know if you have any further questions.
Comment 1 Jacek Pospychala CLA 2008-05-03 12:46:31 EDT
Note, class names in log are different than in example.
Comment 2 Andrew Clement CLA 2008-06-10 18:54:43 EDT
the tests relating to this little bit of code are Ajc10xTests.test100() and test101(). The code relates to ensuring the target is right when join points are within inner classes.  I have changed it as per the suggestion here and it has no adverse affects on those test cases.  I've added the example code here as a testcase (added an aspect to apply the around advice and show the failure really occurring).

tests and change committed, will be in next dev build.
Comment 3 Jacek Pospychala CLA 2008-06-12 01:46:12 EDT
thanks!