throw CloneNotSupportedException if Object.clone called on non-Cloneable

This commit is contained in:
Joel Dice 2013-04-22 21:19:01 -06:00
parent e0ceaa5f43
commit 63ee3ab0a2
3 changed files with 7 additions and 1 deletions

View File

@ -260,11 +260,14 @@ clone(Thread* t, object o)
memcpy(clone, o, size); memcpy(clone, o, size);
// clear any object header flags: // clear any object header flags:
setObjectClass(t, o, objectClass(t, o)); setObjectClass(t, o, objectClass(t, o));
} else { } else if (instanceOf(t, type(t, Machine::CloneableType), o)) {
clone = make(t, class_); clone = make(t, class_);
memcpy(reinterpret_cast<void**>(clone) + 1, memcpy(reinterpret_cast<void**>(clone) + 1,
reinterpret_cast<void**>(o) + 1, reinterpret_cast<void**>(o) + 1,
size - BytesPerWord); size - BytesPerWord);
} else {
throwNew(t, Machine::CloneNotSupportedExceptionType, "%s",
&byteArrayBody(t, className(t, objectClass(t, o)), 0));
} }
return clone; return clone;

View File

@ -226,6 +226,8 @@
(type negativeArraySizeException java/lang/NegativeArraySizeException) (type negativeArraySizeException java/lang/NegativeArraySizeException)
(type cloneNotSupportedException java/lang/CloneNotSupportedException)
(type reflectiveOperationException java/lang/ReflectiveOperationException) (type reflectiveOperationException java/lang/ReflectiveOperationException)
(type classCastException java/lang/ClassCastException) (type classCastException java/lang/ClassCastException)

1
vm.pro
View File

@ -54,6 +54,7 @@
-keep public class java.lang.ArrayIndexOutOfBoundsException -keep public class java.lang.ArrayIndexOutOfBoundsException
-keep public class java.lang.ArrayStoreException -keep public class java.lang.ArrayStoreException
-keep public class java.lang.NegativeArraySizeException -keep public class java.lang.NegativeArraySizeException
-keep public class java.lang.CloneNotSupportedException
-keep public class java.lang.ClassCastException -keep public class java.lang.ClassCastException
-keep public class java.lang.ClassNotFoundException -keep public class java.lang.ClassNotFoundException
-keep public class java.lang.NullPointerException -keep public class java.lang.NullPointerException