Bug 120245 - [clone]Advice that calls clone on object always fails
Summary: [clone]Advice that calls clone on object always fails
Status: RESOLVED INVALID
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0M5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-10 18:27 EST by Dean Wampler CLA
Modified: 2006-05-10 11:04 EDT (History)
0 users

See Also:


Attachments
Aspect that invokes clone() in advice (572 bytes, text/plain)
2005-12-10 18:29 EST, Dean Wampler CLA
no flags Details
Class that is advised, which has a clone() method (545 bytes, text/plain)
2005-12-10 18:30 EST, Dean Wampler CLA
no flags Details
JUnit test that drives everything. (441 bytes, text/plain)
2005-12-10 18:31 EST, Dean Wampler CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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