From a1209dab6e3eebf46812e07fd698b4920d54d1f6 Mon Sep 17 00:00:00 2001 From: jhugunin Date: Wed, 23 Jul 2003 16:45:09 +0000 Subject: added test for Bugzilla Bug 40589 Default method impl for interface causes internal exception. test submitted by George Harley --- tests/ajcTests.xml | 6 +++++ tests/bugs/CloneMethod.java | 58 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/bugs/CloneMethod.java diff --git a/tests/ajcTests.xml b/tests/ajcTests.xml index e133841a2..b88e97da1 100644 --- a/tests/ajcTests.xml +++ b/tests/ajcTests.xml @@ -6450,4 +6450,10 @@ + + + + + diff --git a/tests/bugs/CloneMethod.java b/tests/bugs/CloneMethod.java new file mode 100644 index 000000000..c80bc1708 --- /dev/null +++ b/tests/bugs/CloneMethod.java @@ -0,0 +1,58 @@ +aspect AspectA { + protected interface I { + } + + declare parents : MyString implements I; + + protected Object createCloneFor(I object) { + if (object instanceof MyString) { + return new MyString(((MyString) object).toString()); + } else { + return null; + } + } + + public Object I.clone() throws CloneNotSupportedException { + return super.clone(); +// return null; + } + + public Object cloneObject(I object) { + try { + return object.clone(); + } catch (CloneNotSupportedException ex) { + return createCloneFor(object); + } + } +} + +class MyString implements Cloneable { + + protected String text; + + public MyString(String init) { + text = init; + } + + public void setText(String newText) { + text = newText; + } + + public String toString() { + return "MyString: " + text; + } +} + +public class CloneMethod { + + public static void main(String[] args) { + MyString orig1; + MyString copy1; + + orig1 = new MyString(" This is I 1"); + copy1 = (MyString) AspectA.aspectOf().cloneObject(orig1); + orig1.setText(" This is I 2"); + copy1.setText(" This is Clone 1"); + System.out.println("... done."); + } +} -- cgit v1.2.3