Skip to content

Commit 0975f3a

Browse files
authored
Merge pull request #131 from bulasevich/GR-62942
[Backport] [Oracle GraalVM] [GR-62942] Backport to 23.1: java.lang.ref.Reference and its subclasses are not cloneable.
2 parents fb847ba + bc7ab0a commit 0975f3a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/jdk/SubstrateObjectCloneSnippets.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import com.oracle.svm.core.heap.PodReferenceMapDecoder;
6969
import com.oracle.svm.core.hub.DynamicHub;
7070
import com.oracle.svm.core.hub.DynamicHubSupport;
71+
import com.oracle.svm.core.hub.HubType;
7172
import com.oracle.svm.core.hub.LayoutEncoding;
7273
import com.oracle.svm.core.meta.SharedType;
7374
import com.oracle.svm.core.snippets.KnownIntrinsics;
@@ -90,14 +91,19 @@ public static void registerForeignCalls(SubstrateForeignCallsProvider foreignCal
9091
}
9192

9293
@SubstrateForeignCallTarget(stubCallingConvention = false)
94+
// @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-21+35/src/hotspot/share/prims/jvm.cpp#L643-L692")
9395
private static Object doClone(Object original) throws CloneNotSupportedException, InstantiationException {
9496
if (original == null) {
9597
throw new NullPointerException();
9698
} else if (!(original instanceof Cloneable)) {
97-
throw new CloneNotSupportedException("Object is no instance of Cloneable.");
99+
throw new CloneNotSupportedException("Object is no instance of Cloneable: " + original.getClass().getName());
98100
}
99101

100102
DynamicHub hub = KnownIntrinsics.readHub(original);
103+
if (hub.getHubType() == HubType.REFERENCE_INSTANCE) {
104+
throw new CloneNotSupportedException("Subclasses of java.lang.ref.Reference are not cloneable: " + hub.getName());
105+
}
106+
101107
int layoutEncoding = hub.getLayoutEncoding();
102108
boolean isArrayLike = LayoutEncoding.isArrayLike(layoutEncoding);
103109

0 commit comments

Comments
 (0)