mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-11 05:32:13 +00:00
cls.newInstance() causing warnings replaced with cls.getDeclaredConstructor().newInstance()
This commit is contained in:
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
@@ -28,6 +29,7 @@ import com.jpexs.helpers.plugin.CharSequenceJavaFileObject;
|
||||
import com.jpexs.helpers.plugin.ClassFileManager;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
@@ -111,12 +113,12 @@ public class SWFDecompilerPlugin {
|
||||
String pluginName = Path.getFileNameWithoutExtension(pluginFile);
|
||||
Class<?> cls = cl.loadClass(pluginName);
|
||||
if (SWFDecompilerListener.class.isAssignableFrom(cls)) {
|
||||
if (SWFDecompilerListener.class.isAssignableFrom(cls)) {
|
||||
SWFDecompilerListener listener = (SWFDecompilerListener) cls.getDeclaredConstructor().newInstance();
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
System.out.println("Plugin loaded: " + pluginName);
|
||||
System.out.println("Plugin loaded: " + pluginName);
|
||||
} catch (MalformedURLException | ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
@@ -159,9 +161,15 @@ public class SWFDecompilerPlugin {
|
||||
|
||||
// Creating an instance of our compiled class and
|
||||
try {
|
||||
try {
|
||||
listeners.add((SWFDecompilerListener) fileManager.getClassLoader(null).loadClass(fullName).getDeclaredConstructor().newInstance());
|
||||
System.out.println("Plugin loaded: " + fullName);
|
||||
System.out.println("Plugin loaded: " + fullName);
|
||||
} catch (ClassNotFoundException
|
||||
| InstantiationException
|
||||
| IllegalAccessException
|
||||
| NoSuchMethodException
|
||||
| SecurityException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.helpers;
|
||||
|
||||
import com.jpexs.decompiler.flash.types.FieldChangeObserver;
|
||||
@@ -20,6 +21,7 @@ import com.jpexs.decompiler.flash.types.annotations.Internal;
|
||||
import com.jpexs.decompiler.flash.types.annotations.SWFField;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.ArrayList;
|
||||
@@ -207,7 +209,7 @@ public class ReflectionTools {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Object newInstanceOf(Class<?> cls) throws InstantiationException, IllegalAccessException {
|
||||
if (cls == Integer.class || cls == int.class) {
|
||||
return 0;
|
||||
} else if (cls == Float.class || cls == float.class) {
|
||||
@@ -223,7 +225,12 @@ public class ReflectionTools {
|
||||
if (Modifier.isAbstract(cls.getModifiers())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return cls.getDeclaredConstructor().newInstance();
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
Logger.getLogger(ReflectionTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
Reference in New Issue
Block a user