Sun GlassFish Communications Server 2.0 版本說明

TopLink 預期 Collection 欄位/特性可複製 ( 代碼 556)

說明

如果使用 java.util.Arrays.asList() API 將 Object[] 轉換為 Collection,JDK 便會傳回不可複製的 java.util.ArrayList 之實作。這樣會導致出現以下異常︰


The method invocation of the method [protected native java.lang.Object 
java.lang.Object.clone() throws java.lang.CloneNotSupportedException] on the object 
[[pkg.A id = xxx]], of class [class java.util.Arrays$ArrayList], triggered an 
exception. Internal Exception: java.lang.reflect.InvocationTargetException Target 
Invocation Exception: java.lang.CloneNotSupportedException: 
java.util.Arrays$ArrayList

此問題將以 https://glassfish.dev.java.net/issues/show_bug.cgi?id=556 持續追蹤。

解決方案

使用其建構子建立另一集合;例如︰


myCollection = new ArrayList(java.util.Arrays.asList(a))