diff --git a/contrib/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentFactory.java b/contrib/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentFactory.java index 5f928acc049b..5b1517cc246c 100644 --- a/contrib/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentFactory.java +++ b/contrib/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentFactory.java @@ -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 } diff --git a/enterprise/j2ee.dd.webservice/src/org/netbeans/modules/j2ee/dd/impl/webservices/CommonDDAccess.java b/enterprise/j2ee.dd.webservice/src/org/netbeans/modules/j2ee/dd/impl/webservices/CommonDDAccess.java index ca79217ff4ea..1411b9f8f165 100644 --- a/enterprise/j2ee.dd.webservice/src/org/netbeans/modules/j2ee/dd/impl/webservices/CommonDDAccess.java +++ b/enterprise/j2ee.dd.webservice/src/org/netbeans/modules/j2ee/dd/impl/webservices/CommonDDAccess.java @@ -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) diff --git a/enterprise/j2ee.dd/src/org/netbeans/modules/j2ee/dd/impl/common/CommonDDAccess.java b/enterprise/j2ee.dd/src/org/netbeans/modules/j2ee/dd/impl/common/CommonDDAccess.java index d26277440d24..5fd6d6d889a2 100644 --- a/enterprise/j2ee.dd/src/org/netbeans/modules/j2ee/dd/impl/common/CommonDDAccess.java +++ b/enterprise/j2ee.dd/src/org/netbeans/modules/j2ee/dd/impl/common/CommonDDAccess.java @@ -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) diff --git a/enterprise/j2ee.sun.appsrv/src/org/netbeans/modules/j2ee/sun/api/ServerLocationManager.java b/enterprise/j2ee.sun.appsrv/src/org/netbeans/modules/j2ee/sun/api/ServerLocationManager.java index c76606ddffd5..1908b09141e9 100644 --- a/enterprise/j2ee.sun.appsrv/src/org/netbeans/modules/j2ee/sun/api/ServerLocationManager.java +++ b/enterprise/j2ee.sun.appsrv/src/org/netbeans/modules/j2ee/sun/api/ServerLocationManager.java @@ -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) { diff --git a/enterprise/j2ee.sun.dd/src/org/netbeans/modules/j2ee/sun/dd/api/DDProvider.java b/enterprise/j2ee.sun.dd/src/org/netbeans/modules/j2ee/sun/dd/api/DDProvider.java index 1d4452084358..be02763b51c8 100644 --- a/enterprise/j2ee.sun.dd/src/org/netbeans/modules/j2ee/sun/dd/api/DDProvider.java +++ b/enterprise/j2ee.sun.dd/src/org/netbeans/modules/j2ee/sun/dd/api/DDProvider.java @@ -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(); diff --git a/enterprise/j2ee.sun.dd/src/org/netbeans/modules/j2ee/sun/dd/impl/common/SunBaseBean.java b/enterprise/j2ee.sun.dd/src/org/netbeans/modules/j2ee/sun/dd/impl/common/SunBaseBean.java index 40843bff45ea..c2936c378fa9 100644 --- a/enterprise/j2ee.sun.dd/src/org/netbeans/modules/j2ee/sun/dd/impl/common/SunBaseBean.java +++ b/enterprise/j2ee.sun.dd/src/org/netbeans/modules/j2ee/sun/dd/impl/common/SunBaseBean.java @@ -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); } diff --git a/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/GenericTablePanel.java b/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/GenericTablePanel.java index 99ae13ed057a..e4e563fa22fa 100644 --- a/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/GenericTablePanel.java +++ b/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/GenericTablePanel.java @@ -238,7 +238,7 @@ 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); @@ -246,10 +246,7 @@ private GenericTableDialogPanelAccessor internalGetDialogPanel() { 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? } diff --git a/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/validation/util/Utils.java b/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/validation/util/Utils.java index 3334ebc821c2..287f96af7181 100644 --- a/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/validation/util/Utils.java +++ b/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/validation/util/Utils.java @@ -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; @@ -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; @@ -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; diff --git a/enterprise/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/DeployOnSaveManager.java b/enterprise/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/DeployOnSaveManager.java index cfb5e42a4464..04b70ec0e13e 100644 --- a/enterprise/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/DeployOnSaveManager.java +++ b/enterprise/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/DeployOnSaveManager.java @@ -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); diff --git a/enterprise/javaee.wildfly/src/org/netbeans/modules/javaee/wildfly/ide/commands/WildflyClient.java b/enterprise/javaee.wildfly/src/org/netbeans/modules/javaee/wildfly/ide/commands/WildflyClient.java index c963e52d921d..9bd8eb9665f2 100644 --- a/enterprise/javaee.wildfly/src/org/netbeans/modules/javaee/wildfly/ide/commands/WildflyClient.java +++ b/enterprise/javaee.wildfly/src/org/netbeans/modules/javaee/wildfly/ide/commands/WildflyClient.java @@ -205,7 +205,7 @@ private String resolvePath(WildflyClassLoader cl, LinkedHashMap return modelNodeAsString(cl, readResult(cl, response)); } return ""; - } catch (InvocationTargetException | ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -272,7 +272,7 @@ public synchronized void shutdownServer(int timeout) throws IOException, Interru throw new IOException(ex); } close(); - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -304,7 +304,7 @@ public synchronized boolean isServerRunning(String homeDir, String configFile) { LOGGER.log(Level.FINE, null, ex.getTargetException()); close(); return false; - } catch (IllegalAccessException | ClassNotFoundException | InstantiationException | NoSuchMethodException | IOException | InterruptedException | ExecutionException ex) { + } catch (ReflectiveOperationException | IOException | InterruptedException | ExecutionException ex) { LOGGER.log(Level.FINE, null, ex); close(); return false; @@ -375,7 +375,7 @@ public Collection listAvailableModules() throws IOException { } } return modules; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -410,7 +410,7 @@ public Collection listWebModules(Lookup lookup) throws IOE } } return modules; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -452,7 +452,7 @@ public String getWebModuleURL(String webModuleName) throws IOException { } } return ""; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -487,7 +487,7 @@ public Collection listEJBModules(Lookup lookup) throws IOE } } return modules; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -505,7 +505,7 @@ public boolean startModule(WildflyTargetModuleID tmid) throws IOException { return true; } return false; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -519,7 +519,7 @@ public boolean startModule(String moduleName) throws IOException { Object enableDeployment = createOperation(cl, DEPLOYMENT_REDEPLOY_OPERATION, deploymentAddressModelNode); Object result = executeOnModelNode(cl, enableDeployment); return isSuccessfulOutcome(cl, result); - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -532,7 +532,7 @@ public boolean stopModule(String moduleName) throws IOException { // ModelNode Object enableDeployment = createOperation(cl, DEPLOYMENT_UNDEPLOY_OPERATION, deploymentAddressModelNode); return isSuccessfulOutcome(cl, executeOnModelNode(cl, enableDeployment)); - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -552,7 +552,7 @@ public boolean undeploy(String fileName) throws IOException { addModelNodeChild(cl, steps, createOperation(cl, DEPLOYMENT_UNDEPLOY_OPERATION, deploymentAddressModelNode)); addModelNodeChild(cl, steps, createRemoveOperation(cl, deploymentAddressModelNode)); return isSuccessfulOutcome(cl, executeOnModelNode(cl, undeploy)); - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -586,7 +586,7 @@ public boolean deploy(DeploymentContext deployment) throws IOException { // ModelNode Object result = executeOnModelNode(cl, deploy); return isSuccessfulOutcome(cl, result); - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -626,7 +626,7 @@ private Set listDatasources() throws IOException { } } return listedDatasources; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -655,7 +655,7 @@ private WildflyDatasource getDatasource(WildflyClassLoader cl, String name) thro modelNodeAsString(cl, getModelNodeChild(cl, datasource, "driver-class"))); } return null; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -672,7 +672,7 @@ public boolean removeDatasource(String name) throws IOException { // ModelNode Object response = executeOnModelNode(cl, operation); return (isSuccessfulOutcome(cl, response)); - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -703,7 +703,7 @@ private Pair getServerPaths(WildflyClassLoader cl) { } } return null; - } catch (IOException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (IOException | ReflectiveOperationException ex) { return null; } } @@ -755,7 +755,7 @@ public List listDestinationForDeployment(String deplo } } return destinations; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -788,7 +788,7 @@ public List listDestinations() throws IOException { } } return destinations; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -834,7 +834,7 @@ private List getJMSDestinationForServerDeployment(Str } } return listedDestinations; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -878,7 +878,7 @@ private List getJMSDestinationForServer(String server } } return listedDestinations; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -915,7 +915,7 @@ public boolean addMessageDestination(WildflyMessageDestination destination) thro } Object response = executeOnModelNode(cl, operation); return (isSuccessfulOutcome(cl, response)); - } catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) { + } catch (ReflectiveOperationException ex) { return false; } } @@ -935,7 +935,7 @@ public boolean removeMessageDestination(WildflyMessageDestination destination) t Object operation = createRemoveOperation(cl, address); Object response = executeOnModelNode(cl, operation); return (isSuccessfulOutcome(cl, response)); - } catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) { + } catch (ReflectiveOperationException ex) { return false; } } @@ -984,7 +984,7 @@ private Collection listJaxrsResources(String deployment) t } } return jaxrsResources.values(); - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -1014,7 +1014,7 @@ public Collection listMailSessions() throws IOExcept } } return modules; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -1037,7 +1037,7 @@ public Collection listEarApplications(Lookup lookup) throws IOException { } } return modules; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -1080,7 +1080,7 @@ public Collection listEarSubModules(Lookup lookup, String jeeApplicationName) th } } return modules; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -1107,14 +1107,13 @@ public Collection listEJBForDeployment(Lookup lookup, String applicationName) th } return modules; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } private List listEJBs(WildflyClassLoader cl, - Object deployment, WildflyEjbComponentNode.Type type) throws IllegalAccessException, NoSuchMethodException, - InvocationTargetException { + Object deployment, WildflyEjbComponentNode.Type type) throws ReflectiveOperationException { List modules = new ArrayList<>(); if (modelNodeHasDefinedChild(cl, deployment, type.getPropertyName())) { List ejbs = modelNodeAsList(cl, getModelNodeChild(cl, deployment, type.getPropertyName())); @@ -1125,9 +1124,7 @@ private List listEJBs(WildflyClassLoader cl, return modules; } - private WildflySocket fillSocket(String name, boolean outBound) throws - ClassNotFoundException, NoSuchMethodException, - InvocationTargetException, IllegalAccessException, InstantiationException, IOException { + private WildflySocket fillSocket(String name, boolean outBound) throws ReflectiveOperationException, IOException { WildflyClassLoader cl = WildflyDeploymentFactory.getInstance().getWildFlyClassLoader(ip); WildflySocket socket = new WildflySocket(); LinkedHashMap values = new LinkedHashMap<>(); @@ -1187,7 +1184,7 @@ public Collection listConnectionFactories() throws IOE } } return connectionFactories; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -1224,14 +1221,12 @@ private Collection getConnectionFactoriesFor } } return listedConnectionFactories; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } - private WildflyConnectionFactory fillConnectionFactory(String name, Object configuration) throws - ClassNotFoundException, NoSuchMethodException, - InvocationTargetException, IllegalAccessException, InstantiationException, IOException { + private WildflyConnectionFactory fillConnectionFactory(String name, Object configuration) throws ReflectiveOperationException, IOException { WildflyClassLoader cl = WildflyDeploymentFactory.getInstance().getWildFlyClassLoader(ip); List properties = modelNodeAsPropertyList(cl, configuration); Map attributes = new HashMap<>(properties.size()); @@ -1245,9 +1240,7 @@ private WildflyConnectionFactory fillConnectionFactory(String name, Object confi return new WildflyConnectionFactory(attributes, name); } - private WildflyMailSessionResource fillMailSession(String name, Object mailSession) throws - ClassNotFoundException, NoSuchMethodException, - InvocationTargetException, IllegalAccessException, InstantiationException, IOException { + private WildflyMailSessionResource fillMailSession(String name, Object mailSession) throws ReflectiveOperationException, IOException { WildflyClassLoader cl = WildflyDeploymentFactory.getInstance().getWildFlyClassLoader(ip); Object configuration = modelNodeAsPropertyForValue(cl, mailSession); @@ -1307,7 +1300,7 @@ private String resolveExpression(String unresolvedString) throws IOException { return modelNodeAsString(cl, resolvedExpression); } return unresolvedString; - } catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } @@ -1351,7 +1344,7 @@ public Collection listResourceAdapters() throws IOExcept } } return resourceAdapters; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException ex) { + } catch (ReflectiveOperationException ex) { throw new IOException(ex); } } diff --git a/enterprise/javaee.wildfly/src/org/netbeans/modules/javaee/wildfly/ide/commands/WildflyManagementAPI.java b/enterprise/javaee.wildfly/src/org/netbeans/modules/javaee/wildfly/ide/commands/WildflyManagementAPI.java index 40e7a1df5094..7db923e80d65 100644 --- a/enterprise/javaee.wildfly/src/org/netbeans/modules/javaee/wildfly/ide/commands/WildflyManagementAPI.java +++ b/enterprise/javaee.wildfly/src/org/netbeans/modules/javaee/wildfly/ide/commands/WildflyManagementAPI.java @@ -49,8 +49,7 @@ public class WildflyManagementAPI { private static final int TIMEOUT = 1000; static Object createClient(WildflyClassLoader cl, Version version, final String serverAddress, final int serverPort, - final CallbackHandler handler) throws ClassNotFoundException, NoSuchMethodException, - IllegalAccessException, InvocationTargetException, NoSuchAlgorithmException, InstantiationException { + final CallbackHandler handler) throws ReflectiveOperationException, NoSuchAlgorithmException { Class clazz = cl.loadClass("org.jboss.as.controller.client.ModelControllerClient$Factory"); // NOI18N if (version.compareTo(WildflyPluginUtils.WILDFLY_26_0_0) >= 0) { Class configurationBuilderClazz = cl.loadClass("org.jboss.as.controller.client.ModelControllerClientConfiguration$Builder"); @@ -71,15 +70,13 @@ static Object createClient(WildflyClassLoader cl, Version version, final String return method.invoke(null, serverAddress, serverPort, handler, SSLContext.getDefault(), TIMEOUT); } - static void closeClient(WildflyClassLoader cl, Object client) throws ClassNotFoundException, NoSuchMethodException, - IllegalAccessException, InvocationTargetException { + static void closeClient(WildflyClassLoader cl, Object client) throws ReflectiveOperationException { Method method = client.getClass().getMethod("close", new Class[]{}); method.invoke(client, (Object[]) null); } // ModelNode - static Object createDeploymentPathAddressAsModelNode(WildflyClassLoader cl, String name) - throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + static Object createDeploymentPathAddressAsModelNode(WildflyClassLoader cl, String name) throws ReflectiveOperationException { Class paClazz = cl.loadClass("org.jboss.as.controller.PathAddress"); // NOI18N Class peClazz = cl.loadClass("org.jboss.as.controller.PathElement"); // NOI18N @@ -98,8 +95,7 @@ static Object createDeploymentPathAddressAsModelNode(WildflyClassLoader cl, Stri } // ModelNode - static Object createPathAddressAsModelNode(WildflyClassLoader cl, LinkedHashMap elements) - throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + static Object createPathAddressAsModelNode(WildflyClassLoader cl, LinkedHashMap elements) throws ReflectiveOperationException { Class paClazz = cl.loadClass("org.jboss.as.controller.PathAddress"); // NOI18N Class peClazz = cl.loadClass("org.jboss.as.controller.PathElement"); // NOI18N @@ -119,8 +115,7 @@ static Object createPathAddressAsModelNode(WildflyClassLoader cl, LinkedHashMap< } // ModelNode - static Object createOperation(WildflyClassLoader cl, Object name, Object modelNode) - throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + static Object createOperation(WildflyClassLoader cl, Object name, Object modelNode) throws ReflectiveOperationException { Class clazz = cl.loadClass("org.jboss.as.controller.client.helpers.Operations"); // NOI18N Class modelClazz = cl.loadClass("org.jboss.dmr.ModelNode"); // NOI18N Method method = clazz.getDeclaredMethod("createOperation", new Class[]{String.class, modelClazz}); @@ -128,8 +123,7 @@ static Object createOperation(WildflyClassLoader cl, Object name, Object modelNo } // ModelNode - static Object createReadResourceOperation(WildflyClassLoader cl, Object modelNode, boolean recursive, boolean runtime) - throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { + static Object createReadResourceOperation(WildflyClassLoader cl, Object modelNode, boolean recursive, boolean runtime) throws ReflectiveOperationException { Class clazz = cl.loadClass("org.jboss.as.controller.client.helpers.Operations"); // NOI18N Class modelClazz = cl.loadClass("org.jboss.dmr.ModelNode"); // NOI18N Method method = clazz.getDeclaredMethod("createReadResourceOperation", new Class[]{modelClazz, boolean.class}); @@ -139,8 +133,7 @@ static Object createReadResourceOperation(WildflyClassLoader cl, Object modelNod } // ModelNode - static Object createRemoveOperation(WildflyClassLoader cl, Object modelNode) throws ClassNotFoundException, - NoSuchMethodException, IllegalAccessException, InvocationTargetException { + static Object createRemoveOperation(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Class clazz = cl.loadClass("org.jboss.as.controller.client.helpers.Operations"); // NOI18N Class modelClazz = cl.loadClass("org.jboss.dmr.ModelNode"); // NOI18N Method method = clazz.getDeclaredMethod("createRemoveOperation", new Class[]{modelClazz}); @@ -148,8 +141,7 @@ static Object createRemoveOperation(WildflyClassLoader cl, Object modelNode) thr } // ModelNode - static Object createAddOperation(WildflyClassLoader cl, Object modelNode) throws ClassNotFoundException, - NoSuchMethodException, IllegalAccessException, InvocationTargetException { + static Object createAddOperation(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Class clazz = cl.loadClass("org.jboss.as.controller.client.helpers.Operations"); // NOI18N Class modelClazz = cl.loadClass("org.jboss.dmr.ModelNode"); // NOI18N Method method = clazz.getDeclaredMethod("createAddOperation", new Class[]{modelClazz}); @@ -157,8 +149,7 @@ static Object createAddOperation(WildflyClassLoader cl, Object modelNode) throws } // ModelNode - static Object readResult(WildflyClassLoader cl, Object modelNode) throws ClassNotFoundException, - NoSuchMethodException, IllegalAccessException, InvocationTargetException { + static Object readResult(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Class clazz = cl.loadClass("org.jboss.as.controller.client.helpers.Operations"); // NOI18N Class modelClazz = cl.loadClass("org.jboss.dmr.ModelNode"); // NOI18N Method method = clazz.getDeclaredMethod("readResult", new Class[]{modelClazz}); @@ -166,22 +157,19 @@ static Object readResult(WildflyClassLoader cl, Object modelNode) throws ClassNo } // ModelNode - static Object getModelNodeChild(WildflyClassLoader cl, Object modelNode, Object name) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static Object getModelNodeChild(WildflyClassLoader cl, Object modelNode, Object name) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("get", String.class); return method.invoke(modelNode, name); } // ModelNode - static Object getModelNodeChildAtIndex(WildflyClassLoader cl, Object modelNode, int index) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static Object getModelNodeChildAtIndex(WildflyClassLoader cl, Object modelNode, int index) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("get", int.class); return method.invoke(modelNode, index); } // ModelNode - static Object getModelNodeChildAtPath(WildflyClassLoader cl, Object modelNode, Object[] path) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static Object getModelNodeChildAtPath(WildflyClassLoader cl, Object modelNode, Object[] path) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("get", String[].class); Object array = Array.newInstance(String.class, path.length); for (int i = 0; i < path.length; i++) { @@ -191,36 +179,32 @@ static Object getModelNodeChildAtPath(WildflyClassLoader cl, Object modelNode, O } // ModelNode - static boolean modelNodeHasChild(WildflyClassLoader cl, Object modelNode, String child) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static boolean modelNodeHasChild(WildflyClassLoader cl, Object modelNode, String child) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("has", String.class); return (Boolean) method.invoke(modelNode, child); } // ModelNode - static boolean modelNodeHasDefinedChild(WildflyClassLoader cl, Object modelNode, String child) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static boolean modelNodeHasDefinedChild(WildflyClassLoader cl, Object modelNode, String child) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("hasDefined", String.class); return (Boolean) method.invoke(modelNode, child); } // ModelNode - static Object createModelNode(WildflyClassLoader cl) throws IllegalAccessException, ClassNotFoundException, InstantiationException { + static Object createModelNode(WildflyClassLoader cl) throws ReflectiveOperationException { Class modelClazz = cl.loadClass("org.jboss.dmr.ModelNode"); // NOI18N - return modelClazz.newInstance(); + return modelClazz.getDeclaredConstructor().newInstance(); } // ModelNode - static Object setModelNodeChildString(WildflyClassLoader cl, Object modelNode, Object value) throws IllegalAccessException, - ClassNotFoundException, InstantiationException, NoSuchMethodException, InvocationTargetException { + static Object setModelNodeChildString(WildflyClassLoader cl, Object modelNode, Object value) throws ReflectiveOperationException { assert value != null; Method method = modelNode.getClass().getMethod("set", String.class); return method.invoke(modelNode, value); } // ModelNode - static Object setModelNodeChild(WildflyClassLoader cl, Object modelNode, Object value) throws IllegalAccessException, - ClassNotFoundException, InstantiationException, NoSuchMethodException, InvocationTargetException { + static Object setModelNodeChild(WildflyClassLoader cl, Object modelNode, Object value) throws ReflectiveOperationException { assert value != null; Class modelClazz = cl.loadClass("org.jboss.dmr.ModelNode"); // NOI18N Method method = modelNode.getClass().getMethod("set", modelClazz); @@ -228,51 +212,44 @@ static Object setModelNodeChild(WildflyClassLoader cl, Object modelNode, Object } // ModelNode - static Object setModelNodeChild(WildflyClassLoader cl, Object modelNode, int value) throws IllegalAccessException, - ClassNotFoundException, InstantiationException, NoSuchMethodException, InvocationTargetException { + static Object setModelNodeChild(WildflyClassLoader cl, Object modelNode, int value) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("set", int.class); return method.invoke(modelNode, value); } // ModelNode - static Object setModelNodeChild(WildflyClassLoader cl, Object modelNode, boolean value) throws IllegalAccessException, - ClassNotFoundException, InstantiationException, NoSuchMethodException, InvocationTargetException { + static Object setModelNodeChild(WildflyClassLoader cl, Object modelNode, boolean value) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("set", boolean.class); return method.invoke(modelNode, value); } // ModelNode - static Object setModelNodeChildEmptyList(WildflyClassLoader cl, Object modelNode) throws IllegalAccessException, - ClassNotFoundException, InstantiationException, NoSuchMethodException, InvocationTargetException { + static Object setModelNodeChildEmptyList(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("setEmptyList", (Class[]) null); return method.invoke(modelNode, (Object[]) null); } // ModelNode - static Object setModelNodeChildBytes(WildflyClassLoader cl, Object modelNode, byte[] value) throws IllegalAccessException, - ClassNotFoundException, InstantiationException, NoSuchMethodException, InvocationTargetException { + static Object setModelNodeChildBytes(WildflyClassLoader cl, Object modelNode, byte[] value) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("set", byte[].class); return method.invoke(modelNode, value); } // ModelNode - static Object addModelNodeChild(WildflyClassLoader cl, Object modelNode, Object toAddModelNode) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException, ClassNotFoundException { + static Object addModelNodeChild(WildflyClassLoader cl, Object modelNode, Object toAddModelNode) throws ReflectiveOperationException { Class modelClazz = cl.loadClass("org.jboss.dmr.ModelNode"); // NOI18N Method method = modelNode.getClass().getMethod("add", modelClazz); return method.invoke(modelNode, toAddModelNode); } - static Object addModelNodeChildString(WildflyClassLoader cl, Object modelNode, String toAddModelNode) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException, ClassNotFoundException { + static Object addModelNodeChildString(WildflyClassLoader cl, Object modelNode, String toAddModelNode) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("add", String.class); return method.invoke(modelNode, toAddModelNode); } - static boolean modelNodeIsDefined(WildflyClassLoader cl, Object modelNode) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static boolean modelNodeIsDefined(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("isDefined", (Class[]) null); return (Boolean) method.invoke(modelNode, (Object[]) null); } @@ -283,60 +260,51 @@ static String modelNodeAsString(WildflyClassLoader cl, Object modelNode) throws return (String) method.invoke(modelNode, (Object[]) null); } - static String modelNodeAsPropertyForName(WildflyClassLoader cl, Object modelNode) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static String modelNodeAsPropertyForName(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("asProperty", (Class[]) null); Object property = method.invoke(modelNode, (Object[]) null); return getPropertyName(cl, property); } - static Object modelNodeAsPropertyForValue(WildflyClassLoader cl, Object modelNode) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static Object modelNodeAsPropertyForValue(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("asProperty", (Class[]) null); Object property = method.invoke(modelNode, (Object[]) null); return getPropertyValue(cl, property); } - static String getPropertyName(WildflyClassLoader cl, Object property) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static String getPropertyName(WildflyClassLoader cl, Object property) throws ReflectiveOperationException { Method method = property.getClass().getMethod("getName", (Class[]) null); return (String) method.invoke(property, (Object[]) null); } - static Object getPropertyValue(WildflyClassLoader cl, Object property) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static Object getPropertyValue(WildflyClassLoader cl, Object property) throws ReflectiveOperationException { Method method = property.getClass().getMethod("getValue", (Class[]) null); return method.invoke(property, (Object[]) null); } // List - static List modelNodeAsList(WildflyClassLoader cl, Object modelNode) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static List modelNodeAsList(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("asList", (Class[]) null); return (List) method.invoke(modelNode, (Object[]) null); } - static List modelNodeAsPropertyList(WildflyClassLoader cl, Object modelNode) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static List modelNodeAsPropertyList(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("asPropertyList", (Class[]) null); return (List) method.invoke(modelNode, (Object[]) null); } - static boolean modelNodeAsBoolean(WildflyClassLoader cl, Object modelNode) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static boolean modelNodeAsBoolean(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("asBoolean", (Class[]) null); return (boolean) method.invoke(modelNode, (Object[]) null); } - static int modelNodeAsInt(WildflyClassLoader cl, Object modelNode) throws IllegalAccessException, - NoSuchMethodException, InvocationTargetException { + static int modelNodeAsInt(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Method method = modelNode.getClass().getMethod("asInt", (Class[]) null); return (int) method.invoke(modelNode, (Object[]) null); } - static boolean isSuccessfulOutcome(WildflyClassLoader cl, Object modelNode) throws ClassNotFoundException, - NoSuchMethodException, IllegalAccessException, InvocationTargetException { + static boolean isSuccessfulOutcome(WildflyClassLoader cl, Object modelNode) throws ReflectiveOperationException { Class clazz = cl.loadClass("org.jboss.as.controller.client.helpers.Operations"); // NOI18N Class modelClazz = cl.loadClass("org.jboss.dmr.ModelNode"); // NOI18N Method method = clazz.getDeclaredMethod("isSuccessfulOutcome", modelClazz); diff --git a/enterprise/payara.eecommon/src/org/netbeans/modules/payara/eecommon/dd/loader/PayaraDDProvider.java b/enterprise/payara.eecommon/src/org/netbeans/modules/payara/eecommon/dd/loader/PayaraDDProvider.java index 5d26df031fb5..2fbaa2b370b4 100644 --- a/enterprise/payara.eecommon/src/org/netbeans/modules/payara/eecommon/dd/loader/PayaraDDProvider.java +++ b/enterprise/payara.eecommon/src/org/netbeans/modules/payara/eecommon/dd/loader/PayaraDDProvider.java @@ -475,7 +475,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(); diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/DeployOnSaveManager.java b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/DeployOnSaveManager.java index bbd6fbb0a9bb..c75aa62c3e89 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/DeployOnSaveManager.java +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/DeployOnSaveManager.java @@ -506,7 +506,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); diff --git a/enterprise/websvc.manager/src/org/netbeans/modules/websvc/manager/ui/ReflectionHelper.java b/enterprise/websvc.manager/src/org/netbeans/modules/websvc/manager/ui/ReflectionHelper.java index 46adb5267fef..7432fd8c40bf 100644 --- a/enterprise/websvc.manager/src/org/netbeans/modules/websvc/manager/ui/ReflectionHelper.java +++ b/enterprise/websvc.manager/src/org/netbeans/modules/websvc/manager/ui/ReflectionHelper.java @@ -24,7 +24,6 @@ import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URLClassLoader; import java.util.ArrayList; @@ -169,7 +168,7 @@ public static Object makeGenericArray(String componentType, int length, ClassLoa } return Array.newInstance(componentClass, length); - } catch (Exception ex) { + } catch (ReflectiveOperationException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } } @@ -198,16 +197,8 @@ public static Object makeJAXBElement(String valueType, String localPart, Object Constructor jaxBConstr = jaxBClass.getConstructor(new Class[]{qNameClass, Class.class, Object.class}); return jaxBConstr.newInstance(qName, declaredClass, value); - } catch (ClassNotFoundException cnfe) { - throw new WebServiceReflectionException("ClassNotFoundException", cnfe); - } catch (InstantiationException ie) { - throw new WebServiceReflectionException("InstantiationException", ie); - } catch (IllegalAccessException iae) { - throw new WebServiceReflectionException("IllegalAccessException", iae); - } catch (InvocationTargetException ite) { - throw new WebServiceReflectionException("InvocationTargetException", ite); - } catch (NoSuchMethodException nsme) { - throw new WebServiceReflectionException("NoSuchMethodException", nsme); + } catch (ReflectiveOperationException ex) { + throw new WebServiceReflectionException(ex.getClass().getName(), ex); } finally { if (savedLoader != null) { Thread.currentThread().setContextClassLoader(savedLoader); @@ -222,7 +213,7 @@ public static Object makeEnumeration(String enumeration, ClassLoader loader) Class enumClass = Class.forName(enumeration, true, loader); return Enum.valueOf(enumClass, enumerationValues.get(0)); - } catch (Exception ex) { + } catch (ReflectiveOperationException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } } @@ -232,7 +223,7 @@ public static Object getEnumeration(String enumeration, String name, ClassLoader try { Class enumClass = Class.forName(enumeration, true, loader); return Enum.valueOf(enumClass, name); - } catch (Exception ex) { + } catch (ReflectiveOperationException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } } @@ -251,16 +242,16 @@ public static Object makeCollection(String className, ClassLoader loader) } else { Class cls = Class.forName(className, true, loader); if (cls.isInterface()) { - return new ArrayList(); + return new ArrayList<>(); } else { savedLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(loader); - Object result = cls.newInstance(); + Object result = cls.getDeclaredConstructor().newInstance(); return result; } } - } catch (Exception ex) { + } catch (ReflectiveOperationException | SecurityException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } finally { if (savedLoader != null) { @@ -279,15 +270,11 @@ public static Object makeComplexType(String typeName, ClassLoader loader) Thread.currentThread().setContextClassLoader(loader); Class typeClass = Class.forName(typeName, true, loader); - Object result = typeClass.newInstance(); + Object result = typeClass.getDeclaredConstructor().newInstance(); return result; - } catch (ClassNotFoundException cnfe) { - throw new WebServiceReflectionException("ClassNotFoundException", cnfe); - } catch (InstantiationException ie) { - throw new WebServiceReflectionException("InstantiationException", ie); - } catch (IllegalAccessException iae) { - throw new WebServiceReflectionException("IllegalAccessException", iae); + } catch (ReflectiveOperationException ex) { + throw new WebServiceReflectionException(ex.getClass().getName(), ex); } finally { if (savedLoader != null) { Thread.currentThread().setContextClassLoader(savedLoader); @@ -298,7 +285,7 @@ public static Object makeComplexType(String typeName, ClassLoader loader) public static List getEnumerationValues(String enumeration, ClassLoader loader) throws WebServiceReflectionException { try { - List enumerations = new ArrayList(); + List enumerations = new ArrayList<>(); Class enumerClass = Class.forName(enumeration, true, loader); Field[] fields = enumerClass.getDeclaredFields(); @@ -310,7 +297,7 @@ public static List getEnumerationValues(String enumeration, ClassLoader } return enumerations; - } catch (Exception ex) { + } catch (ClassNotFoundException | SecurityException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } } @@ -319,7 +306,7 @@ public static List getPropertyNames(String complexType, ClassLoader load throws WebServiceReflectionException { ClassLoader savedLoader = null; try { - List properties = new ArrayList(); + List properties = new ArrayList<>(); savedLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(loader); @@ -341,12 +328,11 @@ public static List getPropertyNames(String complexType, ClassLoader load properties.add(props[i]); } } - } catch (Exception ex) { - } + } catch (ReflectiveOperationException | SecurityException ex) {} } return properties; - } catch (Exception ex) { + } catch (ClassNotFoundException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } finally { if (savedLoader != null) { @@ -380,7 +366,7 @@ public static String getPropertyType(String type, String propName, ClassLoader l } return TypeUtil.typeToString(method.getGenericReturnType()); - } catch (Exception ex) { + } catch (ReflectiveOperationException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } finally { if (savedLoader != null) { @@ -393,7 +379,7 @@ public static Object getHolderValue(Object holder) throws WebServiceReflectionEx try { Field valueField = holder.getClass().getField("value"); // NO18N return valueField.get(holder); - } catch (Exception ex) { + } catch (ReflectiveOperationException | SecurityException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } } @@ -402,7 +388,7 @@ public static void setHolderValue(Object holder, Object value) throws WebService try { Field valueField = holder.getClass().getField("value"); // NO18N valueField.set(holder, value); - } catch (Exception ex) { + } catch (ReflectiveOperationException | SecurityException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } } @@ -411,7 +397,7 @@ public static Object getJAXBElementValue(Object jaxBElement) throws WebServiceRe try { Method m = jaxBElement.getClass().getMethod("getValue", new Class[0]); // NOI18N return m.invoke(jaxBElement); - } catch (Exception ex) { + } catch (ReflectiveOperationException | SecurityException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } } @@ -423,7 +409,7 @@ public static String getQNameLocalPart(Object jaxBElement) throws WebServiceRefl Method getLocalPart = qName.getClass().getMethod("getLocalPart", new Class[0]); // NOI18N return (String) getLocalPart.invoke(qName); - } catch (Exception ex) { + } catch (ReflectiveOperationException | SecurityException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } } @@ -432,7 +418,7 @@ public static void setJAXBElementValue(Object jaxBElement, Object value) throws try { Method m = jaxBElement.getClass().getMethod("setValue", new Class[]{Object.class}); // NOI18N m.invoke(jaxBElement, value); - } catch (Exception ex) { + } catch (ReflectiveOperationException | SecurityException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } } @@ -461,7 +447,7 @@ public static boolean isPropertySettable(String className, String propName, Clas } return false; - } catch (Exception ex) { + } catch (ClassNotFoundException | SecurityException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } finally { if (savedLoader != null) { @@ -508,14 +494,8 @@ public static void setPropertyValue(Object objValue, String propName, Object[] args = new Object[]{propValue}; method.invoke(objValue, args); - } catch (ClassNotFoundException cnfe) { - throw new WebServiceReflectionException("ClassNotFoundException", cnfe); - } catch (NoSuchMethodException nsme) { - throw new WebServiceReflectionException("NoSuchMethodException", nsme); - } catch (IllegalAccessException iae) { - throw new WebServiceReflectionException("IllegalAccessException", iae); - } catch (InvocationTargetException ite) { - throw new WebServiceReflectionException("InvocationTargetException", ite); + } catch (ReflectiveOperationException ex) { + throw new WebServiceReflectionException(ex.getClass().getName(), ex); } } finally { @@ -555,7 +535,7 @@ public static Object getPropertyValue(Object obj, String propertyName, } return method.invoke(obj, new Object[0]); - } catch (Exception ex) { + } catch (ReflectiveOperationException ex) { throw new WebServiceReflectionException(ex.getClass().getName(), ex); } } finally { @@ -654,7 +634,7 @@ public static Object callMethodWithParams( Object serviceObject; if (isRPCEncoded) { - serviceObject = serviceClass.newInstance(); + serviceObject = serviceClass.getDeclaredConstructor().newInstance(); } else { Constructor constructor = serviceClass.getConstructor(java.net.URL.class, javax.xml.namespace.QName.class); serviceObject = constructor.newInstance(jarWsdlUrl, name); @@ -665,19 +645,10 @@ public static Object callMethodWithParams( classInstance = getPort.invoke(serviceObject); clazz = classInstance.getClass(); - } catch (InstantiationException ia) { - throw new WebServiceReflectionException("InstantiationExceptoin", ia); - } catch (IllegalAccessException iae) { - throw new WebServiceReflectionException("IllegalAccessException", iae); - } catch (NoSuchMethodException nsme) { - throw new WebServiceReflectionException("NoSuchMethodException", nsme); - } catch (InvocationTargetException ite) { - throw new WebServiceReflectionException("InvocationTargetException", ite); - } catch (IOException ioe) { - throw new WebServiceReflectionException("IOException", ioe); + } catch (ReflectiveOperationException | IOException ex) { + throw new WebServiceReflectionException(ex.getClass().getName(), ex); } - Method method = null; Object[] paramValues = inParamList.toArray(); /** @@ -734,14 +705,8 @@ public static Object callMethodWithParams( Object returnObject = null; try { returnObject = method.invoke(classInstance, paramValues); - } catch (InvocationTargetException ite) { - throw new WebServiceReflectionException("InvocationTargetException", ite); - } catch (IllegalArgumentException ia) { - throw new WebServiceReflectionException("IllegalArgumentException", ia); - } catch (IllegalAccessException iae) { - throw new WebServiceReflectionException("IllegalAccessException", iae); - } catch (Exception e) { - throw new WebServiceReflectionException("Exception", e); + } catch (ReflectiveOperationException ex) { + throw new WebServiceReflectionException(ex.getClass().getName(), ex); } return returnObject; diff --git a/extide/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java b/extide/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java index d8f972b9bf56..4f0b4d085b53 100644 --- a/extide/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java +++ b/extide/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java @@ -120,7 +120,7 @@ public boolean toBoolean(String val) { public String[] getEnumeratedValues(Class c) { if (EnumeratedAttribute.class.isAssignableFrom(c)) { try { - return ((EnumeratedAttribute)c.newInstance()).getValues(); + return ((EnumeratedAttribute)c.getDeclaredConstructor().newInstance()).getValues(); } catch (Exception e) { AntModule.err.notify(ErrorManager.INFORMATIONAL, e); } diff --git a/extide/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/AntBridge.java b/extide/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/AntBridge.java index 935700aef957..9b0459ccfd96 100644 --- a/extide/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/AntBridge.java +++ b/extide/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/AntBridge.java @@ -307,7 +307,7 @@ private static AntInstance createAntInstance() { } } // in classpath mode, these checks do not apply Map cDCLs = createCustomDefClassLoaders(main); - return new AntInstance(classPathToString(mainClassPath), main, bridgeLoader, impl.newInstance(), createCustomDefs(cDCLs), cDCLs); + return new AntInstance(classPathToString(mainClassPath), main, bridgeLoader, impl.getDeclaredConstructor().newInstance(), createCustomDefs(cDCLs), cDCLs); } catch (Exception e) { return fallback(e); } catch (LinkageError e) { diff --git a/harness/jellytools.platform/src/org/netbeans/jellytools/actions/Action.java b/harness/jellytools.platform/src/org/netbeans/jellytools/actions/Action.java index 8aa364c31cd1..3838a781e4c7 100644 --- a/harness/jellytools.platform/src/org/netbeans/jellytools/actions/Action.java +++ b/harness/jellytools.platform/src/org/netbeans/jellytools/actions/Action.java @@ -782,14 +782,14 @@ public void run() { } else if (javax.swing.Action.class.isAssignableFrom(systemActionClass)) { // action implements javax.swing.Action try { - ((javax.swing.Action) systemActionClass.newInstance()).actionPerformed( + ((javax.swing.Action) systemActionClass.getDeclaredConstructor().newInstance()).actionPerformed( new ActionEvent(new Container(), 0, null)); } catch (Exception e) { throw new JemmyException("Exception when trying to create instance of action \"" + systemActionClass.getName() + "\".", e); } } else if (ActionListener.class.isAssignableFrom(systemActionClass)) { try { - ((ActionListener) systemActionClass.newInstance()).actionPerformed( + ((ActionListener) systemActionClass.getDeclaredConstructor().newInstance()).actionPerformed( new ActionEvent(new Container(), 0, null)); } catch (Exception e) { throw new JemmyException("Exception when trying to create instance of action \"" + systemActionClass.getName() + "\".", e); diff --git a/harness/jellytools.platform/src/org/netbeans/jellytools/actions/ActionNoBlock.java b/harness/jellytools.platform/src/org/netbeans/jellytools/actions/ActionNoBlock.java index b4720f7e9a5b..f401b6778156 100644 --- a/harness/jellytools.platform/src/org/netbeans/jellytools/actions/ActionNoBlock.java +++ b/harness/jellytools.platform/src/org/netbeans/jellytools/actions/ActionNoBlock.java @@ -313,7 +313,7 @@ public void run() { } else { // action implements javax.swing.Action try { - ((javax.swing.Action) systemActionClass.newInstance()).actionPerformed( + ((javax.swing.Action) systemActionClass.getDeclaredConstructor().newInstance()).actionPerformed( new ActionEvent(new Container(), 0, null)); } catch (Exception e) { throw new JemmyException("Exception when trying to create instance of action \"" + systemActionClass.getName() + "\".", e); diff --git a/harness/nbjunit/src/org/netbeans/junit/Manager.java b/harness/nbjunit/src/org/netbeans/junit/Manager.java index a7bc291fd2e5..f401cac8fe35 100644 --- a/harness/nbjunit/src/org/netbeans/junit/Manager.java +++ b/harness/nbjunit/src/org/netbeans/junit/Manager.java @@ -140,7 +140,7 @@ protected static Diff instantiateDiffImpl(String diffImplName) { // instantiate the diff class clazz = Class.forName(diffImplName); - diffImpl = clazz.newInstance(); + diffImpl = clazz.getDeclaredConstructor().newInstance(); if (diffImpl instanceof Diff) { impl = (Diff) diffImpl; diff --git a/harness/nbjunit/src/org/netbeans/junit/NbModuleSuite.java b/harness/nbjunit/src/org/netbeans/junit/NbModuleSuite.java index 3aee9ed044d4..a4a80ef5d6b2 100644 --- a/harness/nbjunit/src/org/netbeans/junit/NbModuleSuite.java +++ b/harness/nbjunit/src/org/netbeans/junit/NbModuleSuite.java @@ -929,7 +929,7 @@ private void runInRuntimeContainer(TestResult result) throws Exception { }else{ Class sndClazz = testLoader.loadClass(item.clazz.getName()).asSubclass(Test.class); - toRun.addTest(sndClazz.newInstance()); + toRun.addTest(sndClazz.getDeclaredConstructor().newInstance()); } } diff --git a/ide/api.debugger/src/org/netbeans/api/debugger/Properties.java b/ide/api.debugger/src/org/netbeans/api/debugger/Properties.java index 3f5fc8f7bd40..8a9fcf794d71 100644 --- a/ide/api.debugger/src/org/netbeans/api/debugger/Properties.java +++ b/ide/api.debugger/src/org/netbeans/api/debugger/Properties.java @@ -1272,14 +1272,8 @@ public Collection getCollection (String propertyName, Collection defaultValue) { } Collection c; try { - c = (Collection) Class.forName (typeID.substring (2)).newInstance (); - } catch (ClassNotFoundException ex) { - LOG.log(Level.WARNING, ex.getLocalizedMessage(), ex); - return defaultValue; - } catch (InstantiationException ex) { - LOG.log(Level.WARNING, ex.getLocalizedMessage(), ex); - return defaultValue; - } catch (IllegalAccessException ex) { + c = (Collection) Class.forName(typeID.substring(2)).getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage(), ex); return defaultValue; } @@ -1338,14 +1332,8 @@ public Map getMap (String propertyName, Map defaultValue) { } Map m; try { - m = (Map) Class.forName (typeID.substring (2)).newInstance (); - } catch (ClassNotFoundException ex) { - LOG.log(Level.WARNING, ex.getLocalizedMessage(), ex); - return defaultValue; - } catch (InstantiationException ex) { - LOG.log(Level.WARNING, ex.getLocalizedMessage(), ex); - return defaultValue; - } catch (IllegalAccessException ex) { + m = (Map) Class.forName(typeID.substring(2)).getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage(), ex); return defaultValue; } diff --git a/ide/api.debugger/src/org/netbeans/spi/debugger/ContextAwareSupport.java b/ide/api.debugger/src/org/netbeans/spi/debugger/ContextAwareSupport.java index f14f7d2fc75b..90f233e7d86f 100644 --- a/ide/api.debugger/src/org/netbeans/spi/debugger/ContextAwareSupport.java +++ b/ide/api.debugger/src/org/netbeans/spi/debugger/ContextAwareSupport.java @@ -111,7 +111,7 @@ public static Object createInstance(String service, ContextProvider context) { } } if (o == null) - o = cls.newInstance (); + o = cls.getDeclaredConstructor().newInstance(); if (Logger.getLogger(ContextAwareSupport.class.getName()).isLoggable(Level.FINE)) { Logger.getLogger(ContextAwareSupport.class.getName()).fine("instance "+o+" created."); } @@ -121,7 +121,7 @@ public static Object createInstance(String service, ContextProvider context) { Exceptions.attachMessage( e, "The service "+service+" not found.")); - } catch (InstantiationException e) { + } catch (InstantiationException | NoSuchMethodException e) { Exceptions.printStackTrace( Exceptions.attachMessage( e, diff --git a/ide/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/ui/util/DbUtil.java b/ide/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/ui/util/DbUtil.java index d7e2959dc621..04630646090b 100644 --- a/ide/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/ui/util/DbUtil.java +++ b/ide/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/ui/util/DbUtil.java @@ -55,7 +55,7 @@ public static Connection createConnection(Properties p,File[] f) throws Exceptio URL[] driverURLs=(URL[])list.toArray(new URL[0]); URLClassLoader l = new URLClassLoader(driverURLs); Class c = Class.forName(driver_name, true, l); - Driver driver=(Driver)c.newInstance(); + Driver driver=(Driver)c.getDeclaredConstructor().newInstance(); Connection con=driver.connect(url,p); return con; } diff --git a/ide/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/spi/DBConnectionProviderImpl.java b/ide/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/spi/DBConnectionProviderImpl.java index 210f3ee83124..cf7701c2627c 100644 --- a/ide/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/spi/DBConnectionProviderImpl.java +++ b/ide/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/spi/DBConnectionProviderImpl.java @@ -89,25 +89,17 @@ public Connection getConnection(DatabaseConnection dbConn) { TestCaseContext context = DbUtil.getContext(); File[] jars = context.getJars(); - ArrayList list = new java.util.ArrayList(); + ArrayList list = new ArrayList<>(); for (int i = 0; i < jars.length; i++) { list.add(jars[i].toURI().toURL()); } URL[] driverURLs = list.toArray(new URL[0]); URLClassLoader l = new URLClassLoader(driverURLs); Class c = Class.forName(driver, true, l); - Driver drv = (Driver) c.newInstance(); + Driver drv = (Driver) c.getDeclaredConstructor().newInstance(); Connection con = drv.connect(url, prop); return con; - } catch (SQLException ex) { - Exceptions.printStackTrace(ex); - } catch (InstantiationException ex) { - Exceptions.printStackTrace(ex); - } catch (IllegalAccessException ex) { - Exceptions.printStackTrace(ex); - } catch (ClassNotFoundException ex) { - Exceptions.printStackTrace(ex); - } catch (MalformedURLException ex) { + } catch (ReflectiveOperationException | SQLException | MalformedURLException ex) { Exceptions.printStackTrace(ex); } return null; diff --git a/ide/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/util/DbUtil.java b/ide/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/util/DbUtil.java index 638db47b9106..c20c69933620 100644 --- a/ide/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/util/DbUtil.java +++ b/ide/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/util/DbUtil.java @@ -292,7 +292,7 @@ private static Connection getConnection(JDBCDriver drv, String driverName, Strin // get the driver jar files and load them manually URL[] urls = drv.getURLs(); ClassLoader cl = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); - newDriverClass = (Driver) cl.loadClass(driverName).newInstance(); + newDriverClass = (Driver) cl.loadClass(driverName).getDeclaredConstructor().newInstance(); Properties prop = new Properties(); prop.setProperty("user", username); prop.setProperty("password", password); diff --git a/ide/db.mysql/src/org/netbeans/modules/db/mysql/util/DatabaseUtils.java b/ide/db.mysql/src/org/netbeans/modules/db/mysql/util/DatabaseUtils.java index f3928d01e015..d73733ad9db8 100644 --- a/ide/db.mysql/src/org/netbeans/modules/db/mysql/util/DatabaseUtils.java +++ b/ide/db.mysql/src/org/netbeans/modules/db/mysql/util/DatabaseUtils.java @@ -129,7 +129,7 @@ public static Driver getDriver() throws DatabaseException { try { ClassLoader driverLoader = new DriverClassLoader(jdbcDriver); driver = (Driver)Class.forName(jdbcDriver.getClassName(), - true, driverLoader).newInstance(); + true, driverLoader).getDeclaredConstructor().newInstance(); } catch ( Exception e ) { DatabaseException dbe = new DatabaseException( Utils.getMessage( diff --git a/ide/db/libsrc/org/netbeans/lib/ddl/impl/CreateProcedure.java b/ide/db/libsrc/org/netbeans/lib/ddl/impl/CreateProcedure.java index d304c74c9a9e..3be56c511d63 100644 --- a/ide/db/libsrc/org/netbeans/lib/ddl/impl/CreateProcedure.java +++ b/ide/db/libsrc/org/netbeans/lib/ddl/impl/CreateProcedure.java @@ -118,7 +118,7 @@ public Argument createArgument(String name, int type, int datatype) new String[] {tname})); Class typeclass = Class.forName((String)typemap.get("Class")); // NOI18N String format = (String)typemap.get("Format"); // NOI18N - ProcedureArgument arg = (ProcedureArgument)typeclass.newInstance(); + ProcedureArgument arg = (ProcedureArgument)typeclass.getDeclaredConstructor().newInstance(); arg.setName(name); arg.setType(type); arg.setDataType(datatype); diff --git a/ide/db/libsrc/org/netbeans/lib/ddl/impl/CreateTrigger.java b/ide/db/libsrc/org/netbeans/lib/ddl/impl/CreateTrigger.java index 724810d569a5..a529fcc695ff 100644 --- a/ide/db/libsrc/org/netbeans/lib/ddl/impl/CreateTrigger.java +++ b/ide/db/libsrc/org/netbeans/lib/ddl/impl/CreateTrigger.java @@ -163,7 +163,7 @@ public TriggerEvent createTriggerEvent(int when, String columnname) new String[] {tname})); Class typeclass = Class.forName((String)typemap.get("Class")); // NOI18N String format = (String)typemap.get("Format"); // NOI18N - TriggerEvent evt = (TriggerEvent)typeclass.newInstance(); + TriggerEvent evt = (TriggerEvent)typeclass.getDeclaredConstructor().newInstance(); Map temap = (Map)props.get("TriggerEventMap"); // NOI18N evt.setName(TriggerEvent.getName(when)); evt.setColumn(columnname); diff --git a/ide/db/src/org/netbeans/modules/db/explorer/DbDriverManager.java b/ide/db/src/org/netbeans/modules/db/explorer/DbDriverManager.java index d70c1a9440b6..a361378f6119 100644 --- a/ide/db/src/org/netbeans/modules/db/explorer/DbDriverManager.java +++ b/ide/db/src/org/netbeans/modules/db/explorer/DbDriverManager.java @@ -202,7 +202,7 @@ public Driver getDriver(JDBCDriver jdbcDriver) throws SQLException { ClassLoader l = getClassLoader(jdbcDriver); Object driver; try { - driver = Class.forName(jdbcDriver.getClassName(), true, l).newInstance(); + driver = Class.forName(jdbcDriver.getClassName(), true, l).getDeclaredConstructor().newInstance(); } catch (Exception e) { SQLException sqlex = createDriverNotFoundException(); sqlex.initCause(e); diff --git a/ide/db/src/org/netbeans/modules/db/explorer/node/NodePropertySupport.java b/ide/db/src/org/netbeans/modules/db/explorer/node/NodePropertySupport.java index 1c916e01a0bb..a59e6368dbb1 100644 --- a/ide/db/src/org/netbeans/modules/db/explorer/node/NodePropertySupport.java +++ b/ide/db/src/org/netbeans/modules/db/explorer/node/NodePropertySupport.java @@ -73,15 +73,13 @@ public PropertyEditor getPropertyEditor() { result = (PropertyEditor) potentialEditor; } else if (potentialEditor instanceof Class) { try { - potentialEditor = ((Class) potentialEditor).newInstance(); + potentialEditor = ((Class) potentialEditor).getDeclaredConstructor().newInstance(); if (!(potentialEditor instanceof PropertyEditor)) { throw new IllegalArgumentException( "Editor class does not derive from property editor"); //NOI18N } return (PropertyEditor) potentialEditor; - } catch (InstantiationException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { + } catch (ReflectiveOperationException ex) { throw new RuntimeException(ex); } } diff --git a/ide/db/test/unit/src/org/netbeans/modules/db/test/DBTestBase.java b/ide/db/test/unit/src/org/netbeans/modules/db/test/DBTestBase.java index bc57c8a72992..567fae67c240 100644 --- a/ide/db/test/unit/src/org/netbeans/modules/db/test/DBTestBase.java +++ b/ide/db/test/unit/src/org/netbeans/modules/db/test/DBTestBase.java @@ -30,10 +30,7 @@ import java.sql.SQLException; import java.util.Collection; import java.util.Properties; -import java.util.logging.Filter; -import java.util.logging.Handler; import java.util.logging.Level; -import java.util.logging.LogRecord; import java.util.logging.Logger; import org.netbeans.api.db.explorer.ConnectionManager; import org.netbeans.api.db.explorer.DatabaseConnection; @@ -697,7 +694,7 @@ private void createDBProvider() { private Driver getDriver() throws Exception { if (driver == null) { URLClassLoader driverLoader = new URLClassLoader(new URL[]{new URL(driverJar)}); - driver = (Driver)driverLoader.loadClass(driverClassName).newInstance(); + driver = (Driver)driverLoader.loadClass(driverClassName).getDeclaredConstructor().newInstance(); } return driver; diff --git a/ide/derby/src/org/netbeans/modules/derby/DerbyDatabasesImpl.java b/ide/derby/src/org/netbeans/modules/derby/DerbyDatabasesImpl.java index 2ffdc13fc8cc..a06ccf96f7e5 100644 --- a/ide/derby/src/org/netbeans/modules/derby/DerbyDatabasesImpl.java +++ b/ide/derby/src/org/netbeans/modules/derby/DerbyDatabasesImpl.java @@ -552,14 +552,8 @@ private Driver loadDerbyNetDriver() throws DatabaseException, IllegalStateExcep URL[] driverURLs = new URL[] { derbyClient.toURI().toURL() }; // NOI18N DbURLClassLoader l = new DbURLClassLoader(driverURLs); Class c = Class.forName(DerbyOptions.DRIVER_CLASS_NET, true, l); - return (Driver)c.newInstance(); - } catch (MalformedURLException e) { - exception = e; - } catch (IllegalAccessException e) { - exception = e; - } catch (ClassNotFoundException e) { - exception = e; - } catch (InstantiationException e) { + return (Driver)c.getDeclaredConstructor().newInstance(); + } catch (MalformedURLException | ReflectiveOperationException e) { exception = e; } if (exception != null) { diff --git a/ide/derby/test/qa-functional/src/org/netbeans/test/db/util/DbUtil.java b/ide/derby/test/qa-functional/src/org/netbeans/test/db/util/DbUtil.java index 35bbaf4da026..d63a16fdc5d8 100644 --- a/ide/derby/test/qa-functional/src/org/netbeans/test/db/util/DbUtil.java +++ b/ide/derby/test/qa-functional/src/org/netbeans/test/db/util/DbUtil.java @@ -20,6 +20,7 @@ package org.netbeans.test.db.util; import java.io.File; +import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; import java.sql.Connection; @@ -42,10 +43,10 @@ public static Connection createDerbyConnection(String dbURL) { File clientJar = new File(location, "lib/derbyclient.jar"); Connection con = null; try { - System.out.println("> Creating Derby connection using: "+clientJar.toURL()); - URL[] driverURLs = new URL[]{clientJar.toURL()}; + System.out.println("> Creating Derby connection using: "+clientJar.toURI().toURL()); + URL[] driverURLs = new URL[]{clientJar.toURI().toURL()}; DbURLClassLoader loader = new DbURLClassLoader(driverURLs); - Driver driver = (Driver) Class.forName(DRIVER_CLASS_NAME, true, loader).newInstance(); + Driver driver = (Driver) Class.forName(DRIVER_CLASS_NAME, true, loader).getDeclaredConstructor().newInstance(); con = driver.connect(dbURL, null); } catch (MalformedURLException ex) { Exceptions.attachMessage(ex, "Cannot convert to URL: "+clientJar); @@ -53,7 +54,7 @@ public static Connection createDerbyConnection(String dbURL) { } catch (SQLException ex) { Exceptions.attachMessage(ex, "Cannot conect to: "+dbURL); Exceptions.printStackTrace(ex); - } catch (InstantiationException ex) { + } catch (InstantiationException | NoSuchMethodException | InvocationTargetException ex) { Exceptions.attachMessage(ex, "Cannot instantiate: "+DRIVER_CLASS_NAME+" from: "+clientJar); Exceptions.printStackTrace(ex); } catch (IllegalAccessException ex) { diff --git a/ide/editor.bracesmatching/src/org/netbeans/modules/editor/bracesmatching/BraceToolTip.java b/ide/editor.bracesmatching/src/org/netbeans/modules/editor/bracesmatching/BraceToolTip.java index 951734c2e08d..d48e4e647d00 100644 --- a/ide/editor.bracesmatching/src/org/netbeans/modules/editor/bracesmatching/BraceToolTip.java +++ b/ide/editor.bracesmatching/src/org/netbeans/modules/editor/bracesmatching/BraceToolTip.java @@ -70,7 +70,7 @@ private void addGlyphGutter(JTextComponent jtx) { try { clazz = Class.forName("org.netbeans.editor.GlyphGutter", true, cls); // NOI18N // get the factory instance - Object o = clazz.newInstance(); + Object o = clazz.getDeclaredConstructor().newInstance(); Method m = clazz.getDeclaredMethod("createSideBar", JTextComponent.class); // NOI18N gutter = (JComponent)m.invoke(o, jtx); } catch (IllegalArgumentException ex) { diff --git a/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/FoldToolTip.java b/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/FoldToolTip.java index fee39f733b7d..e4d4ee04e233 100644 --- a/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/FoldToolTip.java +++ b/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/FoldToolTip.java @@ -92,7 +92,7 @@ private void addGlyphGutter(JTextComponent jtx) { clazz = Class.forName("org.netbeans.editor.GlyphGutter", true, cls); // NOI18N editorUiClass = Class.forName("org.netbeans.editor.EditorUI", true, cls); // NOI18N // get the factory instance - Object o = clazz.newInstance(); + Object o = clazz.getDeclaredConstructor().newInstance(); Method m = clazz.getDeclaredMethod("createSideBar", JTextComponent.class); // NOI18N gutter = (JComponent)m.invoke(o, jtx); } catch (IllegalArgumentException ex) { diff --git a/ide/editor.lib/src/org/netbeans/editor/BaseKit.java b/ide/editor.lib/src/org/netbeans/editor/BaseKit.java index 80814a961de1..bfd14e37bd2d 100644 --- a/ide/editor.lib/src/org/netbeans/editor/BaseKit.java +++ b/ide/editor.lib/src/org/netbeans/editor/BaseKit.java @@ -34,7 +34,6 @@ import java.util.Iterator; import java.util.List; import java.util.ArrayList; -import java.util.LinkedList; import java.util.prefs.PreferenceChangeEvent; import javax.swing.Action; import javax.swing.InputMap; @@ -73,10 +72,6 @@ import javax.swing.text.EditorKit; import javax.swing.text.Position; import javax.swing.text.View; -import javax.swing.undo.AbstractUndoableEdit; -import javax.swing.undo.CannotRedoException; -import javax.swing.undo.CannotUndoException; -import javax.swing.undo.UndoableEdit; import org.netbeans.api.editor.caret.CaretInfo; import org.netbeans.api.editor.EditorActionRegistration; import org.netbeans.api.editor.EditorActionRegistrations; @@ -102,7 +97,6 @@ import org.netbeans.spi.editor.caret.CaretMoveHandler; import org.netbeans.lib.editor.util.swing.PositionRegion; import org.netbeans.modules.editor.lib.SettingsConversions; -import org.netbeans.modules.editor.lib2.CaretUndo; import org.netbeans.modules.editor.lib2.RectangularSelectionCaretAccessor; import org.netbeans.modules.editor.lib2.RectangularSelectionUtils; import org.netbeans.modules.editor.lib2.actions.KeyBindingsUpdater; @@ -116,7 +110,6 @@ import org.openide.util.LookupEvent; import org.openide.util.LookupListener; import org.openide.util.NbBundle; -import org.openide.util.Pair; import org.openide.util.WeakListeners; import org.openide.util.WeakSet; @@ -469,14 +462,13 @@ public static BaseKit getKit(Class kitClass) { BaseKit kit = (BaseKit)kits.get(classToTry); if (kit == null) { try { - kit = (BaseKit)classToTry.newInstance(); + kit = (BaseKit)classToTry.getDeclaredConstructor().newInstance(); kits.put(classToTry, kit); return kit; - } catch (IllegalAccessException e) { - LOG.log(Level.WARNING, "Can't instantiate editor kit from: " + classToTry, e); //NOI18N - } catch (InstantiationException e) { + } catch (ReflectiveOperationException e) { LOG.log(Level.WARNING, "Can't instantiate editor kit from: " + classToTry, e); //NOI18N } + //NOI18N if (classToTry != BaseKit.class) { classToTry = BaseKit.class; diff --git a/ide/editor.lib/src/org/netbeans/editor/BaseTextUI.java b/ide/editor.lib/src/org/netbeans/editor/BaseTextUI.java index 4be9b3f6c3f0..82b8e4a8ab5a 100644 --- a/ide/editor.lib/src/org/netbeans/editor/BaseTextUI.java +++ b/ide/editor.lib/src/org/netbeans/editor/BaseTextUI.java @@ -28,8 +28,6 @@ import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.prefs.PreferenceChangeEvent; -import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; import javax.swing.text.*; import javax.swing.event.DocumentListener; @@ -47,7 +45,6 @@ import org.netbeans.modules.editor.lib2.EditorApiPackageAccessor; import org.netbeans.editor.view.spi.LockView; import org.netbeans.lib.editor.view.GapDocumentView; -import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults; import org.netbeans.modules.editor.lib2.EditorPreferencesKeys; import org.netbeans.modules.editor.lib.SettingsConversions; import org.netbeans.modules.editor.lib.drawing.DrawEngineDocView; @@ -55,7 +52,6 @@ import org.netbeans.modules.editor.lib2.view.LockedViewHierarchy; import org.netbeans.modules.editor.lib2.view.ViewHierarchy; import org.netbeans.spi.lexer.MutableTextInput; -import org.openide.util.WeakListeners; /** * Text UI implementation @@ -604,6 +600,7 @@ static class UIWatcher implements PropertyChangeListener { this.uiClass = uiClass; } + @Override public void propertyChange(PropertyChangeEvent evt) { Object newValue = evt.getNewValue(); if ("UI".equals(evt.getPropertyName())) { @@ -617,7 +614,7 @@ public void propertyChange(PropertyChangeEvent evt) { if (kit instanceof BaseKit) { // BaseKit but not BaseTextUI -> restore BaseTextUI try { - BaseTextUI newUI = (BaseTextUI) uiClass.newInstance(); + BaseTextUI newUI = (BaseTextUI) uiClass.getDeclaredConstructor().newInstance(); c.setUI(newUI); if (evt.getOldValue() instanceof BaseTextUI) { BaseTextUI oldUI = (BaseTextUI) evt.getOldValue(); @@ -633,9 +630,7 @@ public void propertyChange(PropertyChangeEvent evt) { } } - } catch (InstantiationException e) { - } catch (IllegalAccessException e) { - } + } catch (ReflectiveOperationException ignored) {} } } } diff --git a/ide/editor.lib/src/org/netbeans/editor/ext/ExtKit.java b/ide/editor.lib/src/org/netbeans/editor/ext/ExtKit.java index 5ebf4b0e320e..d72acbb00baf 100644 --- a/ide/editor.lib/src/org/netbeans/editor/ext/ExtKit.java +++ b/ide/editor.lib/src/org/netbeans/editor/ext/ExtKit.java @@ -176,7 +176,7 @@ public ExtKit() { try { ClassLoader loader = Lookup.getDefault().lookup(ClassLoader.class); Class extEditorUIClass = loader.loadClass("org.netbeans.editor.ext.ExtEditorUI"); //NOI18N - return (EditorUI) extEditorUIClass.newInstance(); + return (EditorUI) extEditorUIClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { noExtEditorUIClass = true; } diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/options/ui/FmtOptions.java b/ide/html.editor/src/org/netbeans/modules/html/editor/options/ui/FmtOptions.java index 41d15bd830e1..9fc60a1319c8 100644 --- a/ide/html.editor/src/org/netbeans/modules/html/editor/options/ui/FmtOptions.java +++ b/ide/html.editor/src/org/netbeans/modules/html/editor/options/ui/FmtOptions.java @@ -18,16 +18,12 @@ */ package org.netbeans.modules.html.editor.options.ui; -import java.awt.Component; -import java.awt.Container; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Level; @@ -35,14 +31,9 @@ import java.util.prefs.AbstractPreferences; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JEditorPane; import javax.swing.JPanel; -import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.BadLocationException; @@ -625,8 +616,8 @@ public Factory(String mimeType, String id, Class panelClass, S @Override public PreferencesCustomizer create(Preferences preferences) { try { - return new CategorySupport(mimeType, preferences, id, panelClass.newInstance(), previewText, forcedOptions); - } catch (InstantiationException | IllegalAccessException e) { + return new CategorySupport(mimeType, preferences, id, panelClass.getDeclaredConstructor().newInstance(), previewText, forcedOptions); + } catch (ReflectiveOperationException e) { LOGGER.log(Level.WARNING, "Exception during creating formatter customiezer", e); return null; } diff --git a/ide/ide.kit/test/qa-functional/src/org/netbeans/test/ide/CountingSecurityManager.java b/ide/ide.kit/test/qa-functional/src/org/netbeans/test/ide/CountingSecurityManager.java index 770c2081a322..45b65e53bbb3 100755 --- a/ide/ide.kit/test/qa-functional/src/org/netbeans/test/ide/CountingSecurityManager.java +++ b/ide/ide.kit/test/qa-functional/src/org/netbeans/test/ide/CountingSecurityManager.java @@ -161,7 +161,7 @@ public void checkPermission(Permission p) { try { ClassLoader l = Thread.currentThread().getContextClassLoader(); Class manClass = Class.forName("org.netbeans.TopSecurityManager", false, l); - man = (SecurityManager) manClass.newInstance(); + man = (SecurityManager) manClass.getDeclaredConstructor().newInstance(); } catch (Exception ex) { throw new IllegalStateException(ex); } diff --git a/ide/parsing.indexing/test/unit/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater2Test.java b/ide/parsing.indexing/test/unit/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater2Test.java index 3a103b8d34ee..753b0acd141d 100644 --- a/ide/parsing.indexing/test/unit/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater2Test.java +++ b/ide/parsing.indexing/test/unit/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater2Test.java @@ -596,7 +596,7 @@ public T createIndexer() { return customIndexerInstance; } else { try { - return customIndexerClass.newInstance(); + return customIndexerClass.getDeclaredConstructor().newInstance(); } catch (Exception ex) { throw new IllegalStateException(ex); } @@ -652,7 +652,7 @@ public FixedParserFactory(T parserInstance) { return parserInstance; } else { try { - return parserClass.newInstance(); + return parserClass.getDeclaredConstructor().newInstance(); } catch (Exception ex) { throw new IllegalStateException(ex); } diff --git a/ide/project.libraries/test/unit/src/org/netbeans/modules/project/libraries/LibrariesTestUtil.java b/ide/project.libraries/test/unit/src/org/netbeans/modules/project/libraries/LibrariesTestUtil.java index 10bd49bda826..f5ead75a1769 100644 --- a/ide/project.libraries/test/unit/src/org/netbeans/modules/project/libraries/LibrariesTestUtil.java +++ b/ide/project.libraries/test/unit/src/org/netbeans/modules/project/libraries/LibrariesTestUtil.java @@ -393,7 +393,7 @@ public static void assertLibEquals (LibraryImplementation[] libs, String[] names public static void registerLibraryTypeProvider (final Class provider) throws Exception { final MockLibraryTypeRegistry mr = Lookup.getDefault().lookup(MockLibraryTypeRegistry.class); if (mr != null) { - mr.register(provider.newInstance()); + mr.register(provider.getDeclaredConstructor().newInstance()); return; } FileObject root = FileUtil.getConfigRoot(); diff --git a/ide/schema2beans/src/org/netbeans/modules/schema2beans/BaseBean.java b/ide/schema2beans/src/org/netbeans/modules/schema2beans/BaseBean.java index 7010ba0091c0..3ae0d84b4a58 100644 --- a/ide/schema2beans/src/org/netbeans/modules/schema2beans/BaseBean.java +++ b/ide/schema2beans/src/org/netbeans/modules/schema2beans/BaseBean.java @@ -1217,7 +1217,7 @@ public Object clone() { try { // FIXME this seriosly breaks the clone contract :( // Create a new instance of ourself - bean = (BaseBean)this.getClass().newInstance(); + bean = (BaseBean)this.getClass().getDeclaredConstructor().newInstance(); } catch(Exception e) { TraceLogger.error(e); throw new Schema2BeansRuntimeException(Common. diff --git a/ide/schema2beans/src/org/netbeans/modules/schema2beans/BeanProp.java b/ide/schema2beans/src/org/netbeans/modules/schema2beans/BeanProp.java index 72b52dbf5300..45095a6d089e 100644 --- a/ide/schema2beans/src/org/netbeans/modules/schema2beans/BeanProp.java +++ b/ide/schema2beans/src/org/netbeans/modules/schema2beans/BeanProp.java @@ -1702,7 +1702,7 @@ BaseBean newBeanInstance() { c = this.propClass.getDeclaredConstructor(cc); } catch(NoSuchMethodException me) { - return (BaseBean)this.propClass.newInstance(); + return (BaseBean)this.propClass.getDeclaredConstructor().newInstance(); } // Do not initialize the default values diff --git a/ide/schema2beans/src/org/netbeans/modules/schema2beans/DOMBinding.java b/ide/schema2beans/src/org/netbeans/modules/schema2beans/DOMBinding.java index 6639a7acd328..31d862f16d16 100644 --- a/ide/schema2beans/src/org/netbeans/modules/schema2beans/DOMBinding.java +++ b/ide/schema2beans/src/org/netbeans/modules/schema2beans/DOMBinding.java @@ -386,7 +386,7 @@ Object getValue(BeanProp prop) { try { // If cls implements Wrapper, use it first if ((Wrapper.class).isAssignableFrom(cls)) { - Wrapper w = (Wrapper)cls.newInstance(); + Wrapper w = (Wrapper)cls.getDeclaredConstructor().newInstance(); w.setWrapperValue(ret); return w; } diff --git a/ide/selenium2.server/src/org/netbeans/modules/selenium2/server/Selenium2ServerSupport.java b/ide/selenium2.server/src/org/netbeans/modules/selenium2/server/Selenium2ServerSupport.java index a5db7eb14c88..c8a748ebad94 100644 --- a/ide/selenium2.server/src/org/netbeans/modules/selenium2/server/Selenium2ServerSupport.java +++ b/ide/selenium2.server/src/org/netbeans/modules/selenium2/server/Selenium2ServerSupport.java @@ -234,7 +234,7 @@ private static void initializeServer() throws Exception { Class remoteControlConfiguration = urlClassLoader.loadClass( "org.openqa.selenium.server.RemoteControlConfiguration"); //NOI18N - Object remoteControlConfigurationInstance = remoteControlConfiguration.newInstance(); + Object remoteControlConfigurationInstance = remoteControlConfiguration.getDeclaredConstructor().newInstance(); int port = getPrefs().getInt(PORT, PORT_DEFAULT); remoteControlConfiguration.getMethod("setPort", int.class).invoke( remoteControlConfigurationInstance, port); //NOI18N diff --git a/ide/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/actions/BreakpointCustomizeAction.java b/ide/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/actions/BreakpointCustomizeAction.java index 96bb52700ab8..33ce823dede2 100644 --- a/ide/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/actions/BreakpointCustomizeAction.java +++ b/ide/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/actions/BreakpointCustomizeAction.java @@ -166,7 +166,7 @@ private Customizer getCustomizer(Breakpoint b) { Class cc = getCustomizerClass(b); if (cc == null) return null; try { - Customizer c = (Customizer) cc.newInstance(); + Customizer c = (Customizer) cc.getDeclaredConstructor().newInstance(); c.setObject(b); return c; } catch (Exception ex) { diff --git a/ide/spi.palette/src/org/netbeans/modules/palette/ActiveEditorDropProvider.java b/ide/spi.palette/src/org/netbeans/modules/palette/ActiveEditorDropProvider.java index 7cde6e3e291f..f831a1b3cadb 100644 --- a/ide/spi.palette/src/org/netbeans/modules/palette/ActiveEditorDropProvider.java +++ b/ide/spi.palette/src/org/netbeans/modules/palette/ActiveEditorDropProvider.java @@ -67,7 +67,7 @@ private ActiveEditorDrop getActiveEditorDrop(String instanceName) { if (loader == null) loader = getClass ().getClassLoader (); Class instanceClass = loader.loadClass (instanceName); - drop = (ActiveEditorDrop)instanceClass.newInstance(); + drop = (ActiveEditorDrop)instanceClass.getDeclaredConstructor().newInstance(); } catch (Exception ex) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); diff --git a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessor.java b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessor.java index 35b31c099eb1..ca3014252020 100644 --- a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessor.java +++ b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessor.java @@ -261,7 +261,7 @@ private Iterable completeMimePath( l = CreateRegistrationProcessor.class.getClassLoader(); } try { - COMPLETIONS = (Processor)Class.forName(pathCompletions, true, l).newInstance(); + COMPLETIONS = (Processor)Class.forName(pathCompletions, true, l).getDeclaredConstructor().newInstance(); } catch (Exception ex) { Exceptions.printStackTrace(ex); // no completions, OK diff --git a/ide/xml.catalog.ui/src/org/netbeans/modules/xml/catalog/lib/Util.java b/ide/xml.catalog.ui/src/org/netbeans/modules/xml/catalog/lib/Util.java index b5866bf60a01..a19839906b47 100644 --- a/ide/xml.catalog.ui/src/org/netbeans/modules/xml/catalog/lib/Util.java +++ b/ide/xml.catalog.ui/src/org/netbeans/modules/xml/catalog/lib/Util.java @@ -57,14 +57,8 @@ public static Customizer getProviderCustomizer(Class clazz) { try { Class customizer = Introspector.getBeanInfo(clazz).getBeanDescriptor().getCustomizerClass(); - - return (Customizer) customizer.newInstance(); - - } catch (InstantiationException ex) { - return null; - } catch (IntrospectionException ex) { - return null; - } catch (IllegalAccessException ex) { + return (Customizer) customizer.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException | IntrospectionException ex) { return null; } } @@ -75,10 +69,8 @@ public static Customizer getProviderCustomizer(Class clazz) { */ public static Object createProvider(Class clazz) { try { - return clazz.newInstance(); - } catch (InstantiationException ex) { - return null; - } catch (IllegalAccessException ex) { + return clazz.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException ex) { return null; } } diff --git a/ide/xml.tax/src/org/netbeans/modules/xml/tax/beans/Lib.java b/ide/xml.tax/src/org/netbeans/modules/xml/tax/beans/Lib.java index 07447feb896d..ae1f2338335d 100644 --- a/ide/xml.tax/src/org/netbeans/modules/xml/tax/beans/Lib.java +++ b/ide/xml.tax/src/org/netbeans/modules/xml/tax/beans/Lib.java @@ -68,12 +68,8 @@ public static Component getCustomizer (Object object) { Object o; try { - o = clazz.newInstance (); - } catch (InstantiationException e) { - if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("Lib::getCustomizer: exception = " + e); // NOI18N - - return null; - } catch (IllegalAccessException e) { + o = clazz.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("Lib::getCustomizer: exception = " + e); // NOI18N return null; @@ -141,12 +137,8 @@ public static Component getCustomizer (Class classClass, Object property, String } Object peo; try { - peo = clazz.newInstance (); - } catch (InstantiationException e) { - if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("Lib::getCustomizer: exception = " + e); // NOI18N - - return null; - } catch (IllegalAccessException e) { + peo = clazz.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("Lib::getCustomizer: exception = " + e); // NOI18N return null; diff --git a/java/ant.debugger/test/unit/src/org/netbeans/modules/ant/debugger/StepTest.java b/java/ant.debugger/test/unit/src/org/netbeans/modules/ant/debugger/StepTest.java index 348b2d89c19a..f276275d8fb8 100644 --- a/java/ant.debugger/test/unit/src/org/netbeans/modules/ant/debugger/StepTest.java +++ b/java/ant.debugger/test/unit/src/org/netbeans/modules/ant/debugger/StepTest.java @@ -61,11 +61,11 @@ public void testStepOver () throws Exception { } public static final class Lkp extends ProxyLookup { - public Lkp() throws InstantiationException, IllegalAccessException, ClassNotFoundException { + public Lkp() throws ReflectiveOperationException { setLookups(new Lookup[] { Lookups.fixed(new Object[] { new IFL(), - Class.forName("org.netbeans.modules.masterfs.MasterURLMapper").newInstance(), + Class.forName("org.netbeans.modules.masterfs.MasterURLMapper").getDeclaredConstructor().newInstance(), new DebuggerAntLogger () }), }); diff --git a/java/dbschema/src/org/netbeans/modules/dbschema/migration/archiver/deserializer/XMLGraphDeserializer.java b/java/dbschema/src/org/netbeans/modules/dbschema/migration/archiver/deserializer/XMLGraphDeserializer.java index 909e9be0b147..183d67b6a8fa 100644 --- a/java/dbschema/src/org/netbeans/modules/dbschema/migration/archiver/deserializer/XMLGraphDeserializer.java +++ b/java/dbschema/src/org/netbeans/modules/dbschema/migration/archiver/deserializer/XMLGraphDeserializer.java @@ -23,6 +23,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; import org.xml.sax.*; @@ -588,7 +589,7 @@ public void readObjectHeader(java.lang.String name, org.xml.sax.AttributeList if (WrapperClassHelper.isWrapperClass(lClass)) lObj = new WrapperClassHelper(lClass, lIDName); else - lObj = lClass.newInstance(); + lObj = lClass.getDeclaredConstructor().newInstance(); } catch (IllegalAccessException e1) { @@ -598,7 +599,7 @@ public void readObjectHeader(java.lang.String name, org.xml.sax.AttributeList SAXException useError = new SAXException(message); throw useError; } - catch (InstantiationException e2) + catch (InstantiationException | NoSuchMethodException | InvocationTargetException e2) { lObj = NewInstanceHelper.newInstance(lClassName, this.topObject()); @@ -688,7 +689,7 @@ else if (name.equals("ARRAY")) try { Class lArrayTypeClass = this.findClass(lArrayType); - lArray = lArrayTypeClass.newInstance(); + lArray = lArrayTypeClass.getDeclaredConstructor().newInstance(); } catch (ClassNotFoundException e1) { @@ -708,7 +709,7 @@ else if (name.equals("ARRAY")) SAXException accessError = new SAXException(message); throw accessError; } - catch (InstantiationException e3) + catch (InstantiationException | NoSuchMethodException | InvocationTargetException e3) { e3.printStackTrace(); //java.lang.String message = new String("Instantiation exception whilst trying to init new instance of " + lArrayType); @@ -822,11 +823,11 @@ else if (name.equals("NULLVALUE")) // does not declare the field anymore => ignore. this.pushObject(new Object()); else - this.pushObject(lField.getType().newInstance()); + this.pushObject(lField.getType().getDeclaredConstructor().newInstance()); this.State = new Integer(this.XGD_NEED_END_NULLVALUE); } - catch (InstantiationException e1) + catch (InstantiationException | NoSuchMethodException | InvocationTargetException e1) { e1.printStackTrace(); //java.lang.String message = new String("Could not init instance of " + lField.getType().getName()); diff --git a/java/dbschema/test/unit/src/org/netbeans/modules/dbschema/ColumnElementTest.java b/java/dbschema/test/unit/src/org/netbeans/modules/dbschema/ColumnElementTest.java index a11c03f48329..0350e1631349 100644 --- a/java/dbschema/test/unit/src/org/netbeans/modules/dbschema/ColumnElementTest.java +++ b/java/dbschema/test/unit/src/org/netbeans/modules/dbschema/ColumnElementTest.java @@ -137,7 +137,7 @@ private Connection getConnection() throws Exception { private Driver getDriver() throws Exception { URLClassLoader driverLoader = new URLClassLoader(new URL[] {new URL(jarpath)}); - return (Driver)Class.forName(driverClassName, true, driverLoader).newInstance(); + return (Driver)Class.forName(driverClassName, true, driverLoader).getDeclaredConstructor().newInstance(); } @Override diff --git a/java/form/src/org/netbeans/modules/form/CreationFactory.java b/java/form/src/org/netbeans/modules/form/CreationFactory.java index 4ec3811fdd1a..581f923d9437 100644 --- a/java/form/src/org/netbeans/modules/form/CreationFactory.java +++ b/java/form/src/org/netbeans/modules/form/CreationFactory.java @@ -152,7 +152,7 @@ public static Object createDefaultInstance(final Class cls) UIManager.put("ClassLoader", newCl); // NOI18N Object instance = cd != null ? cd.createDefaultInstance() : - cls.newInstance(); + cls.getDeclaredConstructor().newInstance(); if (cl == cl2) { // The original classloader (i.e., cl) was in look and feel defaults. // It remains there, we just have to remove the value that @@ -173,7 +173,7 @@ public static Object createInstance(Class cls) CreationDescriptor cd = CreationFactory.getDescriptor(cls); instance = cd != null ? cd.createDefaultInstance() : - cls.newInstance(); + cls.getDeclaredConstructor().newInstance(); initAfterCreation(instance); return instance; diff --git a/java/form/src/org/netbeans/modules/form/FormLAF.java b/java/form/src/org/netbeans/modules/form/FormLAF.java index 3ba23cf5bc73..01fb75b8f2ba 100644 --- a/java/form/src/org/netbeans/modules/form/FormLAF.java +++ b/java/form/src/org/netbeans/modules/form/FormLAF.java @@ -75,7 +75,7 @@ public static PreviewInfo initPreviewLaf(Class lafClass, ClassLoader formClassLo !MetalLookAndFeel.class.equals(lafClass) && (lafToTheme.get(MetalLookAndFeel.class) == null)) { lafToTheme.put(MetalLookAndFeel.class, MetalLookAndFeel.getCurrentTheme()); } - LookAndFeel previewLookAndFeel = (LookAndFeel)lafClass.newInstance(); + LookAndFeel previewLookAndFeel = (LookAndFeel)lafClass.getDeclaredConstructor().newInstance(); if (previewLafIsMetal) { MetalTheme theme = lafToTheme.get(lafClass); if (theme == null) { @@ -203,7 +203,7 @@ private static void initialize() throws Exception { } LookAndFeel original = laf; try { - original = laf.getClass().newInstance(); + original = laf.getClass().getDeclaredConstructor().newInstance(); } catch (Exception ex) { Logger.getLogger(FormLAF.class.getName()).log(Level.INFO, ex.getMessage(), ex); } diff --git a/java/form/src/org/netbeans/modules/form/FormPropertyEditorManager.java b/java/form/src/org/netbeans/modules/form/FormPropertyEditorManager.java index b03d46c9b02b..e64802001a37 100644 --- a/java/form/src/org/netbeans/modules/form/FormPropertyEditorManager.java +++ b/java/form/src/org/netbeans/modules/form/FormPropertyEditorManager.java @@ -304,7 +304,7 @@ private static boolean isComponentType(Class type) { private static PropertyEditor createEditorInstance(Class cls) { try { - return (PropertyEditor) cls.newInstance(); + return (PropertyEditor) cls.getDeclaredConstructor().newInstance(); } catch (Exception ex) { log(ex, "Error instantiating property editor: "+cls.getName()); // NOI18N } catch (LinkageError ex) { diff --git a/java/form/src/org/netbeans/modules/form/GandalfPersistenceManager.java b/java/form/src/org/netbeans/modules/form/GandalfPersistenceManager.java index 3066104a716a..4c1b0d0b7988 100644 --- a/java/form/src/org/netbeans/modules/form/GandalfPersistenceManager.java +++ b/java/form/src/org/netbeans/modules/form/GandalfPersistenceManager.java @@ -4606,8 +4606,7 @@ private void saveAuxValues(Map auxValues, StringBuffer buf, Strin private PropertyEditor createPropertyEditor(Class editorClass, Class propertyType, FormProperty property) - throws InstantiationException, - IllegalAccessException + throws ReflectiveOperationException { PropertyEditor ed = null; if (editorClass.equals(RADConnectionPropertyEditor.class)) { @@ -4623,7 +4622,7 @@ private PropertyEditor createPropertyEditor(Class editorClass, ed = RADProperty.createDefaultEnumEditor(propertyType); } } else { - ed = (PropertyEditor) editorClass.newInstance(); + ed = (PropertyEditor) editorClass.getDeclaredConstructor().newInstance(); } if (property != null) @@ -5575,10 +5574,7 @@ private Object getPropertyEditorOrValue(org.w3c.dom.Node node) { try { prEd = createPropertyEditor(editorClass, propertyType, null); } - catch (Exception ex) { - t = ex; - } - catch (LinkageError ex) { + catch (Exception | LinkageError ex) { t = ex; } if (t != null) { diff --git a/java/form/src/org/netbeans/modules/form/PersistenceManager.java b/java/form/src/org/netbeans/modules/form/PersistenceManager.java index 923b54837d85..2d0c2012ecda 100644 --- a/java/form/src/org/netbeans/modules/form/PersistenceManager.java +++ b/java/form/src/org/netbeans/modules/form/PersistenceManager.java @@ -103,7 +103,7 @@ public static Iterator getManagers() { String pmClassName = iter.next(); try { PersistenceManager manager = (PersistenceManager) - classLoader.loadClass(pmClassName).newInstance(); + classLoader.loadClass(pmClassName).getDeclaredConstructor().newInstance(); getManagersList().add(manager); } catch (Exception ex1) { diff --git a/java/form/src/org/netbeans/modules/form/PersistenceObjectRegistry.java b/java/form/src/org/netbeans/modules/form/PersistenceObjectRegistry.java index f864dca37a7d..468f8cb7bc01 100644 --- a/java/form/src/org/netbeans/modules/form/PersistenceObjectRegistry.java +++ b/java/form/src/org/netbeans/modules/form/PersistenceObjectRegistry.java @@ -58,9 +58,9 @@ public static void registerAlias(Class clazz, String alias) { } public static Object createInstance(String classname, FileObject form) - throws InstantiationException, IllegalAccessException, ClassNotFoundException + throws ReflectiveOperationException { - return loadClass(classname, form).newInstance(); + return loadClass(classname, form).getDeclaredConstructor().newInstance(); } public static Class loadClass(String name, FileObject form) diff --git a/java/form/src/org/netbeans/modules/form/RADComponentNode.java b/java/form/src/org/netbeans/modules/form/RADComponentNode.java index c41984800dd5..b78c2dccf35d 100644 --- a/java/form/src/org/netbeans/modules/form/RADComponentNode.java +++ b/java/form/src/org/netbeans/modules/form/RADComponentNode.java @@ -449,13 +449,8 @@ protected Component createCustomizer() { Object customizerObject; try { - customizerObject = customizerClass.newInstance(); - } - catch (InstantiationException e) { - ErrorManager.getDefault().notify(ErrorManager.WARNING, e); - return null; - } - catch (IllegalAccessException e) { + customizerObject = customizerClass.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { ErrorManager.getDefault().notify(ErrorManager.WARNING, e); return null; } diff --git a/java/form/src/org/netbeans/modules/form/actions/TestAction.java b/java/form/src/org/netbeans/modules/form/actions/TestAction.java index 8fb9196fa2e2..fa72ceaa7cd3 100644 --- a/java/form/src/org/netbeans/modules/form/actions/TestAction.java +++ b/java/form/src/org/netbeans/modules/form/actions/TestAction.java @@ -330,7 +330,7 @@ public JPopupMenu getPopupMenu() { try { Class clazz = pitem.getComponentClass(); if ((clazz != null) && (LookAndFeel.class.isAssignableFrom(clazz))) { - LookAndFeel laf = (LookAndFeel)clazz.newInstance(); + LookAndFeel laf = (LookAndFeel)clazz.getDeclaredConstructor().newInstance(); supported = laf.isSupportedLookAndFeel(); if (supported && isSynthLAF && !lafName.equals(pitem.getComponentClassName()) && SynthLookAndFeel.class.isAssignableFrom(clazz)) { diff --git a/java/form/src/org/netbeans/modules/form/editors2/TableColumnModelEditor.java b/java/form/src/org/netbeans/modules/form/editors2/TableColumnModelEditor.java index 2553db5764fa..6e1f9370fd41 100644 --- a/java/form/src/org/netbeans/modules/form/editors2/TableColumnModelEditor.java +++ b/java/form/src/org/netbeans/modules/form/editors2/TableColumnModelEditor.java @@ -308,7 +308,7 @@ private void loadProperty(FormProperty property, Node node) { } else { Class propEdClass = PersistenceObjectRegistry.loadClass(propEdName, FormEditor.getFormDataObject(formModel).getFormFile()); - Object propEd = propEdClass.newInstance(); + Object propEd = propEdClass.getDeclaredConstructor().newInstance(); if (propEd instanceof XMLPropertyEditor) { xmlPropEd = (XMLPropertyEditor)propEd; if (propEd instanceof FormAwareEditor) { diff --git a/java/form/src/org/netbeans/modules/form/layoutsupport/AbstractLayoutSupport.java b/java/form/src/org/netbeans/modules/form/layoutsupport/AbstractLayoutSupport.java index b9a69f630b9f..744b57ca31b8 100644 --- a/java/form/src/org/netbeans/modules/form/layoutsupport/AbstractLayoutSupport.java +++ b/java/form/src/org/netbeans/modules/form/layoutsupport/AbstractLayoutSupport.java @@ -913,7 +913,7 @@ protected LayoutManager cloneLayoutInstance(Container container, */ protected AbstractLayoutSupport createLayoutSupportInstance() { try { - return (AbstractLayoutSupport) getClass().newInstance(); + return (AbstractLayoutSupport) getClass().getDeclaredConstructor().newInstance(); } catch (Exception ex) { // should not happen for AbstractLayoutSupport subclasses return null; diff --git a/java/form/src/org/netbeans/modules/form/layoutsupport/LayoutNode.java b/java/form/src/org/netbeans/modules/form/layoutsupport/LayoutNode.java index b9417e8969b0..31168b688480 100644 --- a/java/form/src/org/netbeans/modules/form/layoutsupport/LayoutNode.java +++ b/java/form/src/org/netbeans/modules/form/layoutsupport/LayoutNode.java @@ -118,13 +118,9 @@ protected Component createCustomizer() { // create bean customizer for layout manager Object customizerObject; try { - customizerObject = customizerClass.newInstance(); + customizerObject = customizerClass.getDeclaredConstructor().newInstance(); } - catch (InstantiationException e) { - ErrorManager.getDefault().notify(ErrorManager.WARNING, e); - return null; - } - catch (IllegalAccessException e) { + catch (ReflectiveOperationException e) { ErrorManager.getDefault().notify(ErrorManager.WARNING, e); return null; } diff --git a/java/form/src/org/netbeans/modules/form/layoutsupport/LayoutSupportRegistry.java b/java/form/src/org/netbeans/modules/form/layoutsupport/LayoutSupportRegistry.java index 2c4e5f5fd555..a4dbc55fc85e 100644 --- a/java/form/src/org/netbeans/modules/form/layoutsupport/LayoutSupportRegistry.java +++ b/java/form/src/org/netbeans/modules/form/layoutsupport/LayoutSupportRegistry.java @@ -97,22 +97,18 @@ public static void registerSupportForLayout( // creation methods public LayoutSupportDelegate createSupportForContainer(Class containerClass) - throws ClassNotFoundException, - InstantiationException, - IllegalAccessException + throws ReflectiveOperationException { String delegateClassName = getContainersMap().get(containerClass.getName()); if (delegateClassName == null) { return createLayoutSupportForSuperClass(getContainersMap(), containerClass); } else { - return (LayoutSupportDelegate) loadClass(delegateClassName).newInstance(); + return (LayoutSupportDelegate) loadClass(delegateClassName).getDeclaredConstructor().newInstance(); } } public LayoutSupportDelegate createSupportForLayout(Class layoutClass) - throws ClassNotFoundException, - InstantiationException, - IllegalAccessException + throws ReflectiveOperationException { String layoutClassName = layoutClass.getName(); String delegateClassName = getLayoutsMap().get(layoutClassName); @@ -125,7 +121,7 @@ public LayoutSupportDelegate createSupportForLayout(Class layoutClass) if (DEFAULT_SUPPORT.equals(delegateClassName)) { return new DefaultLayoutSupport(layoutClass); } else if (delegateClassName != null) { - return (LayoutSupportDelegate) loadClass(delegateClassName).newInstance(); + return (LayoutSupportDelegate) loadClass(delegateClassName).getDeclaredConstructor().newInstance(); } else { return null; } @@ -133,9 +129,9 @@ public LayoutSupportDelegate createSupportForLayout(Class layoutClass) public static LayoutSupportDelegate createSupportInstance( Class layoutDelegateClass) - throws InstantiationException, IllegalAccessException + throws ReflectiveOperationException { - return (LayoutSupportDelegate) layoutDelegateClass.newInstance(); + return (LayoutSupportDelegate) layoutDelegateClass.getDeclaredConstructor().newInstance(); } // ----------- @@ -155,7 +151,7 @@ private static boolean isUsableCustomLayoutClass(Class layoutClass) { } private LayoutSupportDelegate createLayoutSupportForSuperClass(Map map, Class subClass) - throws ClassNotFoundException, InstantiationException, IllegalAccessException { + throws ReflectiveOperationException { // We don't ask if the loaded registered class is assignable from 'subClass' // because it would not work for custom classes when the project classloader changes. for (Map.Entry en : map.entrySet()) { @@ -166,7 +162,7 @@ private LayoutSupportDelegate createLayoutSupportForSuperClass(Map computeFixes(CompilationInfo info, int pos, TreePath path) t } protected List computeFixes(CompilationInfo info, String diagnosticCode, int pos, TreePath path) throws Exception { - if (ruleToInvoke != null) return ruleToInvoke.newInstance().run(info, diagnosticCode, pos, path, null); + if (ruleToInvoke != null) return ruleToInvoke.getDeclaredConstructor().newInstance().run(info, diagnosticCode, pos, path, null); return computeFixes(info, pos, path); } @@ -325,7 +325,7 @@ protected void performFixTest(String fileName, String code, int pos, String fixC } protected Set getSupportedErrorKeys() throws Exception { - if (ruleToInvoke != null) return ruleToInvoke.newInstance().getCodes(); + if (ruleToInvoke != null) return ruleToInvoke.getDeclaredConstructor().newInstance().getCodes(); return null; } diff --git a/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/jrtfs/NBJRTFileSystem.java b/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/jrtfs/NBJRTFileSystem.java index 3f28daa43531..0c7a423c2677 100644 --- a/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/jrtfs/NBJRTFileSystem.java +++ b/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/jrtfs/NBJRTFileSystem.java @@ -245,7 +245,7 @@ private R writeOp(Class clz) throws E { try { e = clz.getDeclaredConstructor(String.class).newInstance(message); } catch (NoSuchMethodException nsm) { - e = clz.newInstance(); + e = clz.getDeclaredConstructor().newInstance(); } } catch (ReflectiveOperationException roe) { throw new IllegalStateException(message); diff --git a/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/queries/QueriesCache.java b/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/queries/QueriesCache.java index 8c660331b490..fa84b442bbbe 100644 --- a/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/queries/QueriesCache.java +++ b/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/queries/QueriesCache.java @@ -36,7 +36,6 @@ import javax.swing.event.ChangeListener; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.java.queries.JavadocForBinaryQuery; -import org.netbeans.api.java.queries.SourceForBinaryQuery; import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -93,12 +92,10 @@ void updateRoot(final URL binaryRoot, final URL... rootsToAttach) { } if (currentMapping == null) { try { - currentMapping = clazz.newInstance(); + currentMapping = clazz.getDeclaredConstructor().newInstance(); currentRoots.put(binaryRoot, currentMapping); - } catch (InstantiationException ie) { + } catch (ReflectiveOperationException ie) { Exceptions.printStackTrace(ie); - } catch (IllegalAccessException iae) { - Exceptions.printStackTrace(iae); } } } @@ -131,19 +128,13 @@ private Map loadRoots() { } } for (Map.Entry> e : bindings.entrySet()) { - final T instance = clazz.newInstance(); + final T instance = clazz.getDeclaredConstructor().newInstance(); instance.update(e.getValue()); result.put(e.getKey(), instance); } } - } catch (BackingStoreException bse) { + } catch (BackingStoreException | MalformedURLException | ReflectiveOperationException bse) { Exceptions.printStackTrace(bse); - } catch (MalformedURLException mue) { - Exceptions.printStackTrace(mue); - } catch (InstantiationException ie) { - Exceptions.printStackTrace(ie); - } catch (IllegalAccessException iae) { - Exceptions.printStackTrace(iae); } cache = result; } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/APTUtils.java b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/APTUtils.java index 58f01106fcb6..5b07844b8fa8 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/APTUtils.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/APTUtils.java @@ -381,7 +381,7 @@ private Collection lookupProcessors(ClassLoader cl, boolean onScan, b for (String name : processorNames) { try { Class clazz = Class.forName(name, true, cl); - Object instance = clazz.newInstance(); + Object instance = clazz.getDeclaredConstructor().newInstance(); if (instance instanceof Processor) { result.add(new ErrorToleratingProcessor((Processor) instance)); } diff --git a/java/java.source/src/org/netbeans/modules/java/ui/CategorySupport.java b/java/java.source/src/org/netbeans/modules/java/ui/CategorySupport.java index 1e9b5e93b08d..c0f9258eea26 100644 --- a/java/java.source/src/org/netbeans/modules/java/ui/CategorySupport.java +++ b/java/java.source/src/org/netbeans/modules/java/ui/CategorySupport.java @@ -319,7 +319,7 @@ public Factory(String id, Class panelClass, String previewText public PreferencesCustomizer create(Preferences preferences) { try { - CategorySupport categorySupport = new CategorySupport(preferences, id, panelClass.newInstance(), previewText, forcedOptions); + CategorySupport categorySupport = new CategorySupport(preferences, id, panelClass.getDeclaredConstructor().newInstance(), previewText, forcedOptions); if (categorySupport.panel instanceof Runnable) ((Runnable)categorySupport.panel).run(); return categorySupport; diff --git a/java/lib.jshell.agent/agentsrc/org/netbeans/lib/jshell/agent/AgentWorker.java b/java/lib.jshell.agent/agentsrc/org/netbeans/lib/jshell/agent/AgentWorker.java index a822ac5bba6a..ac69f903fa44 100644 --- a/java/lib.jshell.agent/agentsrc/org/netbeans/lib/jshell/agent/AgentWorker.java +++ b/java/lib.jshell.agent/agentsrc/org/netbeans/lib/jshell/agent/AgentWorker.java @@ -149,12 +149,8 @@ private Executor findExecutor() { } else if (o instanceof String) { try { Class executorClazz = Class.forName((String)o); - return (Executor)executorClazz.newInstance(); - } catch (ClassNotFoundException ex) { - LOG.log(Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - LOG.log(Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { + return (Executor)executorClazz.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException ex) { LOG.log(Level.SEVERE, null, ex); } } diff --git a/java/maven/test/unit/src/org/netbeans/modules/maven/newproject/simplewizard/EnsureJavaFXPresent.java b/java/maven/test/unit/src/org/netbeans/modules/maven/newproject/simplewizard/EnsureJavaFXPresent.java index 225018a1af4b..e2d73d65d5d0 100644 --- a/java/maven/test/unit/src/org/netbeans/modules/maven/newproject/simplewizard/EnsureJavaFXPresent.java +++ b/java/maven/test/unit/src/org/netbeans/modules/maven/newproject/simplewizard/EnsureJavaFXPresent.java @@ -25,7 +25,7 @@ class EnsureJavaFXPresent { static { Throwable t; try { - Object p = Class.forName("javafx.embed.swing.JFXPanel").newInstance(); + Object p = Class.forName("javafx.embed.swing.JFXPanel").getDeclaredConstructor().newInstance(); assertNotNull("Allocated", p); t = null; } catch (Throwable err) { diff --git a/java/performance/src/org/netbeans/modules/performance/Inst.java b/java/performance/src/org/netbeans/modules/performance/Inst.java index 8ec428c97cec..cf4c27180116 100644 --- a/java/performance/src/org/netbeans/modules/performance/Inst.java +++ b/java/performance/src/org/netbeans/modules/performance/Inst.java @@ -33,7 +33,7 @@ public void restored() { if (value != null) { try { Class c = Thread.currentThread().getContextClassLoader().loadClass(value); - Object run = c.newInstance(); + Object run = c.getDeclaredConstructor().newInstance(); ((Runnable)run).run(); } catch (Exception ex) { throw new IllegalStateException(ex); diff --git a/java/performance/test/qa-functional/src/org/netbeans/test/ide/PerfCountingSecurityManager.java b/java/performance/test/qa-functional/src/org/netbeans/test/ide/PerfCountingSecurityManager.java index ac6a13581db9..dcd3b28cead8 100644 --- a/java/performance/test/qa-functional/src/org/netbeans/test/ide/PerfCountingSecurityManager.java +++ b/java/performance/test/qa-functional/src/org/netbeans/test/ide/PerfCountingSecurityManager.java @@ -161,7 +161,7 @@ public void checkPermission(Permission p) { try { ClassLoader l = Thread.currentThread().getContextClassLoader(); Class manClass = Class.forName("org.netbeans.TopSecurityManager", false, l); - man = (SecurityManager) manClass.newInstance(); + man = (SecurityManager) manClass.getDeclaredConstructor().newInstance(); } catch (Exception ex) { throw new IllegalStateException(ex); } diff --git a/java/performance/test/unit/src/org/netbeans/performance/scalability/AWTThreadFreeTest.java b/java/performance/test/unit/src/org/netbeans/performance/scalability/AWTThreadFreeTest.java index 13286b79750e..b97e6de58855 100644 --- a/java/performance/test/unit/src/org/netbeans/performance/scalability/AWTThreadFreeTest.java +++ b/java/performance/test/unit/src/org/netbeans/performance/scalability/AWTThreadFreeTest.java @@ -130,7 +130,7 @@ public static void assertAWT(String msg, File dump) throws Exception { try { if (dump != null) { Class type = Class.forName("org.netbeans.lib.profiler.results.cpu.StackTraceSnapshotBuilder"); - Object builder = type.newInstance(); + Object builder = type.getDeclaredConstructor().newInstance(); long base = System.currentTimeMillis(); long time = base; for (StackTraceElement[] arr : traces) { diff --git a/java/performance/test/unit/src/org/netbeans/performance/scalability/TabSwitchSpeedTest.java b/java/performance/test/unit/src/org/netbeans/performance/scalability/TabSwitchSpeedTest.java index c811632ae386..1492d879502f 100644 --- a/java/performance/test/unit/src/org/netbeans/performance/scalability/TabSwitchSpeedTest.java +++ b/java/performance/test/unit/src/org/netbeans/performance/scalability/TabSwitchSpeedTest.java @@ -140,7 +140,7 @@ public void testAllPlatform() throws Exception { final void activateComponent(TopComponent tc) { if (map == null) { try { - Object o = Class.forName("org.netbeans.performance.scalability.Calls").newInstance(); + Object o = Class.forName("org.netbeans.performance.scalability.Calls").getDeclaredConstructor().newInstance(); @SuppressWarnings("unchecked") Map m = (Map)o; map = m; diff --git a/java/whitelist/src/org/netbeans/spi/whitelist/support/WhiteListImplementationBuilder.java b/java/whitelist/src/org/netbeans/spi/whitelist/support/WhiteListImplementationBuilder.java index ccf8b058968a..263d44b8ee2a 100644 --- a/java/whitelist/src/org/netbeans/spi/whitelist/support/WhiteListImplementationBuilder.java +++ b/java/whitelist/src/org/netbeans/spi/whitelist/support/WhiteListImplementationBuilder.java @@ -354,12 +354,8 @@ private static final class Model { private Model() { try { - names = (Names) Class.forName(System.getProperty("WhiteListBuilder.names", DEF_NAMES)).newInstance(); //NOI18N - } catch (InstantiationException ex) { - throw new IllegalStateException("Cannot instantiate names", ex); //NOI18N - } catch (IllegalAccessException ex) { - throw new IllegalStateException("Cannot instantiate names", ex); //NOI18N - } catch (ClassNotFoundException ex) { + names = (Names) Class.forName(System.getProperty("WhiteListBuilder.names", DEF_NAMES)).getDeclaredConstructor().newInstance(); //NOI18N + } catch (ReflectiveOperationException ex) { throw new IllegalStateException("Cannot instantiate names", ex); //NOI18N } checkedPkgs = Union2.createFirst(new StringBuilder()); diff --git a/java/xml.tools.java/src/org/netbeans/modules/xml/tools/java/generator/SAXGeneratorAbstractPanel.java b/java/xml.tools.java/src/org/netbeans/modules/xml/tools/java/generator/SAXGeneratorAbstractPanel.java index 54c46155dab5..20af481bff23 100644 --- a/java/xml.tools.java/src/org/netbeans/modules/xml/tools/java/generator/SAXGeneratorAbstractPanel.java +++ b/java/xml.tools.java/src/org/netbeans/modules/xml/tools/java/generator/SAXGeneratorAbstractPanel.java @@ -86,13 +86,11 @@ private SAXGeneratorAbstractPanel getPeer() { // object properly, client need to call setIndex and setBean if (bean == null) throw new IllegalStateException(); if (index == null) throw new IllegalStateException(); - peer = (SAXGeneratorAbstractPanel) peerClass.newInstance(); + peer = (SAXGeneratorAbstractPanel) peerClass.getDeclaredConstructor().newInstance(); peer.step = this; peer.setObject(bean); peer.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, index); // NOI18N - } catch (InstantiationException ex) { - throw new IllegalStateException(); - } catch (IllegalAccessException ex) { + } catch (ReflectiveOperationException ex) { throw new IllegalStateException(); } } diff --git a/nb/o.n.upgrader/src/org/netbeans/upgrade/systemoptions/SettingsRecognizer.java b/nb/o.n.upgrader/src/org/netbeans/upgrade/systemoptions/SettingsRecognizer.java index 4040ebdc7dd4..b9836c8a094e 100644 --- a/nb/o.n.upgrader/src/org/netbeans/upgrade/systemoptions/SettingsRecognizer.java +++ b/nb/o.n.upgrader/src/org/netbeans/upgrade/systemoptions/SettingsRecognizer.java @@ -311,7 +311,7 @@ public Object instanceCreate() throws java.io.IOException, ClassNotFoundExceptio } } else { try { - inst = clazz.newInstance(); + inst = clazz.getDeclaredConstructor().newInstance(); } catch (Exception ex) { IOException ioe = new IOException(); ErrorManager emgr = ErrorManager.getDefault(); diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java index 853aac8b0233..cba8a55286a0 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java @@ -635,8 +635,8 @@ public Factory(String id, Class panelClass, String previewText @Override public PreferencesCustomizer create(Preferences preferences) { try { - return new CategorySupport(preferences, id, panelClass.newInstance(), previewText, forcedOptions); - } catch (InstantiationException | IllegalAccessException e) { + return new CategorySupport(preferences, id, panelClass.getDeclaredConstructor().newInstance(), previewText, forcedOptions); + } catch (ReflectiveOperationException e) { LOGGER.log(Level.WARNING, "Exception during creating formatter customiezer", e); return null; } diff --git a/platform/api.io/src/org/netbeans/api/io/IOProvider.java b/platform/api.io/src/org/netbeans/api/io/IOProvider.java index d72a80d980bc..37ad0dcd4e3c 100644 --- a/platform/api.io/src/org/netbeans/api/io/IOProvider.java +++ b/platform/api.io/src/org/netbeans/api/io/IOProvider.java @@ -120,7 +120,7 @@ private static InputOutputProvider getBridging(String methodName, if (cl != null) { try { Class c = Class.forName(className, true, cl); - Object instance = c.newInstance(); + Object instance = c.getDeclaredConstructor().newInstance(); Method m = c.getDeclaredMethod(methodName, paramTypes); Object result = m.invoke(instance, params); if (result instanceof InputOutputProvider) { diff --git a/platform/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoUsesSwingTest.java b/platform/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoUsesSwingTest.java index b9070daf898d..794457fad57c 100644 --- a/platform/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoUsesSwingTest.java +++ b/platform/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoUsesSwingTest.java @@ -68,7 +68,7 @@ public void testCanReferenceJFrame() throws Exception { m1 = mgr.create(simpleModule, null, false, false, false); mgr.enable(Collections.singleton(m1)); Class c = m1.getClassLoader().loadClass("org.barwing.Main"); - Runnable r = (Runnable)c.newInstance(); + Runnable r = (Runnable)c.getDeclaredConstructor().newInstance(); r.run(); } finally { mgr.mutexPrivileged().exitWriteAccess(); diff --git a/platform/core.osgi/src/org/netbeans/core/osgi/Activator.java b/platform/core.osgi/src/org/netbeans/core/osgi/Activator.java index 856f447e8d63..8f6583e244de 100644 --- a/platform/core.osgi/src/org/netbeans/core/osgi/Activator.java +++ b/platform/core.osgi/src/org/netbeans/core/osgi/Activator.java @@ -315,7 +315,7 @@ private void registerUrlProtocolHandlers(final Bundle bundle) { class Svc extends AbstractURLStreamHandlerService { public @Override URLConnection openConnection(final URL u) throws IOException { try { - URLStreamHandler handler = (URLStreamHandler) bundle.loadClass(fqn).newInstance(); + URLStreamHandler handler = (URLStreamHandler) bundle.loadClass(fqn).getDeclaredConstructor().newInstance(); Method openConnection = URLStreamHandler.class.getDeclaredMethod("openConnection", URL.class); openConnection.setAccessible(true); return (URLConnection) openConnection.invoke(handler, u); diff --git a/platform/core.startup.base/src/org/netbeans/core/startup/layers/SystemFileSystem.java b/platform/core.startup.base/src/org/netbeans/core/startup/layers/SystemFileSystem.java index d10d56c59f51..1fa57ee30275 100644 --- a/platform/core.startup.base/src/org/netbeans/core/startup/layers/SystemFileSystem.java +++ b/platform/core.startup.base/src/org/netbeans/core/startup/layers/SystemFileSystem.java @@ -185,7 +185,7 @@ static SystemFileSystem create (File userDir, File homeDir, File[] extradirs) if (customFSClass != null) { try { Class clazz = Class.forName(customFSClass); - Object instance = clazz.newInstance(); + Object instance = clazz.getDeclaredConstructor().newInstance(); user = (FileSystem)instance; } catch (Exception x) { ModuleLayeredFileSystem.err.log( diff --git a/platform/core.startup/src/org/netbeans/core/startup/ManifestSection.java b/platform/core.startup/src/org/netbeans/core/startup/ManifestSection.java index 1ce3f02976b8..fb91fb830018 100644 --- a/platform/core.startup/src/org/netbeans/core/startup/ManifestSection.java +++ b/platform/core.startup/src/org/netbeans/core/startup/ManifestSection.java @@ -175,7 +175,7 @@ protected final Object createInstance() throws Exception { if (SharedClassObject.class.isAssignableFrom(clazz)) { return SharedClassObject.findObject(clazz.asSubclass(SharedClassObject.class), true); } else { - return clazz.newInstance(); + return clazz.getDeclaredConstructor().newInstance(); } } } diff --git a/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CountingSecurityManager.java b/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CountingSecurityManager.java index 67de8f6fb7b6..8d5e5668d0c3 100644 --- a/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CountingSecurityManager.java +++ b/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CountingSecurityManager.java @@ -167,7 +167,7 @@ public void checkPermission(Permission p) { try { ClassLoader l = Thread.currentThread().getContextClassLoader(); Class manClass = Class.forName("org.netbeans.TopSecurityManager", false, l); - man = (SecurityManager) manClass.newInstance(); + man = (SecurityManager) manClass.getDeclaredConstructor().newInstance(); } catch (Exception ex) { throw new IllegalStateException(ex); } diff --git a/platform/core.windows/src/org/netbeans/core/windows/options/LafPanel.java b/platform/core.windows/src/org/netbeans/core/windows/options/LafPanel.java index c7725da837dd..4ecff34c30a3 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/options/LafPanel.java +++ b/platform/core.windows/src/org/netbeans/core/windows/options/LafPanel.java @@ -276,7 +276,7 @@ private boolean isChangeEditorColorsPossible() { cl = LafPanel.class.getClassLoader(); try { Class klz = cl.loadClass( COLOR_MODEL_CLASS_NAME ); - Object colorModel = klz.newInstance(); + Object colorModel = klz.getDeclaredConstructor().newInstance(); Method m = klz.getDeclaredMethod( "getCurrentProfile", new Class[0] ); //NOI18N Object res = m.invoke( colorModel, new Object[0] ); return res != null && !preferredProfile.equals( res ); @@ -296,7 +296,7 @@ private void switchEditorColorsProfile() { cl = LafPanel.class.getClassLoader(); try { Class klz = cl.loadClass( COLOR_MODEL_CLASS_NAME ); - Object colorModel = klz.newInstance(); + Object colorModel = klz.getDeclaredConstructor().newInstance(); Method m = klz.getDeclaredMethod( "getAnnotations", String.class ); //NOI18N Object annotations = m.invoke( colorModel, preferredProfile ); m = klz.getDeclaredMethod( "setAnnotations", String.class, Collection.class ); //NOI18N @@ -349,7 +349,7 @@ private String getPreferredColorProfile() { try { Class klazz = loader.loadClass( className ); - LookAndFeel laf = ( LookAndFeel ) klazz.newInstance(); + LookAndFeel laf = ( LookAndFeel ) klazz.getDeclaredConstructor().newInstance(); return laf.getDefaults().getString( "nb.preferred.color.profile" ); //NOI18N } catch( Exception e ) { //ignore diff --git a/platform/core.windows/src/org/netbeans/core/windows/view/ui/toolbars/ToolbarContainer.java b/platform/core.windows/src/org/netbeans/core/windows/view/ui/toolbars/ToolbarContainer.java index 97a53056dcb1..ae4482d4a808 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/view/ui/toolbars/ToolbarContainer.java +++ b/platform/core.windows/src/org/netbeans/core/windows/view/ui/toolbars/ToolbarContainer.java @@ -258,7 +258,7 @@ private JComponent createDragger() { if( null != className ) { try { Class klzz = Lookup.getDefault().lookup( ClassLoader.class ).loadClass( className ); - Object inst = klzz.newInstance(); + Object inst = klzz.getDeclaredConstructor().newInstance(); if( inst instanceof JComponent ) { JComponent dragarea = ( JComponent ) inst; dragarea.setCursor( Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR) ); diff --git a/platform/editor.mimelookup.impl/src/org/netbeans/modules/editor/mimelookup/impl/SwitchLookup.java b/platform/editor.mimelookup.impl/src/org/netbeans/modules/editor/mimelookup/impl/SwitchLookup.java index d720879621b6..e5642d0d50b3 100644 --- a/platform/editor.mimelookup.impl/src/org/netbeans/modules/editor/mimelookup/impl/SwitchLookup.java +++ b/platform/editor.mimelookup.impl/src/org/netbeans/modules/editor/mimelookup/impl/SwitchLookup.java @@ -102,11 +102,8 @@ public Class annotationType() { if (loc.instanceProviderClass() != null && loc.instanceProviderClass() != InstanceProvider.class) { try { // Get a lookup for the new instance provider - lookup = getLookupForProvider(paths, loc.instanceProviderClass().newInstance()); - } catch (InstantiationException ex) { - Exceptions.printStackTrace(ex); - lookup = Lookup.EMPTY; - } catch (IllegalAccessException ex) { + lookup = getLookupForProvider(paths, loc.instanceProviderClass().getDeclaredConstructor().newInstance()); + } catch (ReflectiveOperationException ex) { Exceptions.printStackTrace(ex); lookup = Lookup.EMPTY; } diff --git a/platform/editor.mimelookup/src/org/netbeans/modules/editor/mimelookup/CreateRegistrationProcessor.java b/platform/editor.mimelookup/src/org/netbeans/modules/editor/mimelookup/CreateRegistrationProcessor.java index bf65fef12981..a7febe65e5d5 100644 --- a/platform/editor.mimelookup/src/org/netbeans/modules/editor/mimelookup/CreateRegistrationProcessor.java +++ b/platform/editor.mimelookup/src/org/netbeans/modules/editor/mimelookup/CreateRegistrationProcessor.java @@ -277,7 +277,7 @@ private Iterable completeMimePath( l = CreateRegistrationProcessor.class.getClassLoader(); } try { - COMPLETIONS = (Processor)Class.forName(pathCompletions, true, l).newInstance(); + COMPLETIONS = (Processor)Class.forName(pathCompletions, true, l).getDeclaredConstructor().newInstance(); } catch (Exception ex) { Exceptions.printStackTrace(ex); // no completions, OK diff --git a/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/AgentTest.java b/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/AgentTest.java index e47fca0dd11b..046cd1b360b0 100644 --- a/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/AgentTest.java +++ b/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/AgentTest.java @@ -59,7 +59,7 @@ public void testAgentClassRedefinesHello() throws Exception { Module m = mgr.create(agent, null, false, false, false); try { mgr.enable(m); - Callable c = (Callable) m.getClassLoader().loadClass("org.agent.HelloWorld").newInstance(); + Callable c = (Callable) m.getClassLoader().loadClass("org.agent.HelloWorld").getDeclaredConstructor().newInstance(); assertEquals("Bytecode has been patched", "Ahoj World!", c.call()); } finally { mgr.disable(m); diff --git a/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/CountingSecurityManager.java b/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/CountingSecurityManager.java index ca5d0d73525d..608d1d936dbe 100644 --- a/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/CountingSecurityManager.java +++ b/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/CountingSecurityManager.java @@ -162,7 +162,7 @@ public void checkPermission(Permission p) { try { ClassLoader l = Thread.currentThread().getContextClassLoader(); Class manClass = Class.forName("org.netbeans.TopSecurityManager", false, l); - man = (SecurityManager) manClass.newInstance(); + man = (SecurityManager) manClass.getDeclaredConstructor().newInstance(); } catch (Exception ex) { throw new IllegalStateException(ex); } diff --git a/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/NetigsoUsesSwingTest.java b/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/NetigsoUsesSwingTest.java index 66ff1ba6069f..96c6f9100515 100644 --- a/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/NetigsoUsesSwingTest.java +++ b/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/NetigsoUsesSwingTest.java @@ -76,7 +76,7 @@ public void testCanReferenceJFrame() throws Exception { m1 = mgr.create(simpleModule, null, false, false, false); mgr.enable(Collections.singleton(m1)); Class c = m1.getClassLoader().loadClass("org.barwing.Main"); - Runnable r = (Runnable)c.newInstance(); + Runnable r = (Runnable)c.getDeclaredConstructor().newInstance(); r.run(); } finally { mgr.mutexPrivileged().exitWriteAccess(); diff --git a/platform/o.n.bootstrap/test/unit/src/org/netbeans/AgentTest.java b/platform/o.n.bootstrap/test/unit/src/org/netbeans/AgentTest.java index ebc581d4deeb..3e92196ad472 100644 --- a/platform/o.n.bootstrap/test/unit/src/org/netbeans/AgentTest.java +++ b/platform/o.n.bootstrap/test/unit/src/org/netbeans/AgentTest.java @@ -40,7 +40,7 @@ public void testAgentClassRedefinesHello() throws Exception { Module m = mgr.create(jar, null, false, false, false); try { mgr.enable(m); - Callable c = (Callable) m.getClassLoader().loadClass("org.agent.HelloWorld").newInstance(); + Callable c = (Callable) m.getClassLoader().loadClass("org.agent.HelloWorld").getDeclaredConstructor().newInstance(); assertEquals("Bytecode has been patched", "Ahoj World!", c.call()); } finally { mgr.disable(m); diff --git a/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java b/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java index d60864328e7f..a37f613cf495 100644 --- a/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java +++ b/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java @@ -27,6 +27,7 @@ import java.lang.ref.WeakReference; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.net.URLClassLoader; import java.net.URLConnection; @@ -168,7 +169,7 @@ public void testSimpleInstallation() throws Exception { ), installer.args); Class somethingelse = Class.forName("org.bar.SomethingElse", true, m2.getClassLoader()); Method somemethod = somethingelse.getMethod("message"); - assertEquals("hello", somemethod.invoke(somethingelse.newInstance())); + assertEquals("hello", somemethod.invoke(somethingelse.getDeclaredConstructor().newInstance())); installer.clear(); List toDisable = mgr.simulateDisable(Collections.singleton(m1)); assertEquals("correct result of simulateDisable", Arrays.asList(m2, m1), toDisable); @@ -242,7 +243,7 @@ public void testInstallAutoload() throws Exception { ), installer.args); Class somethingelse = Class.forName("org.bar.SomethingElse", true, m2.getClassLoader()); Method somemethod = somethingelse.getMethod("message"); - assertEquals("hello", somemethod.invoke(somethingelse.newInstance())); + assertEquals("hello", somemethod.invoke(somethingelse.getDeclaredConstructor().newInstance())); // Now try turning off m2 and make sure m1 goes away as well. assertEquals("correct result of simulateDisable", Arrays.asList(m2, m1), mgr.simulateDisable(Collections.singleton(m2))); installer.clear(); @@ -302,7 +303,7 @@ public void testInstallEager() throws Exception { ), installer.args); Class somethingelse = Class.forName("org.bar.SomethingElse", true, m2.getClassLoader()); Method somemethod = somethingelse.getMethod("message"); - assertEquals("hello", somemethod.invoke(somethingelse.newInstance())); + assertEquals("hello", somemethod.invoke(somethingelse.getDeclaredConstructor().newInstance())); // Now try turning off m1 and make sure m2 goes away quietly. assertEquals("correct result of simulateDisable", Arrays.asList(m2, m1), mgr.simulateDisable(Collections.singleton(m1))); installer.clear(); @@ -349,7 +350,7 @@ public void testEagerPlusAutoload() throws Exception { ), installer.args); Class somethingelseagain = Class.forName("org.baz.SomethingElseAgain", true, m3.getClassLoader()); Method somemethod = somethingelseagain.getMethod("doit"); - assertEquals("hello", somemethod.invoke(somethingelseagain.newInstance())); + assertEquals("hello", somemethod.invoke(somethingelseagain.getDeclaredConstructor().newInstance())); assertEquals("correct result of simulateDisable", Arrays.asList(m3, m2, m1), mgr.simulateDisable(Collections.singleton(m2))); installer.clear(); mgr.disable(Collections.singleton(m2)); @@ -658,7 +659,7 @@ public void testPackageLoading() throws Exception { Module m = mgr.create(new File(jars, "depends-on-lib-undecl.jar"), null, false, false, false); mgr.enable(m); Class c = m.getClassLoader().loadClass("org.dol.User"); - Object o = c.newInstance(); + Object o = c.getDeclaredConstructor().newInstance(); Field f = c.getField("val"); assertEquals(42, f.getInt(o)); mgr.disable(m); @@ -892,7 +893,7 @@ public void testModulePatches() throws Exception { mgr.enable(m); Class c = m.getClassLoader().loadClass("pkg.subpkg.A"); Field f = c.getField("val"); - Object o = c.newInstance(); + Object o = c.getDeclaredConstructor().newInstance(); assertEquals(25, f.getInt(o)); } finally { mgr.mutexPrivileged().exitWriteAccess(); @@ -2066,8 +2067,8 @@ public void testPackageExports() throws Exception { Module m2 = mgr.create(new File(jars, "uses-api-simple-dep.jar"), null, false, false, false); mgr.enable(m1); mgr.enable(m2); - m2.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance(); - m2.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesPublicClass").getDeclaredConstructor().newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesImplClass").getDeclaredConstructor().newInstance(); mgr.disable(m2); mgr.disable(m1); mgr.delete(m2); @@ -2077,13 +2078,17 @@ public void testPackageExports() throws Exception { mgr.enable(m1); mgr.enable(m2); try { - m2.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesPublicClass").getDeclaredConstructor().newInstance(); fail(); - } catch (NoClassDefFoundError e) {} + } catch (InvocationTargetException e) { + assertTrue(e.getCause() instanceof NoClassDefFoundError); + } try { - m2.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesImplClass").getDeclaredConstructor().newInstance(); fail(); - } catch (NoClassDefFoundError e) {} + } catch (InvocationTargetException e) { + assertTrue(e.getCause() instanceof NoClassDefFoundError); + } assertNotNull(mgr.getClassLoader().getResource("usesapi/UsesImplClass.class")); assertNotNull(mgr.getClassLoader().getResource("org/netbeans/api/foo/PublicClass.class")); assertNotNull(mgr.getClassLoader().getResource("org/netbeans/modules/foo/ImplClass.class")); @@ -2096,13 +2101,17 @@ public void testPackageExports() throws Exception { mgr.enable(m1); mgr.enable(m2); try { - m2.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesPublicClass").getDeclaredConstructor().newInstance(); fail(); - } catch (NoClassDefFoundError e) {} + } catch (InvocationTargetException e) { + assertTrue(e.getCause() instanceof NoClassDefFoundError); + } try { - m2.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesImplClass").getDeclaredConstructor().newInstance(); fail(); - } catch (NoClassDefFoundError e) {} + } catch (InvocationTargetException e) { + assertTrue(e.getCause() instanceof NoClassDefFoundError); + } mgr.disable(m2); mgr.disable(m1); mgr.delete(m2); @@ -2111,8 +2120,8 @@ public void testPackageExports() throws Exception { m2 = mgr.create(new File(jars, "uses-api-impl-dep.jar"), null, false, false, false); mgr.enable(m1); mgr.enable(m2); - m2.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance(); - m2.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesPublicClass").getDeclaredConstructor().newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesImplClass").getDeclaredConstructor().newInstance(); mgr.disable(m2); mgr.disable(m1); mgr.delete(m2); @@ -2123,11 +2132,13 @@ public void testPackageExports() throws Exception { mgr.enable(m1); assertEquals("uses-api-simple-dep.jar can be enabled", Collections.EMPTY_SET, m2.getProblems()); mgr.enable(m2); - m2.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesPublicClass").getDeclaredConstructor().newInstance(); try { - m2.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesImplClass").getDeclaredConstructor().newInstance(); fail(); - } catch (NoClassDefFoundError e) {} + } catch (InvocationTargetException e) { + assertTrue(e.getCause() instanceof NoClassDefFoundError); + } mgr.disable(m2); mgr.disable(m1); mgr.delete(m2); @@ -2136,11 +2147,13 @@ public void testPackageExports() throws Exception { m2 = mgr.create(new File(jars, "uses-api-spec-dep.jar"), null, false, false, false); mgr.enable(m1); mgr.enable(m2); - m2.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesPublicClass").getDeclaredConstructor().newInstance(); try { - m2.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesImplClass").getDeclaredConstructor().newInstance(); fail(); - } catch (NoClassDefFoundError e) {} + } catch (InvocationTargetException e) { + assertTrue(e.getCause() instanceof NoClassDefFoundError); + } mgr.disable(m2); mgr.disable(m1); mgr.delete(m2); @@ -2149,8 +2162,8 @@ public void testPackageExports() throws Exception { m2 = mgr.create(new File(jars, "uses-api-impl-dep.jar"), null, false, false, false); mgr.enable(m1); mgr.enable(m2); - m2.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance(); - m2.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesPublicClass").getDeclaredConstructor().newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesImplClass").getDeclaredConstructor().newInstance(); mgr.disable(m2); mgr.disable(m1); mgr.delete(m2); @@ -2182,15 +2195,17 @@ public void testIndirectPackageExports() throws Exception { assertEquals("uses-and-exports-api.jar had no problems", Collections.EMPTY_SET, m2.getProblems()); assertEquals("uses-api-transitively.jar had no problems", Collections.EMPTY_SET, m3.getProblems()); assertEquals("uses-api-directly.jar had no problems", Collections.EMPTY_SET, m4.getProblems()); - mgr.enable(new HashSet(Arrays.asList(m1, m2, m3, m4))); - m4.getClassLoader().loadClass("usesapitrans.UsesDirectAPI").newInstance(); - m4.getClassLoader().loadClass("usesapitrans.UsesIndirectAPI").newInstance(); - m3.getClassLoader().loadClass("usesapitrans.UsesDirectAPI").newInstance(); + mgr.enable(new HashSet<>(Arrays.asList(m1, m2, m3, m4))); + m4.getClassLoader().loadClass("usesapitrans.UsesDirectAPI").getDeclaredConstructor().newInstance(); + m4.getClassLoader().loadClass("usesapitrans.UsesIndirectAPI").getDeclaredConstructor().newInstance(); + m3.getClassLoader().loadClass("usesapitrans.UsesDirectAPI").getDeclaredConstructor().newInstance(); try { - m3.getClassLoader().loadClass("usesapitrans.UsesIndirectAPI").newInstance(); + m3.getClassLoader().loadClass("usesapitrans.UsesIndirectAPI").getDeclaredConstructor().newInstance(); fail("Should not be able to use a transitive API class with no direct dependency"); - } catch (NoClassDefFoundError e) {} - mgr.disable(new HashSet(Arrays.asList(m1, m2, m3, m4))); + } catch (InvocationTargetException e) { + assertTrue(e.getCause() instanceof NoClassDefFoundError); + } + mgr.disable(new HashSet<>(Arrays.asList(m1, m2, m3, m4))); mgr.delete(m4); mgr.delete(m3); mgr.delete(m2); @@ -2215,34 +2230,34 @@ public void testPublicPackagesCanBeExportedToSelectedFriendsOnlyIssue54123 () th assertEquals("uses-api-directly.jar had no problems", Collections.EMPTY_SET, m4.getProblems()); assertEquals("uses-api-impl-dep-for-friends.jar had no problems", Collections.EMPTY_SET, m5.getProblems()); mgr.enable(new HashSet(Arrays.asList(m1, m2, m3, m4, m5))); - m2.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesPublicClass").getDeclaredConstructor().newInstance(); try { - m2.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance(); + m2.getClassLoader().loadClass("usesapi.UsesImplClass").getDeclaredConstructor().newInstance(); fail ("Even friends modules cannot access implementation classes"); - } catch (NoClassDefFoundError ex) { - // ok + } catch (InvocationTargetException ex) { + assertTrue(ex.getCause() instanceof NoClassDefFoundError); } try { - m4.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance(); + m4.getClassLoader().loadClass("usesapi.UsesPublicClass").getDeclaredConstructor().newInstance(); fail ("m4 is not friend and should not be allowed to load the class"); - } catch (NoClassDefFoundError ex) { - // ok + } catch (InvocationTargetException ex) { + assertTrue(ex.getCause() instanceof NoClassDefFoundError); } try { - m4.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance(); + m4.getClassLoader().loadClass("usesapi.UsesImplClass").getDeclaredConstructor().newInstance(); fail ("m4 is not friend and should not be allowed to load the implementation either"); - } catch (NoClassDefFoundError ex) { - // ok + } catch (InvocationTargetException ex) { + assertTrue(ex.getCause() instanceof NoClassDefFoundError); } try { - m5.getClassLoader().loadClass("usesapi.UsesPublicClass").newInstance(); - } catch (NoClassDefFoundError e) { + m5.getClassLoader().loadClass("usesapi.UsesPublicClass").getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { fail("m5 has an implementation dependency and has not been allowed to load the public class"); } try { - m5.getClassLoader().loadClass("usesapi.UsesImplClass").newInstance(); - } catch (NoClassDefFoundError e) { + m5.getClassLoader().loadClass("usesapi.UsesImplClass").getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { fail("m5 has an implementation dependency and has not been allowed to load the imlpementation class"); } diff --git a/platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/Startup.java b/platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/Startup.java index 8ab286991a4f..3e5f56e655a5 100644 --- a/platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/Startup.java +++ b/platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/Startup.java @@ -158,8 +158,8 @@ private LFInstanceOrName getLookAndFeel() { LookAndFeel lf = UIManager.getLookAndFeel(); if (uiClass != lf.getClass()) { try { - lf = (LookAndFeel) uiClass.newInstance(); - } catch (IllegalAccessException | InstantiationException ex) { + lf = (LookAndFeel) uiClass.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException ex) { return new LFInstanceOrName(uiClass.getName()); } } @@ -385,7 +385,7 @@ private LFCustoms findCustoms () { } try { Class klazz = UIUtils.classForName( uiClassName ); - Object inst = klazz.newInstance(); + Object inst = klazz.getDeclaredConstructor().newInstance(); if( inst instanceof LFCustoms ) return ( LFCustoms ) inst; } catch( ClassNotFoundException e ) { @@ -417,7 +417,7 @@ private LFCustoms findDefaultCustoms() { return new GtkLFCustoms(); } else { try { - return (LFCustoms) UIUtils.classForName(FORCED_CUSTOMS).newInstance(); + return (LFCustoms) UIUtils.classForName(FORCED_CUSTOMS).getDeclaredConstructor().newInstance(); } catch (Exception e) { System.err.println("UI customizations class not found: " //NOI18N + FORCED_CUSTOMS); //NOI18N diff --git a/platform/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java b/platform/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java index 04c61c415f7b..ab64edfcef7b 100644 --- a/platform/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java +++ b/platform/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java @@ -127,7 +127,7 @@ public Iterable getCompletions(Element element, Annotation l = ActionProcessor.class.getClassLoader(); } try { - COMPLETIONS = (Processor)Class.forName(pathCompletions, true, l).newInstance(); + COMPLETIONS = (Processor)Class.forName(pathCompletions, true, l).getDeclaredConstructor().newInstance(); } catch (Exception ex) { Exceptions.printStackTrace(ex); // no completions, OK diff --git a/platform/openide.execution/test/unit/src/org/openide/execution/NbClassLoaderTest.java b/platform/openide.execution/test/unit/src/org/openide/execution/NbClassLoaderTest.java index 989b5763c78a..433fc00093c0 100644 --- a/platform/openide.execution/test/unit/src/org/openide/execution/NbClassLoaderTest.java +++ b/platform/openide.execution/test/unit/src/org/openide/execution/NbClassLoaderTest.java @@ -72,7 +72,7 @@ public void testUsingNbfsProtocol() throws Exception { Class c = cl.loadClass("org.openide.execution.NbClassLoaderTest$User"); assertEquals(cl, c.getClassLoader()); try { - c.newInstance(); + c.getDeclaredConstructor().newInstance(); } catch (ExceptionInInitializerError eiie) { Throwable t = eiie.getException(); if (t instanceof IllegalStateException) { diff --git a/platform/openide.explorer/src/org/openide/explorer/propertysheet/IndexedPropertyEditor.java b/platform/openide.explorer/src/org/openide/explorer/propertysheet/IndexedPropertyEditor.java index 6e2ae38043d4..1df6b95f158d 100644 --- a/platform/openide.explorer/src/org/openide/explorer/propertysheet/IndexedPropertyEditor.java +++ b/platform/openide.explorer/src/org/openide/explorer/propertysheet/IndexedPropertyEditor.java @@ -376,7 +376,7 @@ private Object defaultValue() { } } else { try { - value = getConvertedType().newInstance(); + value = getConvertedType().getDeclaredConstructor().newInstance(); } catch (Exception x) { // ignore any exception - if this fails just // leave null as the value diff --git a/platform/openide.explorer/src/org/openide/explorer/propertysheet/ModelProperty.java b/platform/openide.explorer/src/org/openide/explorer/propertysheet/ModelProperty.java index c3e999d62b13..565735adf822 100644 --- a/platform/openide.explorer/src/org/openide/explorer/propertysheet/ModelProperty.java +++ b/platform/openide.explorer/src/org/openide/explorer/propertysheet/ModelProperty.java @@ -349,7 +349,7 @@ public PropertyEditor getPropertyEditor() { //overrides getPropertyEditorClass() try { //System.err.println(getDisplayName() + "Returning editor class specified property editor - " + edClass); - return (PropertyEditor) edClass.newInstance(); + return (PropertyEditor) edClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { //fall through } diff --git a/platform/openide.explorer/src/org/openide/explorer/propertysheet/RendererFactory.java b/platform/openide.explorer/src/org/openide/explorer/propertysheet/RendererFactory.java index 60db44922a6d..b44fdc089037 100644 --- a/platform/openide.explorer/src/org/openide/explorer/propertysheet/RendererFactory.java +++ b/platform/openide.explorer/src/org/openide/explorer/propertysheet/RendererFactory.java @@ -283,7 +283,7 @@ private PropertyEditor preparePropertyEditor(PropertyModel pm, PropertyEnv env) if (c != null) { try { - result = (PropertyEditor) c.newInstance(); + result = (PropertyEditor) c.getDeclaredConstructor().newInstance(); //Check the values first Object mdlValue = pm.getValue(); diff --git a/platform/openide.loaders/src/org/openide/loaders/XMLDataObject.java b/platform/openide.loaders/src/org/openide/loaders/XMLDataObject.java index 51845241ddc3..bda8047559f1 100644 --- a/platform/openide.loaders/src/org/openide/loaders/XMLDataObject.java +++ b/platform/openide.loaders/src/org/openide/loaders/XMLDataObject.java @@ -24,7 +24,6 @@ import java.lang.ref.*; import java.lang.reflect.*; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.util.*; import java.util.logging.*; import javax.xml.parsers.DocumentBuilder; @@ -1243,7 +1242,7 @@ public synchronized Object getInstance () { if (Processor.class.isAssignableFrom (next)) { // the class implements Processor interface, so use // default constructor to construct instance - obj = next.newInstance (); + obj = next.getDeclaredConstructor().newInstance (); Processor proc = (Processor) obj; proc.attachTo (xmlDataObject); return obj; @@ -1269,11 +1268,7 @@ public synchronized Object getInstance () { } } throw new InternalError ("XMLDataObject processor class " + next + " invalid"); // NOI18N - } catch (InvocationTargetException e) { - xmlDataObject.notifyEx (e); - } catch (InstantiationException e) { - xmlDataObject.notifyEx(e); - } catch (IllegalAccessException e) { + } catch (ReflectiveOperationException e) { xmlDataObject.notifyEx(e); } diff --git a/platform/openide.nodes/src/org/openide/nodes/BeanNode.java b/platform/openide.nodes/src/org/openide/nodes/BeanNode.java index 919e67681f6c..ad1b4dd1f34d 100644 --- a/platform/openide.nodes/src/org/openide/nodes/BeanNode.java +++ b/platform/openide.nodes/src/org/openide/nodes/BeanNode.java @@ -383,14 +383,9 @@ public java.awt.Component getCustomizer() { Object o; try { - o = clazz.newInstance(); - } catch (InstantiationException e) { + o = clazz.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { NodeOp.exception(e); - - return null; - } catch (IllegalAccessException e) { - NodeOp.exception(e); - return null; } diff --git a/platform/openide.nodes/src/org/openide/nodes/TMUtil.java b/platform/openide.nodes/src/org/openide/nodes/TMUtil.java index 294002ed9003..26fd8466cc72 100644 --- a/platform/openide.nodes/src/org/openide/nodes/TMUtil.java +++ b/platform/openide.nodes/src/org/openide/nodes/TMUtil.java @@ -19,6 +19,7 @@ package org.openide.nodes; +import java.lang.reflect.InvocationTargetException; import java.util.Hashtable; import org.openide.util.Mutex; @@ -159,7 +160,7 @@ public Void run() { /** Executes algorithm of given name. * @param name the name of algorithm - * @return true iff successfule + * @return true if successful */ private static boolean exec(String name) { Object obj = algorithms.get(name); @@ -167,20 +168,14 @@ private static boolean exec(String name) { if (obj == null) { try { Class c = Class.forName("org.openide.nodes.TMUtil$" + name); // NOI18N - obj = c.newInstance(); - } catch (ClassNotFoundException ex) { + obj = c.getDeclaredConstructor().newInstance(); + } catch (ClassNotFoundException | InvocationTargetException | IllegalAccessException ex) { obj = ex; NodeOp.exception(ex); - } catch (InstantiationException ex) { + } catch (InstantiationException | NoSuchMethodException | NoClassDefFoundError ex) { // that is ok, we should not be able to create an // instance if some classes are missing obj = ex; - } catch (IllegalAccessException ex) { - obj = ex; - NodeOp.exception(ex); - } catch (NoClassDefFoundError ex) { - // that is ok, some classes need not be found - obj = ex; } algorithms.put(name, obj); @@ -308,7 +303,7 @@ public void run() { nodeRenderer = loadClass("org.openide.explorer.view.NodeRenderer"); // NOI18N } - TALK.set(nodeRenderer.newInstance()); + TALK.set(nodeRenderer.getDeclaredConstructor().newInstance()); } catch (Exception ex) { throw new IllegalStateException(ex.getMessage()); } diff --git a/platform/openide.util.lookup/src/org/openide/util/Lookup.java b/platform/openide.util.lookup/src/org/openide/util/Lookup.java index 5c053c724f01..684fd87fd472 100644 --- a/platform/openide.util.lookup/src/org/openide/util/Lookup.java +++ b/platform/openide.util.lookup/src/org/openide/util/Lookup.java @@ -122,7 +122,7 @@ public static synchronized Lookup getDefault() { LOG.log(Level.FINER, "Searching in classloader {0}", l); try { if (className != null) { - Object o = Class.forName(className, true, l).newInstance(); + Object o = Class.forName(className, true, l).getDeclaredConstructor().newInstance(); defaultLookup = (Lookup)o; // set the global global Lookuo GlobalLookup.setSystemLookup(defaultLookup); diff --git a/platform/openide.util.lookup/src/org/openide/util/lookup/MetaInfServicesLookup.java b/platform/openide.util.lookup/src/org/openide/util/lookup/MetaInfServicesLookup.java index bfe00b034f47..f701548de10b 100644 --- a/platform/openide.util.lookup/src/org/openide/util/lookup/MetaInfServicesLookup.java +++ b/platform/openide.util.lookup/src/org/openide/util/lookup/MetaInfServicesLookup.java @@ -58,7 +58,7 @@ static synchronized Executor getRP() { if (res == null) { try { Class seek = Class.forName("org.openide.util.RequestProcessor"); - res = (Executor)seek.newInstance(); + res = (Executor)seek.getDeclaredConstructor().newInstance(); } catch (Throwable t) { try { res = Executors.newSingleThreadExecutor(); diff --git a/platform/openide.util.lookup/test/unit/src/org/openide/util/lookup/AbstractLookupBaseHid.java b/platform/openide.util.lookup/test/unit/src/org/openide/util/lookup/AbstractLookupBaseHid.java index abe390ac7a30..6641e7d5122a 100644 --- a/platform/openide.util.lookup/test/unit/src/org/openide/util/lookup/AbstractLookupBaseHid.java +++ b/platform/openide.util.lookup/test/unit/src/org/openide/util/lookup/AbstractLookupBaseHid.java @@ -1307,7 +1307,7 @@ private void doTwoSerializedClasses (boolean queryBeforeSerialization, boolean u loader = new CL (); c = loader.loadClass (Garbage.class.getName ()); - Object theInstance = c.newInstance (); + Object theInstance = c.getDeclaredConstructor().newInstance (); ic.addPair (new SerialPair (theInstance)); diff --git a/platform/openide.util.ui/test/unit/src/org/netbeans/modules/openide/util/NbBundleProcessorTest.java b/platform/openide.util.ui/test/unit/src/org/netbeans/modules/openide/util/NbBundleProcessorTest.java index 84bcbc383645..b2d7ec3745aa 100644 --- a/platform/openide.util.ui/test/unit/src/org/netbeans/modules/openide/util/NbBundleProcessorTest.java +++ b/platform/openide.util.ui/test/unit/src/org/netbeans/modules/openide/util/NbBundleProcessorTest.java @@ -209,18 +209,18 @@ public void testIncrementalCompilation() throws Exception { assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); ClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); - assertEquals("v1", l.loadClass("p.C1").newInstance().toString()); - assertEquals("v2", l.loadClass("p.C2").newInstance().toString()); + assertEquals("v1", l.loadClass("p.C1").getDeclaredConstructor().newInstance().toString()); + assertEquals("v2", l.loadClass("p.C2").getDeclaredConstructor().newInstance().toString()); AnnotationProcessorTestUtils.makeSource(src, "p.C1", "@org.openide.util.NbBundle.Messages(\"k1=v3\")", "public class C1 {public @Override String toString() {return Bundle.k1();}}"); assertTrue(AnnotationProcessorTestUtils.runJavac(src, "C1.java", dest, null, null)); l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); - assertEquals("v3", l.loadClass("p.C1").newInstance().toString()); - assertEquals("v2", l.loadClass("p.C2").newInstance().toString()); + assertEquals("v3", l.loadClass("p.C1").getDeclaredConstructor().newInstance().toString()); + assertEquals("v2", l.loadClass("p.C2").getDeclaredConstructor().newInstance().toString()); AnnotationProcessorTestUtils.makeSource(src, "p.C1", "@org.openide.util.NbBundle.Messages(\"k3=v4\")", "public class C1 {public @Override String toString() {return Bundle.k3();}}"); assertTrue(AnnotationProcessorTestUtils.runJavac(src, "C1.java", dest, null, null)); l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); - assertEquals("v4", l.loadClass("p.C1").newInstance().toString()); - assertEquals("v2", l.loadClass("p.C2").newInstance().toString()); + assertEquals("v4", l.loadClass("p.C1").getDeclaredConstructor().newInstance().toString()); + assertEquals("v2", l.loadClass("p.C2").getDeclaredConstructor().newInstance().toString()); } public void testIncrementalCompilationWithBrokenClassFiles() throws Exception { @@ -230,16 +230,16 @@ public void testIncrementalCompilationWithBrokenClassFiles() throws Exception { assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); ClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); - assertEquals("v1", l.loadClass("p.C1").newInstance().toString()); - assertEquals("v2", l.loadClass("p.C2").newInstance().toString()); + assertEquals("v1", l.loadClass("p.C1").getDeclaredConstructor().newInstance().toString()); + assertEquals("v2", l.loadClass("p.C2").getDeclaredConstructor().newInstance().toString()); assertTrue(new File(dest, "p/C3.class").delete()); assertTrue(new File(dest, "p/C3$1.class").delete()); assertTrue(new File(dest, "p/C3$1$1.class").isFile()); AnnotationProcessorTestUtils.makeSource(src, "p.C1", "@org.openide.util.NbBundle.Messages(\"k1=v3\")", "public class C1 {public @Override String toString() {return Bundle.k1();}}"); assertTrue(AnnotationProcessorTestUtils.runJavac(src, "C1.java", dest, null, null)); l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); - assertEquals("v3", l.loadClass("p.C1").newInstance().toString()); - assertEquals("v2", l.loadClass("p.C2").newInstance().toString()); + assertEquals("v3", l.loadClass("p.C1").getDeclaredConstructor().newInstance().toString()); + assertEquals("v2", l.loadClass("p.C2").getDeclaredConstructor().newInstance().toString()); } public void testIncrementalCompilationWithPackageInfo() throws Exception { @@ -248,11 +248,11 @@ public void testIncrementalCompilationWithPackageInfo() throws Exception { assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); ClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); - assertEquals("v1v2", l.loadClass("p.C").newInstance().toString()); + assertEquals("v1v2", l.loadClass("p.C").getDeclaredConstructor().newInstance().toString()); assertTrue(new File(dest, "p/C.class").delete()); assertTrue(AnnotationProcessorTestUtils.runJavac(src, "C.java", dest, null, null)); l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); - assertEquals("v1v2", l.loadClass("p.C").newInstance().toString()); + assertEquals("v1v2", l.loadClass("p.C").getDeclaredConstructor().newInstance().toString()); } public void testComments() throws Exception { diff --git a/platform/openide.util/src/org/openide/util/NbBundle.java b/platform/openide.util/src/org/openide/util/NbBundle.java index e66b3fc11044..b3235ddadf05 100644 --- a/platform/openide.util/src/org/openide/util/NbBundle.java +++ b/platform/openide.util/src/org/openide/util/NbBundle.java @@ -602,7 +602,7 @@ private static ResourceBundle loadBundleClass( for (String suffix : suffixes) { try { Class c = Class.forName(name + suffix, true, l).asSubclass(ResourceBundle.class); - ResourceBundle b = c.newInstance(); + ResourceBundle b = c.getDeclaredConstructor().newInstance(); if (master == null) { master = b; diff --git a/platform/sendopts/src/org/netbeans/api/sendopts/CommandLine.java b/platform/sendopts/src/org/netbeans/api/sendopts/CommandLine.java index 314402281e7c..5c5ac6e57a11 100644 --- a/platform/sendopts/src/org/netbeans/api/sendopts/CommandLine.java +++ b/platform/sendopts/src/org/netbeans/api/sendopts/CommandLine.java @@ -93,7 +93,7 @@ public static CommandLine create(Object... instances) { } private static CommandLine createImpl(Object[] instances) { - List arr = new ArrayList(); + List arr = new ArrayList<>(); for (Object o : instances) { Class c; Object instance; @@ -107,12 +107,10 @@ private static CommandLine createImpl(Object[] instances) { if (OptionProcessor.class.isAssignableFrom(c)) { try { if (instance == null) { - instance = c.newInstance(); + instance = c.getDeclaredConstructor().newInstance(); } arr.add((OptionProcessor) instance); - } catch (InstantiationException ex) { - throw new IllegalStateException(ex); - } catch (IllegalAccessException ex) { + } catch (ReflectiveOperationException ex) { throw new IllegalStateException(ex); } } else { diff --git a/platform/sendopts/src/org/netbeans/modules/sendopts/DefaultProcessor.java b/platform/sendopts/src/org/netbeans/modules/sendopts/DefaultProcessor.java index f1928b5fcefe..4e2e1ecc523c 100644 --- a/platform/sendopts/src/org/netbeans/modules/sendopts/DefaultProcessor.java +++ b/platform/sendopts/src/org/netbeans/modules/sendopts/DefaultProcessor.java @@ -156,7 +156,7 @@ protected void process(Env env, Map optionValues) throws Comma Object inst; if (instance == null) { realClazz = Class.forName(clazz, true, l); - inst = realClazz.newInstance(); + inst = realClazz.getDeclaredConstructor().newInstance(); } else { realClazz = instance.getClass(); inst = instance; diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/FmtOptions.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/FmtOptions.java index 6a21b86a36cc..8780ab37a8dc 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/FmtOptions.java +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/FmtOptions.java @@ -634,8 +634,8 @@ public Factory(String mimeType, String id, Class panelClass, @Override public PreferencesCustomizer create(Preferences preferences) { try { - return new CategorySupport(mimeType, provider, preferences, id, panelClass.newInstance(), previewText, forcedOptions); - } catch (RuntimeException | IllegalAccessException | InstantiationException e) { + return new CategorySupport(mimeType, provider, preferences, id, panelClass.getDeclaredConstructor().newInstance(), previewText, forcedOptions); + } catch (RuntimeException | ReflectiveOperationException e) { LOGGER.log(Level.WARNING, "Exception during creating formatter customiezer", e); return null; } diff --git a/webcommon/libs.graaljs/test/unit/src/org/netbeans/libs/graaljs/GraalJSTest2.java b/webcommon/libs.graaljs/test/unit/src/org/netbeans/libs/graaljs/GraalJSTest2.java index 5a8b6ff3bd1c..b93e78f76024 100644 --- a/webcommon/libs.graaljs/test/unit/src/org/netbeans/libs/graaljs/GraalJSTest2.java +++ b/webcommon/libs.graaljs/test/unit/src/org/netbeans/libs/graaljs/GraalJSTest2.java @@ -127,7 +127,7 @@ public void testDirectEvaluationOfGraalJS() throws Exception { // the test code itself HAS to use the module system to load appropriate Engine. URL u = getClass().getProtectionDomain().getCodeSource().getLocation(); ClassLoader ldr2 = new URLClassLoader(new URL[] { u }, ldr); - Callable c = (Callable)ldr2.loadClass(getClass().getName() + "$T").newInstance(); + Callable c = (Callable)ldr2.loadClass(getClass().getName() + "$T").getDeclaredConstructor().newInstance(); c.call(); }