Anyone have any thoughts on this?
----- Original Message -----
From: "Terracotta JIRA (on behalf of Alex Miller)" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Sent: Thursday, August 23, 2007 4:28:53 PM (GMT-0600) America/Chicago
Subject: [JIRA] Commented: (DEV-865) CloneNotSupportedException got swallowed
and replaced by IllegalMonitorStateException
[
https://jira.terracotta.org/jira//browse/DEV-865?page=comments#action_22689 ]
Alex Miller commented on DEV-865:
---------------------------------
The modification currently made by
TransparencyCodeAdapter.handleJavaLangObjectCloneCall() is to replace calls to
refToBeCloned.clone() with:
{code:java}
Object refToBeCloned;
Object rv;
TCObject tco = (refToBeCloned instanceof Manageable) ? ((Manageable)
refToBeCloned).__tc_managed() : null;
if (tco != null) {
synchronized (tco.getResolveLock()) {
tco.resolveAllReferences();
rv = Util.fixTCObjectReferenceOfClonedObject(refToBeCloned,
refToBeCloned.clone());
}
} else {
rv = refToBeCloned.clone();
}
{code}
This modification of the caller of clone() is done using ASM and is not really
exactly this, but something like this with some modifications. The subtle bug
is introduced because clone() can throw CloneNotSupportedException, which is
not handled here and the ASM modification will not (cannot?) properly update
the exception handlers at the call site. I took a few stabs at tweaking the
ASM code but it's pretty hairy (and will make this code even harder to maintain
going forward).
Tim and I have been discussing some alternatives. One possibility is to make
the modification at the callee intead of in the caller. We were trying to do
it without modifying Manageable but I'm not sure it's possible to both do this
in Manageable and avoid reflection (for performance).
Option 1: Given a clone() method on a Manageable object, replace with:
{code:java}
public Object clone() { // copy throws from original
return Util.cloneHelper(this);
}
public Object __tc_clone() { // copy throws from original clone
return new Bar(a);
}
{code}
and add a new static Util method (which would only be called from code in
Manageable clone methods):
{code:java}
public static Object cloneHelper(Manabeable refToBeCloned) throws
CloneNotSupportedException {
Object rv;
TCObject tco = refToBeCloned.__tc_managed();
if (tco != null) {
synchronized (tco.getResolveLock()) {
tco.resolveAllReferences();
rv = Util.fixTCObjectReferenceOfClonedObject(refToBeCloned,
refToBeCloned.__tc_clone());
}
} else {
rv = refToBeCloned.__tc_clone();
}
{code}
The issue here is that __tc_clone() would need to be added to Manageable. I
could work around that by using reflection in the call above to __tc_clone(),
but I presume the performance implications would be too much to bear.
Another option would be to modify at both caller and callee site so that the
caller would receive an extra method to do this logic. I think the exact same
Manageable/reflection problem arises though (which is why callee would need a
new method). Maybe this is the only option for logical?
Thoughts?
> CloneNotSupportedException got swallowed and replaced by
> IllegalMonitorStateException
> -------------------------------------------------------------------------------------
>
> Key: DEV-865
> URL: https://jira.terracotta.org/jira//browse/DEV-865
> Project: Development
> Issue Type: Bug
> Components: DSO:L1
> Affects Versions: trunk, 2.4.2
> Reporter: Hung Huynh
> Assigned To: Alex Miller
> Priority: 3 Minor
>
> For a class that doesn't implement Cloneable, the expected
> CloneNotSupportedException got lost if you wrap it in RuntimeException. The
> caller will see a IllegalMonitorStateException instead.
> Test for this bug: CloneExceptionTest, currently disabled.
> private static class MyStuff {
> protected Object clone() {
> try {
> return super.clone();
> } catch (CloneNotSupportedException e) {
> throw new RuntimeException(e);
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.terracotta.org/jira//secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
tc-dev mailing list
[email protected]
http://lists.terracotta.org/mailman/listinfo/tc-dev