Skip to content

Commit

Permalink
Fix Class#newInstance deprecation warnings
Browse files Browse the repository at this point in the history
 - c.getDeclaredConstructor().newInstance() can be used instead.
 - simplified exception handling in related code
  • Loading branch information
mbien committed Feb 9, 2024
1 parent 4689251 commit 1473f38
Show file tree
Hide file tree
Showing 120 changed files with 330 additions and 535 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ private DeploymentFactory getFactory(String instanceURL) {
if(version!= null && "7".equals(version.getMajorNumber())) {
Class<?> c = loader.loadClass("org.jboss.as.ee.deployment.spi.factories.DeploymentFactoryImpl");
c.getMethod("register").invoke(null);
jbossFactory = (DeploymentFactory) c.newInstance();//NOI18N
jbossFactory = (DeploymentFactory) c.getDeclaredConstructor().newInstance();//NOI18N
} else {
jbossFactory = (DeploymentFactory) loader.loadClass("org.jboss.deployment.spi.factories.DeploymentFactoryImpl").newInstance();//NOI18N
jbossFactory = (DeploymentFactory) loader.loadClass("org.jboss.deployment.spi.factories.DeploymentFactoryImpl").getDeclaredConstructor().newInstance();//NOI18N
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static BaseBean newBean(CommonDDBean parent, String beanName, String vers
PACKAGE_PREFIX
+ version + DOT
+ beanName);
return (BaseBean) beanClass.newInstance();
return (BaseBean) beanClass.getDeclaredConstructor().newInstance();

} catch (Exception e) {
if (e instanceof ClassNotFoundException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static BaseBean newBean(CommonDDBean parent, String beanName, String pkgN
pkgName
+ DOT
+ beanName);
return (BaseBean) beanClass.newInstance();
return (BaseBean) beanClass.getDeclaredConstructor().newInstance();

} catch (Exception e) {
if (e instanceof ClassNotFoundException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static synchronized ClassLoader getNetBeansAndServerClassLoader(File plat
try {
data.cachedClassLoader =new ExtendedClassLoader( new Empty().getClass().getClassLoader());
updatePluginLoader( platformLocation, data.cachedClassLoader);
data.deploymentFactory = (DeploymentFactory) data.cachedClassLoader.loadClass("com.sun.enterprise.deployapi.SunDeploymentFactory").newInstance();//NOI18N
data.deploymentFactory = (DeploymentFactory) data.cachedClassLoader.loadClass("com.sun.enterprise.deployapi.SunDeploymentFactory").getDeclaredConstructor().newInstance();//NOI18N
data.serverOnlyClassLoader = new ExtendedClassLoader();
updatePluginLoader(platformLocation, data.serverOnlyClassLoader);
} catch (Exception ex2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public RootInterface newGraph(Class rootType, String version) {
try {
// Formerly invoked static 'createGraph()' method, but that is merely a wrapper
// for the default constructor so we'll call it directly.
graphRoot = (SunBaseBean) vInfo.getImplClass().newInstance();
graphRoot = (SunBaseBean) vInfo.getImplClass().getDeclaredConstructor().newInstance();
graphRoot.graphManager().setDoctype(vInfo.getPublicId(), vInfo.getSystemId());

Class proxyClass = vInfo.getProxyClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public CommonDDBean cloneVersion(String version) {
return (SunBaseBean) this.clone();
}

bean = (SunBaseBean) newBeanClass.newInstance();
bean = (SunBaseBean) newBeanClass.getDeclaredConstructor().newInstance();
} catch(Exception e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,15 @@ private GenericTableDialogPanelAccessor internalGetDialogPanel() {
GenericTableDialogPanelAccessor subPanel = null;

try {
subPanel = (GenericTableDialogPanelAccessor) entryPanelClass.newInstance();
subPanel = (GenericTableDialogPanelAccessor) entryPanelClass.getDeclaredConstructor().newInstance();
subPanel.init(getTableModel().getAppServerVersion(),
GenericTablePanel.this.getWidth()*3/4, entryList, extraData);

((JPanel) subPanel).getAccessibleContext().setAccessibleName(
resourceBundle.getString("ACSN_POPUP_" + resourceBase)); // NOI18N
((JPanel) subPanel).getAccessibleContext().setAccessibleDescription(
resourceBundle.getString("ACSD_POPUP_" + resourceBase)); // NOI18N
} catch(InstantiationException ex) {
// !PW Should never happen, but it's fatal for field editing if
// it does so what should exception should we throw?
} catch(IllegalAccessException ex) {
} catch(ReflectiveOperationException ex) {
// !PW Should never happen, but it's fatal for field editing if
// it does so what should exception should we throw?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,8 @@ public Object createObject(String type) {
Object object = null;
try {
Class classObject = Class.forName(type);
object = classObject.newInstance();
} catch (InstantiationException e) {
System.out.println(e);
} catch (IllegalAccessException e) {
System.out.println(e);
} catch (ClassNotFoundException e) {
object = classObject.getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e) {
System.out.println(e);
}
return object;
Expand All @@ -142,10 +138,8 @@ public Object createObject(String type) {
public Object createObject(Class classObject) {
Object object = null;
try {
object = classObject.newInstance();
} catch (InstantiationException e) {
System.out.println(e);
} catch (IllegalAccessException e) {
object = classObject.getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e) {
System.out.println(e);
}
return object;
Expand All @@ -171,13 +165,7 @@ public Object createObject(Constructor constructor,
object = constructor.newInstance(arguments);
//System.out.println ("Object: " + object.toString());
return object;
} catch (InstantiationException e) {
System.out.println(e);
} catch (IllegalAccessException e) {
System.out.println(e);
} catch (IllegalArgumentException e) {
System.out.println(e);
} catch (InvocationTargetException e) {
} catch (ReflectiveOperationException e) {
System.out.println(e);
}
return object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ private void runJPDAAppReloaded() {
ClassLoader reloadedClassLoader = customDefClassLoaders.get(reloadedPackageName);
if (reloadedClassLoader != null) {
Class reloadedClass = reloadedClassLoader.loadClass(reloadedClassName);
reloadedClass.getMethod("execute").invoke(reloadedClass.newInstance());
reloadedClass.getMethod("execute").invoke(reloadedClass.getDeclaredConstructor().newInstance());
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
Expand Down
Loading

0 comments on commit 1473f38

Please sign in to comment.