Java XStream Deep Copy raises Exception ObjectAccessException -
i have xstream cloning. here simple code, have not expertise it.
com.thoughtworks.xstream.xstream xstream = new com.thoughtworks.xstream.xstream();
later store clone instances in hashtable (i know not idea storing on legacy system).
i store class of student, later store (clone) other instance of student , raises.
com.thoughtworks.xstream.converters.reflection.objectaccessexception: not call com.model.student_$$_javassist_83.writereplace():null java.lang.nullpointerexception
here code storing clone objects.
public void keep(string key, object value) { object obj = xstream.fromxml(xstream.toxml(value)); storage.put(key,obj); }
i think here source code problem arising. [xstream sources.][snippet]
public object callwritereplace(object object) { method writereplacemethod = getmethod(object.getclass(), "writereplace", null, true); if (writereplacemethod != null) { try { object[] empty_args = new object[0]; return writereplacemethod.invoke(object, empty_args); } catch (illegalaccessexception e) { throw new objectaccessexception("could not call " + object.getclass().getname() + ".writereplace()", e); } catch (invocationtargetexception e) { throw new objectaccessexception("could not call " + object.getclass().getname() + ".writereplace()", e.gettargetexception()); } } else { return object; } }
i hope can guide me, little lost on topic.
here trace. seems when clean dependences of clazz example student.setlistofphones(null)
works; exception throw on 2 or 3 level in graph. why according xstream says:
making suitable large object graphs or systems high message throughput.
stack trace:
com.thoughtworks.xstream.converters.reflection.objectaccessexception: not call com.model.subjects_$$_javassist_224.writereplace() : null java.lang.nullpointerexception @ javassist.util.proxy.runtimesupport$defaultmethodhandler.invoke(runtimesupport.java:37) @ com.model.subjects_$$_javassist_224.writereplace(subject_$$_javassist_224.java) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) @ java.lang.reflect.method.invoke(method.java:597) @ com.thoughtworks.xstream.converters.reflection.serializationmethodinvoker.callwritereplace(serializationmethodinvoker.java:88) @ com.thoughtworks.xstream.converters.reflection.abstractreflectionconverter.marshal(abstractreflectionconverter.java:60) @ com.thoughtworks.xstream.core.abstractreferencemarshaller.convert(abstractreferencemarshaller.java:69) @ com.thoughtworks.xstream.core.treemarshaller.convertanother(treemarshaller.java:58) @ com.thoughtworks.xstream.core.abstractreferencemarshaller$1.convertanother(abstractreferencemarshaller.java:84) @ com.thoughtworks.xstream.converters.reflection.abstractreflectionconverter.marshallfield(abstractreflectionconverter.java:229) @ com.thoughtworks.xstream.converters.reflection.abstractreflectionconverter$2.writefield(abstractreflectionconverter.java:208) @ com.thoughtworks.xstream.converters.reflection.abstractreflectionconverter$2.<init>(abstractreflectionconverter.java:171) @ com.thoughtworks.xstream.converters.reflection.abstractreflectionconverter.domarshal(abstractreflectionconverter.java:116) @ com.thoughtworks.xstream.converters.reflection.abstractreflectionconverter.marshal(abstractreflectionconverter.java:72) @ com.thoughtworks.xstream.core.abstractreferencemarshaller.convert(abstractreferencemarshaller.java:69) @ com.thoughtworks.xstream.core.treemarshaller.convertanother(treemarshaller.java:58) @ com.thoughtworks.xstream.core.abstractreferencemarshaller$1.convertanother(abstractreferencemarshaller.java:84)
hi have solved problem method creating shallow copy on class student , of course when xstream got class relationship wasn't deep enough xstream , nullpointerexception throw.. thank dave god bless.
Comments
Post a Comment