Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2019-02-13 15:37:55 +0000
committerThomas Watson2019-02-13 15:37:55 +0000
commit49b8041da50c34fe143e425622e5e308572449fc (patch)
treeaefc4ea056889527c2ac3ba575ef9280771b3d8c
parent3e6b090cd7220aa3f733ea9a3cb34412b500cb6e (diff)
downloadrt.equinox.framework-49b8041da50c34fe143e425622e5e308572449fc.tar.gz
rt.equinox.framework-49b8041da50c34fe143e425622e5e308572449fc.tar.xz
rt.equinox.framework-49b8041da50c34fe143e425622e5e308572449fc.zip
Bug 544247 - Replace deprecated method calls to Class.newInstance()
Change-Id: I23a35632bd5ca673787549fbb1949008ac26846f Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/BundleContextImpl.java5
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java25
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/HookRegistry.java2
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/service/resolver/StateObjectFactory.java29
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java2
5 files changed, 32 insertions, 31 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/BundleContextImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/BundleContextImpl.java
index 93004f200..32e6f85f0 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/BundleContextImpl.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/BundleContextImpl.java
@@ -17,6 +17,7 @@ package org.eclipse.osgi.internal.framework;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
import java.net.URLConnection;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -776,7 +777,7 @@ public class BundleContextImpl implements BundleContext, EventDispatcher<Object,
same activator object when we stop this bundle. */
}
- private BundleActivator loadBundleActivator() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+ private BundleActivator loadBundleActivator() throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
ModuleWiring wiring = bundle.getModule().getCurrentRevision().getWiring();
if (wiring == null) {
return null;
@@ -795,7 +796,7 @@ public class BundleContextImpl implements BundleContext, EventDispatcher<Object,
return null;
}
Class<?> activatorClass = loader.findClass(activatorName);
- return (BundleActivator) activatorClass.newInstance();
+ return (BundleActivator) activatorClass.getConstructor().newInstance();
}
/**
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java
index 0357b1272..0a3d865d5 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java
@@ -14,7 +14,10 @@
package org.eclipse.osgi.internal.framework;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
import org.apache.felix.resolver.Logger;
import org.apache.felix.resolver.ResolverImpl;
import org.eclipse.osgi.internal.debug.Debug;
@@ -32,7 +35,11 @@ import org.eclipse.osgi.service.urlconversion.URLConverter;
import org.eclipse.osgi.storage.BundleLocalizationImpl;
import org.eclipse.osgi.storage.url.BundleResourceHandler;
import org.eclipse.osgi.storage.url.BundleURLConverter;
-import org.osgi.framework.*;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.permissionadmin.PermissionAdmin;
@@ -132,19 +139,11 @@ public class SystemBundleActivator implements BundleActivator {
// try to use a specific classloader by classname
try {
Class<?> clazz = Class.forName(securityManager);
- sm = (SecurityManager) clazz.newInstance();
- } catch (ClassNotFoundException e) {
- // do nothing
- } catch (ClassCastException e) {
- // do nothing
- } catch (InstantiationException e) {
- // do nothing
- } catch (IllegalAccessException e) {
- // do nothing
+ sm = (SecurityManager) clazz.getConstructor().newInstance();
+ } catch (Throwable t) {
+ throw new BundleException("Failed to create security manager", t); //$NON-NLS-1$
}
}
- if (sm == null)
- throw new NoClassDefFoundError(securityManager);
if (configuration.getDebug().DEBUG_SECURITY)
Debug.println("Setting SecurityManager to: " + sm); //$NON-NLS-1$
System.setSecurityManager(sm);
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/HookRegistry.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/HookRegistry.java
index 034480d49..491059664 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/HookRegistry.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/HookRegistry.java
@@ -193,7 +193,7 @@ public final class HookRegistry {
String hookName = iHooks.next();
try {
Class<?> clazz = Class.forName(hookName);
- HookConfigurator configurator = (HookConfigurator) clazz.newInstance();
+ HookConfigurator configurator = (HookConfigurator) clazz.getConstructor().newInstance();
configurator.addHooks(this);
} catch (Throwable t) {
// We expect the follow exeptions may happen; but we need to catch all here
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/service/resolver/StateObjectFactory.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/service/resolver/StateObjectFactory.java
index 80e78912a..7b685e1fe 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/service/resolver/StateObjectFactory.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/service/resolver/StateObjectFactory.java
@@ -13,9 +13,18 @@
*******************************************************************************/
package org.eclipse.osgi.service.resolver;
-import java.io.*;
-import java.util.*;
-import org.osgi.framework.*;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Dictionary;
+import java.util.List;
+import java.util.Map;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.Version;
/**
* A factory for states and their component objects.
@@ -494,19 +503,11 @@ public interface StateObjectFactory {
private StateObjectFactory getImplementation() {
synchronized (this.monitor) {
if (implementation == null) {
- Exception error = null;
try {
Class<?> implClass = Class.forName(IMPL_NAME);
- implementation = (StateObjectFactory) implClass.newInstance();
- } catch (ClassNotFoundException e) {
- error = e;
- } catch (InstantiationException e) {
- error = e;
- } catch (IllegalAccessException e) {
- error = e;
- }
- if (error != null) {
- throw new UnsupportedOperationException("Not able to create StateObjectFactory implementation: " + IMPL_NAME, error); //$NON-NLS-1$
+ implementation = (StateObjectFactory) implClass.getConstructor().newInstance();
+ } catch (Throwable t) {
+ throw new UnsupportedOperationException("Not able to create StateObjectFactory implementation: " + IMPL_NAME, t); //$NON-NLS-1$
}
}
return implementation;
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java
index c54dc4cab..66542b93e 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java
@@ -243,7 +243,7 @@ public class FrameworkExtensionInstaller {
BundleActivator activator = null;
try {
Class<?> activatorClass = Class.forName(activatorName);
- activator = (BundleActivator) activatorClass.newInstance();
+ activator = (BundleActivator) activatorClass.getConstructor().newInstance();
startActivator(activator, context, extensionRevision.getBundle());
} catch (Throwable e) {
BundleException eventException;

Back to the top