Bug 120245

Summary: [clone]Advice that calls clone on object always fails
Product: [Tools] AspectJ Reporter: Dean Wampler <dean>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 1.5.0M5   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Aspect that invokes clone() in advice
none
Class that is advised, which has a clone() method
none
JUnit test that drives everything. none

Description Dean Wampler CLA 2005-12-10 18:27:23 EST
I have some advice that calls clone() on an advised object, inside around advise. The attached example always throws CloneNotSupportedException. Curiously though, the real program where I first saw this problem actually threw a NoSuchMethodError with this message "java.lang.Object.ajc$privMethod$org_contract4j_aspects_Contract4J$java_lang_Object$clone()Ljava/lang/Object;)".
org.contract4j.aspects.Contract4J is the aspect in my Contract4J project that invokes clone on a test class that looks almost identical to the attached CloneTestClass.java.
While I'm at it ;), here is one other wierd thing I've seen while debugging. I can't set a breakpoint inside the advice in CloneAdvisedClass.aj; execution just doesn't stop there.
Comment 1 Dean Wampler CLA 2005-12-10 18:29:47 EST
Created attachment 31524 [details]
Aspect that invokes clone() in advice
Comment 2 Dean Wampler CLA 2005-12-10 18:30:32 EST
Created attachment 31525 [details]
Class that is advised, which has a clone() method
Comment 3 Dean Wampler CLA 2005-12-10 18:31:01 EST
Created attachment 31526 [details]
JUnit test that drives everything.
Comment 4 Andrew Clement CLA 2005-12-12 04:45:41 EST
From the javadoc for Object.clone():

The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable, then a CloneNotSupportedException is thrown. Note that all arrays are considered to implement the interface Cloneable. Otherwise, this method creates a new instance of the class of this object and initializes all its fields with exactly the contents of the corresponding fields of this object, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of this object, not a "deep copy" operation.

---
So I changed your program such that CloneTestClass is marked 'implements Cloneable' and it seems to work now...

On the mangled method thing - looks like something related to accessing a non public clone() method, possibly from advice... doing that just *sounds* like its going to cause trouble.
Comment 5 Wes Isberg CLA 2006-05-10 11:04:54 EDT
No response, so I presume Andy's reply was accepted.
stalebug