一、前言
通过定义ObjectUtil的deepCopy进行对象深copy时,报“java.io.NotSerializableException: com.xwood.java.luoku.xdjar.JavaInfoDTO..”详细日志如下
java.io.NotSerializableException: com.xwood.java.luoku.xdjar.JavaInfoDTO@b@ at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)@b@ at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)@b@ at com.xwood.java.util.ObjectUtil.deepCopy(ObjectUtil.java:14)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:120)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:117)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:117)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:117)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:117)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:117)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.getJavaCons(JavaClassTreeContextHandler.java:33)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.parseJavainfo(PmsJavaContentFolderHandler.java:168)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.parseJavainfo(PmsJavaContentFolderHandler.java:198)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.parseJavainfo(PmsJavaContentFolderHandler.java:198)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.handlerFile(PmsJavaContentFolderHandler.java:61)@b@ at com.xwood.java.luoku.pms.JavaFolderParseHandler.run(JavaFolderParseHandler.java:46)@b@ at com.xwood.java.persist.PmsJarAtomExecuteor.jobWBSEntry(PmsJarAtomExecuteor.java:23)@b@ at com.xwood.java.common.Root5sTimerMain$1.run(Root5sTimerMain.java:53)@b@ at java.util.TimerThread.mainLoop(Timer.java:555)@b@ at java.util.TimerThread.run(Timer.java:505)@b@java.lang.NullPointerException@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:121)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:117)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:117)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:117)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:117)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.appendContext(JavaClassTreeContextHandler.java:117)@b@ at com.xwood.java.luoku.pms.JavaClassTreeContextHandler.getJavaCons(JavaClassTreeContextHandler.java:33)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.parseJavainfo(PmsJavaContentFolderHandler.java:168)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.parseJavainfo(PmsJavaContentFolderHandler.java:198)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.parseJavainfo(PmsJavaContentFolderHandler.java:198)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.handlerFile(PmsJavaContentFolderHandler.java:61)@b@ at com.xwood.java.luoku.pms.JavaFolderParseHandler.run(JavaFolderParseHandler.java:46)@b@ at com.xwood.java.persist.PmsJarAtomExecuteor.jobWBSEntry(PmsJarAtomExecuteor.java:23)@b@ at com.xwood.java.common.Root5sTimerMain$1.run(Root5sTimerMain.java:53)@b@ at java.util.TimerThread.mainLoop(Timer.java:555)@b@ at java.util.TimerThread.run(Timer.java:505)
二、解决方法
1)ObjectUtil的deepCopy深copy代码
import java.io.ByteArrayInputStream;@b@import java.io.ByteArrayOutputStream; @b@import java.io.ObjectInputStream;@b@import java.io.ObjectOutputStream;@b@@b@public class ObjectUtil {@b@ @b@ public static Object deepCopy(Object orig){@b@ try {@b@ ByteArrayOutputStream bos = new ByteArrayOutputStream();@b@ ObjectOutputStream oos = new ObjectOutputStream(bos);@b@ oos.writeObject(orig);@b@ oos.flush();@b@ ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());@b@ ObjectInputStream ois = new ObjectInputStream(bin);@b@ return ois.readObject();@b@ } catch (Exception e) { @b@ e.printStackTrace();@b@ }@b@ return null;@b@ } @b@@b@}
2)解决方法com.xwood.java.luoku.xdjar.JavaInfoDTO对象缺少java.io.Serializable接口,进行如下修改即可解决上面异常
public class JavaInfoDTO extends JarGroupDTO{@b@..@b@}
修改如下
public class JavaInfoDTO extends JarGroupDTO implements java.io.Serializable{@b@..@b@}