diff --git a/jme3-core/src/main/java/com/jme3/export/SavableClassUtil.java b/jme3-core/src/main/java/com/jme3/export/SavableClassUtil.java index d41e6bb925..2e206a416b 100644 --- a/jme3-core/src/main/java/com/jme3/export/SavableClassUtil.java +++ b/jme3-core/src/main/java/com/jme3/export/SavableClassUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2012 jMonkeyEngine + * Copyright (c) 2009-2019 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,7 +36,9 @@ import com.jme3.material.MatParamTexture; import java.io.IOException; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -161,16 +163,19 @@ public static int getSavedSavableVersion(Object savable, Class loaders) throws InstantiationException, + InvocationTargetException, NoSuchMethodException, IllegalAccessException, ClassNotFoundException, IOException { if (loaders == null) { return fromName(className); @@ -208,4 +214,25 @@ public static Savable fromName(String className, List loaders) thro return fromName(className); } + + /** + * Use reflection to gain access to the no-arg constructor of the named + * class. + * + * @return the pre-existing constructor (not null) + */ + private static Constructor findNoArgConstructor(String className) + throws ClassNotFoundException, InstantiationException { + Class clazz = Class.forName(className); + Constructor result; + try { + result = clazz.getDeclaredConstructor(); + } catch (NoSuchMethodException e) { + throw new InstantiationException( + "Loading requires a no-arg constructor, but class " + + className + " lacks one."); + } + + return result; + } } diff --git a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryImporter.java b/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryImporter.java index d4c24054dc..93f082337b 100644 --- a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryImporter.java +++ b/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryImporter.java @@ -345,16 +345,7 @@ public Savable readObject(int id) { return out; - } catch (IOException e) { - logger.logp(Level.SEVERE, this.getClass().toString(), "readObject(int id)", "Exception", e); - return null; - } catch (ClassNotFoundException e) { - logger.logp(Level.SEVERE, this.getClass().toString(), "readObject(int id)", "Exception", e); - return null; - } catch (InstantiationException e) { - logger.logp(Level.SEVERE, this.getClass().toString(), "readObject(int id)", "Exception", e); - return null; - } catch (IllegalAccessException e) { + } catch (Exception e) { logger.logp(Level.SEVERE, this.getClass().toString(), "readObject(int id)", "Exception", e); return null; } diff --git a/jme3-plugins/src/xml/java/com/jme3/export/xml/DOMInputCapsule.java b/jme3-plugins/src/xml/java/com/jme3/export/xml/DOMInputCapsule.java index 6b0eb39b75..22779cf254 100644 --- a/jme3-plugins/src/xml/java/com/jme3/export/xml/DOMInputCapsule.java +++ b/jme3-plugins/src/xml/java/com/jme3/export/xml/DOMInputCapsule.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2012 jMonkeyEngine + * Copyright (c) 2009-2019 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,6 +38,7 @@ import com.jme3.util.BufferUtils; import com.jme3.util.IntMap; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; @@ -962,6 +963,7 @@ public Savable readSavable(String name, Savable defVal) throws IOException { private Savable readSavableFromCurrentElem(Savable defVal) throws InstantiationException, ClassNotFoundException, + NoSuchMethodException, InvocationTargetException, IOException, IllegalAccessException { Savable ret = defVal; Savable tmp = null;