6850612: Deprecate Class.newInstance since it violates the checked exception language contract

Reviewed-by: lancea, mullan, dfuchs
This commit is contained in:
Joe Darcy 2016-05-03 10:40:54 -07:00
parent e8cd76568d
commit 01ee88c8ae
71 changed files with 272 additions and 157 deletions

View file

@ -470,7 +470,7 @@ public final class Class<T> implements java.io.Serializable,
* expression with an empty argument list. The class is initialized if it * expression with an empty argument list. The class is initialized if it
* has not already been initialized. * has not already been initialized.
* *
* <p>Note that this method propagates any exception thrown by the * @deprecated This method propagates any exception thrown by the
* nullary constructor, including a checked exception. Use of * nullary constructor, including a checked exception. Use of
* this method effectively bypasses the compile-time exception * this method effectively bypasses the compile-time exception
* checking that would otherwise be performed by the compiler. * checking that would otherwise be performed by the compiler.
@ -500,6 +500,7 @@ public final class Class<T> implements java.io.Serializable,
* of this class. * of this class.
*/ */
@CallerSensitive @CallerSensitive
@Deprecated(since="9")
public T newInstance() public T newInstance()
throws InstantiationException, IllegalAccessException throws InstantiationException, IllegalAccessException
{ {

View file

@ -1645,7 +1645,9 @@ class InetAddress implements java.io.Serializable {
*/ */
String prefix = GetPropertyAction.privilegedGetProperty("impl.prefix", ""); String prefix = GetPropertyAction.privilegedGetProperty("impl.prefix", "");
try { try {
impl = Class.forName("java.net." + prefix + implName).newInstance(); @SuppressWarnings("deprecation")
Object tmp = Class.forName("java.net." + prefix + implName).newInstance();
impl = tmp;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
System.err.println("Class not found: java.net." + prefix + System.err.println("Class not found: java.net." + prefix +
implName + ":\ncheck impl.prefix property " + implName + ":\ncheck impl.prefix property " +
@ -1662,7 +1664,9 @@ class InetAddress implements java.io.Serializable {
if (impl == null) { if (impl == null) {
try { try {
impl = Class.forName(implName).newInstance(); @SuppressWarnings("deprecation")
Object tmp = Class.forName(implName).newInstance();
impl = tmp;
} catch (Exception e) { } catch (Exception e) {
throw new Error("System property impl.prefix incorrect"); throw new Error("System property impl.prefix incorrect");
} }

View file

@ -71,7 +71,9 @@ public abstract class ProxySelector {
try { try {
Class<?> c = Class.forName("sun.net.spi.DefaultProxySelector"); Class<?> c = Class.forName("sun.net.spi.DefaultProxySelector");
if (c != null && ProxySelector.class.isAssignableFrom(c)) { if (c != null && ProxySelector.class.isAssignableFrom(c)) {
theProxySelector = (ProxySelector) c.newInstance(); @SuppressWarnings("deprecation")
ProxySelector tmp = (ProxySelector) c.newInstance();
theProxySelector = tmp;
} }
} catch (Exception e) { } catch (Exception e) {
theProxySelector = null; theProxySelector = null;

View file

@ -1198,8 +1198,9 @@ public final class URL implements java.io.Serializable {
public URLStreamHandler createURLStreamHandler(String protocol) { public URLStreamHandler createURLStreamHandler(String protocol) {
String name = PREFIX + "." + protocol + ".Handler"; String name = PREFIX + "." + protocol + ".Handler";
try { try {
Class<?> c = Class.forName(name); @SuppressWarnings("deprecation")
return (URLStreamHandler)c.newInstance(); Object o = Class.forName(name).newInstance();
return (URLStreamHandler)o;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException x) {
// ignore // ignore
} catch (Exception e) { } catch (Exception e) {
@ -1234,7 +1235,9 @@ public final class URL implements java.io.Serializable {
} }
} }
if (cls != null) { if (cls != null) {
handler = (URLStreamHandler)cls.newInstance(); @SuppressWarnings("deprecation")
Object tmp = cls.newInstance();
handler = (URLStreamHandler)tmp;
} }
} catch (Exception e) { } catch (Exception e) {
// any number of exceptions can get thrown here // any number of exceptions can get thrown here

View file

@ -1323,7 +1323,9 @@ public abstract class URLConnection {
} }
} }
if (cls != null) { if (cls != null) {
return (ContentHandler) cls.newInstance(); @SuppressWarnings("deprecation")
Object tmp = cls.newInstance();
return (ContentHandler) tmp;
} }
} catch(Exception ignored) { } } catch(Exception ignored) { }
} }

View file

@ -94,9 +94,10 @@ public abstract class AsynchronousChannelProvider {
if (cn == null) if (cn == null)
return null; return null;
try { try {
Class<?> c = Class.forName(cn, true, @SuppressWarnings("deprecation")
ClassLoader.getSystemClassLoader()); Object tmp = Class.forName(cn, true,
return (AsynchronousChannelProvider)c.newInstance(); ClassLoader.getSystemClassLoader()).newInstance();
return (AsynchronousChannelProvider)tmp;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException x) {
throw new ServiceConfigurationError(null, x); throw new ServiceConfigurationError(null, x);
} catch (IllegalAccessException x) { } catch (IllegalAccessException x) {

View file

@ -95,9 +95,10 @@ public abstract class SelectorProvider {
if (cn == null) if (cn == null)
return false; return false;
try { try {
Class<?> c = Class.forName(cn, true, @SuppressWarnings("deprecation")
ClassLoader.getSystemClassLoader()); Object tmp = Class.forName(cn, true,
provider = (SelectorProvider)c.newInstance(); ClassLoader.getSystemClassLoader()).newInstance();
provider = (SelectorProvider)tmp;
return true; return true;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException x) {
throw new ServiceConfigurationError(null, x); throw new ServiceConfigurationError(null, x);

View file

@ -222,8 +222,9 @@ public abstract class Policy {
public Policy run() { public Policy run() {
try { try {
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Class<?> c = Class.forName(policyProvider, true, scl); @SuppressWarnings("deprecation")
return (Policy)c.newInstance(); Object o = Class.forName(policyProvider, true, scl).newInstance();
return (Policy)o;
} catch (Exception e) { } catch (Exception e) {
if (debug != null) { if (debug != null) {
debug.println("policy provider " + policyProvider + debug.println("policy provider " + policyProvider +

View file

@ -147,6 +147,7 @@ public abstract class ZoneRulesProvider {
if (prop != null) { if (prop != null) {
try { try {
Class<?> c = Class.forName(prop, true, ClassLoader.getSystemClassLoader()); Class<?> c = Class.forName(prop, true, ClassLoader.getSystemClassLoader());
@SuppressWarnings("deprecation")
ZoneRulesProvider provider = ZoneRulesProvider.class.cast(c.newInstance()); ZoneRulesProvider provider = ZoneRulesProvider.class.cast(c.newInstance());
registerProvider(provider); registerProvider(provider);
loaded.add(provider); loaded.add(provider);

View file

@ -811,7 +811,9 @@ public final class ServiceLoader<S>
} }
S p = null; S p = null;
try { try {
p = service.cast(c.newInstance()); @SuppressWarnings("deprecation")
Object tmp = c.newInstance();
p = service.cast(tmp);
} catch (Throwable x) { } catch (Throwable x) {
fail(service, fail(service,
"Provider " + cn + " could not be instantiated", "Provider " + cn + " could not be instantiated",

View file

@ -3507,6 +3507,7 @@ public class ForkJoinPool extends AbstractExecutorService {
* Creates and returns the common pool, respecting user settings * Creates and returns the common pool, respecting user settings
* specified via system properties. * specified via system properties.
*/ */
@SuppressWarnings("deprecation") // Class.newInstance
static ForkJoinPool makeCommonPool() { static ForkJoinPool makeCommonPool() {
int parallelism = -1; int parallelism = -1;
ForkJoinWorkerThreadFactory factory = null; ForkJoinWorkerThreadFactory factory = null;

View file

@ -704,7 +704,9 @@ public abstract class Pack200 {
impl = com.sun.java.util.jar.pack.UnpackerImpl.class; impl = com.sun.java.util.jar.pack.UnpackerImpl.class;
} }
// We have a class. Now instantiate it. // We have a class. Now instantiate it.
return impl.newInstance(); @SuppressWarnings("deprecation")
Object result = impl.newInstance();
return result;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new Error("Class not found: " + implName + throw new Error("Class not found: " + implName +
":\ncheck property " + prop + ":\ncheck property " + prop +

View file

@ -97,6 +97,7 @@ public abstract class SSLServerSocketFactory extends ServerSocketFactory
} }
} }
log("class " + clsName + " is loaded"); log("class " + clsName + " is loaded");
@SuppressWarnings("deprecation")
SSLServerSocketFactory fac = (SSLServerSocketFactory)cls.newInstance(); SSLServerSocketFactory fac = (SSLServerSocketFactory)cls.newInstance();
log("instantiated an instance of class " + clsName); log("instantiated an instance of class " + clsName);
theFactory = fac; theFactory = fac;

View file

@ -106,6 +106,7 @@ public abstract class SSLSocketFactory extends SocketFactory
} }
} }
log("class " + clsName + " is loaded"); log("class " + clsName + " is loaded");
@SuppressWarnings("deprecation")
SSLSocketFactory fac = (SSLSocketFactory)cls.newInstance(); SSLSocketFactory fac = (SSLSocketFactory)cls.newInstance();
log("instantiated an instance of class " + clsName); log("instantiated an instance of class " + clsName);
theFactory = fac; theFactory = fac;

View file

@ -250,7 +250,9 @@ public abstract class Configuration {
finalClass, false, finalClass, false,
Thread.currentThread().getContextClassLoader() Thread.currentThread().getContextClassLoader()
).asSubclass(Configuration.class); ).asSubclass(Configuration.class);
return implClass.newInstance(); @SuppressWarnings("deprecation")
Configuration result = implClass.newInstance();
return result;
} }
}); });
AccessController.doPrivileged( AccessController.doPrivileged(

View file

@ -304,7 +304,9 @@ public class LoginContext {
Class<? extends CallbackHandler> c = Class.forName( Class<? extends CallbackHandler> c = Class.forName(
defaultHandler, true, defaultHandler, true,
finalLoader).asSubclass(CallbackHandler.class); finalLoader).asSubclass(CallbackHandler.class);
return c.newInstance(); @SuppressWarnings("deprecation")
CallbackHandler result = c.newInstance();
return result;
} }
}); });
} catch (java.security.PrivilegedActionException pae) { } catch (java.security.PrivilegedActionException pae) {
@ -697,8 +699,9 @@ public class LoginContext {
if (moduleStack[i].module == null) { if (moduleStack[i].module == null) {
try { try {
moduleStack[i].module = (LoginModule) Class.forName( @SuppressWarnings("deprecation")
name, false, contextClassLoader).newInstance(); Object tmp = Class.forName(name, false, contextClassLoader).newInstance();
moduleStack[i].module = (LoginModule) tmp;
if (debug != null) { if (debug != null) {
debug.println(name + " loaded via reflection"); debug.println(name + " loaded via reflection");
} }

View file

@ -124,7 +124,9 @@ public final class JrtFileSystemProvider extends FileSystemProvider {
ClassLoader cl = newJrtFsLoader(jrtfs); ClassLoader cl = newJrtFsLoader(jrtfs);
try { try {
Class<?> c = Class.forName(JrtFileSystemProvider.class.getName(), false, cl); Class<?> c = Class.forName(JrtFileSystemProvider.class.getName(), false, cl);
return ((FileSystemProvider)c.newInstance()).newFileSystem(uri, newEnv); @SuppressWarnings("deprecation")
Object tmp = c.newInstance();
return ((FileSystemProvider)tmp).newFileSystem(uri, newEnv);
} catch (ClassNotFoundException | } catch (ClassNotFoundException |
IllegalAccessException | IllegalAccessException |
InstantiationException e) { InstantiationException e) {

View file

@ -392,6 +392,7 @@ class MethodAccessorGenerator extends AccessorGenerator {
// matter. // matter.
return AccessController.doPrivileged( return AccessController.doPrivileged(
new PrivilegedAction<MagicAccessorImpl>() { new PrivilegedAction<MagicAccessorImpl>() {
@SuppressWarnings("deprecation") // Class.newInstance
public MagicAccessorImpl run() { public MagicAccessorImpl run() {
try { try {
return (MagicAccessorImpl) return (MagicAccessorImpl)

View file

@ -67,8 +67,9 @@ public abstract class FtpClientProvider {
return false; return false;
} }
try { try {
Class<?> c = Class.forName(cm, true, null); @SuppressWarnings("deprecation")
provider = (FtpClientProvider) c.newInstance(); Object o = Class.forName(cm, true, null).newInstance();
provider = (FtpClientProvider)o;
return true; return true;
} catch (ClassNotFoundException | } catch (ClassNotFoundException |
IllegalAccessException | IllegalAccessException |

View file

@ -165,14 +165,11 @@ public class ThreadPool {
GetPropertyAction(DEFAULT_THREAD_POOL_THREAD_FACTORY)); GetPropertyAction(DEFAULT_THREAD_POOL_THREAD_FACTORY));
if (propValue != null) { if (propValue != null) {
try { try {
Class<?> c = Class @SuppressWarnings("deprecation")
.forName(propValue, true, ClassLoader.getSystemClassLoader()); Object tmp = Class
return ((ThreadFactory)c.newInstance()); .forName(propValue, true, ClassLoader.getSystemClassLoader()).newInstance();
} catch (ClassNotFoundException x) { return (ThreadFactory)tmp;
throw new Error(x); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException x) {
} catch (InstantiationException x) {
throw new Error(x);
} catch (IllegalAccessException x) {
throw new Error(x); throw new Error(x);
} }
} }

View file

@ -115,10 +115,11 @@ public class FastCharsetProvider
// Instantiate the charset and cache it // Instantiate the charset and cache it
try { try {
Class<?> c = Class.forName(packagePrefix + "." + cln, @SuppressWarnings("deprecation")
Object o= Class.forName(packagePrefix + "." + cln,
true, true,
this.getClass().getClassLoader()); this.getClass().getClassLoader()).newInstance();
cs = (Charset)c.newInstance(); cs = (Charset)o;
cache.put(csn, cs); cache.put(csn, cs);
return cs; return cs;
} catch (ClassNotFoundException | } catch (ClassNotFoundException |

View file

@ -110,10 +110,11 @@ public class StandardCharsets extends CharsetProvider {
// Instantiate the charset and cache it // Instantiate the charset and cache it
try { try {
Class<?> c = Class.forName(packagePrefix + "." + cln, @SuppressWarnings("deprecation")
Object o = Class.forName(packagePrefix + "." + cln,
true, true,
this.getClass().getClassLoader()); this.getClass().getClassLoader()).newInstance();
cs = (Charset)c.newInstance(); cs = (Charset)o;
cache.put(csn, cs); cache.put(csn, cs);
return cs; return cs;
} catch (ClassNotFoundException | } catch (ClassNotFoundException |

View file

@ -185,7 +185,9 @@ final class ProviderConfig {
try { try {
Class<?> c = Class.forName("apple.security.AppleProvider"); Class<?> c = Class.forName("apple.security.AppleProvider");
if (Provider.class.isAssignableFrom(c)) { if (Provider.class.isAssignableFrom(c)) {
return (Provider) c.newInstance(); @SuppressWarnings("deprecation")
Object tmp = c.newInstance();
return (Provider) tmp;
} else { } else {
return null; return null;
} }
@ -386,6 +388,7 @@ final class ProviderConfig {
Provider p = AccessController.doPrivileged Provider p = AccessController.doPrivileged
(new PrivilegedExceptionAction<Provider>() { (new PrivilegedExceptionAction<Provider>() {
@SuppressWarnings("deprecation") // Class.newInstance
public Provider run() throws Exception { public Provider run() throws Exception {
return (Provider) provClass.newInstance(); return (Provider) provClass.newInstance();
} }

View file

@ -218,11 +218,10 @@ public class PKCS8Key implements PrivateKey {
} }
} }
Object inst = null; @SuppressWarnings("deprecation")
Object inst = (keyClass != null) ? keyClass.newInstance() : null;
PKCS8Key result; PKCS8Key result;
if (keyClass != null)
inst = keyClass.newInstance();
if (inst instanceof PKCS8Key) { if (inst instanceof PKCS8Key) {
result = (PKCS8Key) inst; result = (PKCS8Key) inst;
result.algid = algid; result.algid = algid;

View file

@ -728,6 +728,7 @@ public final class Main {
provClass = Class.forName(provName); provClass = Class.forName(provName);
} }
@SuppressWarnings("deprecation")
Object obj = provClass.newInstance(); Object obj = provClass.newInstance();
if (!(obj instanceof Provider)) { if (!(obj instanceof Provider)) {
MessageFormat form = new MessageFormat MessageFormat form = new MessageFormat

View file

@ -196,8 +196,9 @@ public class KeyStoreDelegator extends KeyStoreSpi {
// A new keystore is always created in the primary keystore format // A new keystore is always created in the primary keystore format
if (stream == null) { if (stream == null) {
try { try {
keystore = primaryKeyStore.newInstance(); @SuppressWarnings("deprecation")
KeyStoreSpi tmp = primaryKeyStore.newInstance();
keystore = tmp;
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException e) {
// can safely ignore // can safely ignore
} }
@ -214,7 +215,9 @@ public class KeyStoreDelegator extends KeyStoreSpi {
bufferedStream.mark(Integer.MAX_VALUE); bufferedStream.mark(Integer.MAX_VALUE);
try { try {
keystore = primaryKeyStore.newInstance(); @SuppressWarnings("deprecation")
KeyStoreSpi tmp = primaryKeyStore.newInstance();
keystore = tmp;
type = primaryType; type = primaryType;
keystore.engineLoad(bufferedStream, password); keystore.engineLoad(bufferedStream, password);
@ -232,7 +235,9 @@ public class KeyStoreDelegator extends KeyStoreSpi {
throw e; throw e;
} }
keystore = secondaryKeyStore.newInstance(); @SuppressWarnings("deprecation")
KeyStoreSpi tmp= secondaryKeyStore.newInstance();
keystore = tmp;
type = secondaryType; type = secondaryType;
bufferedStream.reset(); bufferedStream.reset();
keystore.engineLoad(bufferedStream, password); keystore.engineLoad(bufferedStream, password);
@ -284,7 +289,9 @@ public class KeyStoreDelegator extends KeyStoreSpi {
boolean result = false; boolean result = false;
try { try {
keystore = primaryKeyStore.newInstance(); @SuppressWarnings("deprecation")
KeyStoreSpi tmp = primaryKeyStore.newInstance();
keystore = tmp;
type = primaryType; type = primaryType;
result = keystore.engineProbe(stream); result = keystore.engineProbe(stream);

View file

@ -255,11 +255,10 @@ public class X509Key implements PublicKey {
} }
} }
Object inst = null; @SuppressWarnings("deprecation")
Object inst = (keyClass != null) ? keyClass.newInstance() : null;
X509Key result; X509Key result;
if (keyClass != null)
inst = keyClass.newInstance();
if (inst instanceof X509Key) { if (inst instanceof X509Key) {
result = (X509Key) inst; result = (X509Key) inst;
result.algid = algid; result.algid = algid;

View file

@ -157,8 +157,9 @@ public abstract class CalendarSystem {
cal = LocalGregorianCalendar.getLocalGregorianCalendar(calendarName); cal = LocalGregorianCalendar.getLocalGregorianCalendar(calendarName);
} else { } else {
try { try {
Class<?> cl = Class.forName(className); @SuppressWarnings("deprecation")
cal = (CalendarSystem) cl.newInstance(); Object tmp = Class.forName(className).newInstance();
cal = (CalendarSystem) tmp;
} catch (Exception e) { } catch (Exception e) {
throw new InternalError(e); throw new InternalError(e);
} }

View file

@ -171,8 +171,9 @@ public abstract class LocaleProviderAdapter {
if (cached == null) { if (cached == null) {
try { try {
// lazily load adapters here // lazily load adapters here
adapter = (LocaleProviderAdapter)Class.forName(type.getAdapterClassName()) @SuppressWarnings("deprecation")
.newInstance(); Object tmp = Class.forName(type.getAdapterClassName()).newInstance();
adapter = (LocaleProviderAdapter)tmp;
cached = adapterInstances.putIfAbsent(type, adapter); cached = adapterInstances.putIfAbsent(type, adapter);
if (cached != null) { if (cached != null) {
adapter = cached; adapter = cached;

View file

@ -73,7 +73,7 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
try { try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<P>() { return AccessController.doPrivileged(new PrivilegedExceptionAction<P>() {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings(value={"unchecked", "deprecation"})
public P run() { public P run() {
P delegate = null; P delegate = null;

View file

@ -61,7 +61,9 @@ class DefaultDatagramSocketImplFactory {
throws SocketException { throws SocketException {
if (prefixImplClass != null) { if (prefixImplClass != null) {
try { try {
return (DatagramSocketImpl)prefixImplClass.newInstance(); @SuppressWarnings("deprecation")
DatagramSocketImpl result = (DatagramSocketImpl)prefixImplClass.newInstance();
return result;
} catch (Exception e) { } catch (Exception e) {
throw new SocketException("can't instantiate DatagramSocketImpl"); throw new SocketException("can't instantiate DatagramSocketImpl");
} }

View file

@ -48,7 +48,9 @@ public class DefaultAsynchronousChannelProvider {
throw new AssertionError(x); throw new AssertionError(x);
} }
try { try {
return c.newInstance(); @SuppressWarnings("deprecation")
AsynchronousChannelProvider result = c.newInstance();
return result;
} catch (IllegalAccessException | InstantiationException x) { } catch (IllegalAccessException | InstantiationException x) {
throw new AssertionError(x); throw new AssertionError(x);
} }

View file

@ -44,7 +44,9 @@ public class DefaultFileSystemProvider {
throw new AssertionError(x); throw new AssertionError(x);
} }
try { try {
return c.newInstance(); @SuppressWarnings("deprecation")
FileSystemProvider result = c.newInstance();
return result;
} catch (IllegalAccessException | InstantiationException x) { } catch (IllegalAccessException | InstantiationException x) {
throw new AssertionError(x); throw new AssertionError(x);
} }

View file

@ -39,7 +39,9 @@ class FilterFactory {
List<HeaderFilter> l = new LinkedList<>(); List<HeaderFilter> l = new LinkedList<>();
for (Class<? extends HeaderFilter> clazz : filterClasses) { for (Class<? extends HeaderFilter> clazz : filterClasses) {
try { try {
l.add(clazz.newInstance()); @SuppressWarnings("deprecation")
HeaderFilter headerFilter = clazz.newInstance();
l.add(headerFilter);
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
throw new InternalError(e); throw new InternalError(e);
} }

View file

@ -231,13 +231,15 @@ public class LogManager {
cname = System.getProperty("java.util.logging.manager"); cname = System.getProperty("java.util.logging.manager");
if (cname != null) { if (cname != null) {
try { try {
Class<?> clz = ClassLoader.getSystemClassLoader() @SuppressWarnings("deprecation")
.loadClass(cname); Object tmp = ClassLoader.getSystemClassLoader()
mgr = (LogManager) clz.newInstance(); .loadClass(cname).newInstance();
mgr = (LogManager) tmp;
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
Class<?> clz = Thread.currentThread() @SuppressWarnings("deprecation")
.getContextClassLoader().loadClass(cname); Object tmp = Thread.currentThread()
mgr = (LogManager) clz.newInstance(); .getContextClassLoader().loadClass(cname).newInstance();
mgr = (LogManager) tmp;
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -991,8 +993,9 @@ public class LogManager {
List<Handler> handlers = new ArrayList<>(names.length); List<Handler> handlers = new ArrayList<>(names.length);
for (String type : names) { for (String type : names) {
try { try {
Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(type); @SuppressWarnings("deprecation")
Handler hdl = (Handler) clz.newInstance(); Object o = ClassLoader.getSystemClassLoader().loadClass(type).newInstance();
Handler hdl = (Handler) o;
// Check if there is a property defining the // Check if there is a property defining the
// this handler's level. // this handler's level.
String levs = getProperty(type + ".level"); String levs = getProperty(type + ".level");
@ -1330,11 +1333,13 @@ public class LogManager {
// calling readConfiguration(InputStream) with a suitable stream. // calling readConfiguration(InputStream) with a suitable stream.
try { try {
Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(cname); Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(cname);
clz.newInstance(); @SuppressWarnings("deprecation")
Object witness = clz.newInstance();
return; return;
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass(cname); Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass(cname);
clz.newInstance(); @SuppressWarnings("deprecation")
Object witness = clz.newInstance();
return; return;
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -1561,7 +1566,8 @@ public class LogManager {
for (String word : names) { for (String word : names) {
try { try {
Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(word); Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(word);
clz.newInstance(); @SuppressWarnings("deprecation")
Object witness = clz.newInstance();
} catch (Exception ex) { } catch (Exception ex) {
System.err.println("Can't load config class \"" + word + "\""); System.err.println("Can't load config class \"" + word + "\"");
System.err.println("" + ex); System.err.println("" + ex);
@ -2307,8 +2313,9 @@ public class LogManager {
String val = getProperty(name); String val = getProperty(name);
try { try {
if (val != null) { if (val != null) {
Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(val); @SuppressWarnings("deprecation")
return (Filter) clz.newInstance(); Object o = ClassLoader.getSystemClassLoader().loadClass(val).newInstance();
return (Filter) o;
} }
} catch (Exception ex) { } catch (Exception ex) {
// We got one of a variety of exceptions in creating the // We got one of a variety of exceptions in creating the
@ -2328,8 +2335,9 @@ public class LogManager {
String val = getProperty(name); String val = getProperty(name);
try { try {
if (val != null) { if (val != null) {
Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(val); @SuppressWarnings("deprecation")
return (Formatter) clz.newInstance(); Object o = ClassLoader.getSystemClassLoader().loadClass(val).newInstance();
return (Formatter) o;
} }
} catch (Exception ex) { } catch (Exception ex) {
// We got one of a variety of exceptions in creating the // We got one of a variety of exceptions in creating the

View file

@ -117,7 +117,9 @@ public class MemoryHandler extends Handler {
Class<?> clz; Class<?> clz;
try { try {
clz = ClassLoader.getSystemClassLoader().loadClass(targetName); clz = ClassLoader.getSystemClassLoader().loadClass(targetName);
target = (Handler) clz.newInstance(); @SuppressWarnings("deprecation")
Object o = clz.newInstance();
target = (Handler) o;
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new RuntimeException("MemoryHandler can't load handler target \"" + targetName + "\"" , e); throw new RuntimeException("MemoryHandler can't load handler target \"" + targetName + "\"" , e);
} }

View file

@ -655,7 +655,9 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory {
final Object[] openArray = (Object[]) openValue; final Object[] openArray = (Object[]) openValue;
final Collection<Object> valueCollection; final Collection<Object> valueCollection;
try { try {
valueCollection = cast(collectionClass.newInstance()); @SuppressWarnings("deprecation")
Collection<?> tmp = collectionClass.newInstance();
valueCollection = cast(tmp);
} catch (Exception e) { } catch (Exception e) {
throw invalidObjectException("Cannot create collection", e); throw invalidObjectException("Cannot create collection", e);
} }
@ -1114,7 +1116,9 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory {
try { try {
final Class<?> targetClass = getTargetClass(); final Class<?> targetClass = getTargetClass();
ReflectUtil.checkPackageAccess(targetClass); ReflectUtil.checkPackageAccess(targetClass);
o = targetClass.newInstance(); @SuppressWarnings("deprecation")
Object tmp = targetClass.newInstance();
o = tmp;
for (int i = 0; i < itemNames.length; i++) { for (int i = 0; i < itemNames.length; i++) {
if (cd.containsKey(itemNames[i])) { if (cd.containsKey(itemNames[i])) {
Object openItem = cd.get(itemNames[i]); Object openItem = cd.get(itemNames[i]);

View file

@ -458,6 +458,7 @@ public class MBeanServerFactory {
**/ **/
private static MBeanServerBuilder newBuilder(Class<?> builderClass) { private static MBeanServerBuilder newBuilder(Class<?> builderClass) {
try { try {
@SuppressWarnings("deprecation")
final Object abuilder = builderClass.newInstance(); final Object abuilder = builderClass.newInstance();
return (MBeanServerBuilder)abuilder; return (MBeanServerBuilder)abuilder;
} catch (RuntimeException x) { } catch (RuntimeException x) {

View file

@ -531,7 +531,9 @@ public class JMXConnectorFactory {
// We have just proved that this cast is correct // We have just proved that this cast is correct
Class<? extends T> providerClassT = Util.cast(providerClass); Class<? extends T> providerClassT = Util.cast(providerClass);
try { try {
return providerClassT.newInstance(); @SuppressWarnings("deprecation")
T result = providerClassT.newInstance();
return result;
} catch (Exception e) { } catch (Exception e) {
final String msg = final String msg =
"Exception when instantiating provider [" + className + "Exception when instantiating provider [" + className +

View file

@ -86,7 +86,9 @@ public final class FactoryEnumeration {
answer = cls; answer = cls;
} }
// Instantiate Class to get factory // Instantiate Class to get factory
answer = ((Class) answer).newInstance(); @SuppressWarnings("deprecation")
Object tmp = ((Class) answer).newInstance();
answer = tmp;
ref = new NamedWeakReference<>(answer, className); ref = new NamedWeakReference<>(answer, className);
factories.set(posn-1, ref); // replace Class object or null factories.set(posn-1, ref); // replace Class object or null
return answer; return answer;

View file

@ -399,7 +399,9 @@ public final class ResourceManager {
className = parser.nextToken() + classSuffix; className = parser.nextToken() + classSuffix;
try { try {
// System.out.println("loading " + className); // System.out.println("loading " + className);
factory = helper.loadClass(className, loader).newInstance(); @SuppressWarnings("deprecation") // Class.newInstance
Object tmp = helper.loadClass(className, loader).newInstance();
factory = tmp;
} catch (InstantiationException e) { } catch (InstantiationException e) {
NamingException ne = NamingException ne =
new NamingException("Cannot instantiate " + className); new NamingException("Cannot instantiate " + className);

View file

@ -192,18 +192,12 @@ public class StartTlsRequest implements ExtendedRequest {
} }
try { try {
VersionHelper helper = VersionHelper.getVersionHelper(); VersionHelper helper = VersionHelper.getVersionHelper();
Class<?> clas = helper.loadClass( @SuppressWarnings("deprecation")
"com.sun.jndi.ldap.ext.StartTlsResponseImpl"); Object o = helper.loadClass(
"com.sun.jndi.ldap.ext.StartTlsResponseImpl").newInstance();
resp = (StartTlsResponse) o;
resp = (StartTlsResponse) clas.newInstance(); } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
} catch (IllegalAccessException e) {
throw wrapException(e);
} catch (InstantiationException e) {
throw wrapException(e);
} catch (ClassNotFoundException e) {
throw wrapException(e); throw wrapException(e);
} }

View file

@ -159,7 +159,9 @@ public class NamingManager {
} }
} }
return (clas != null) ? (ObjectFactory) clas.newInstance() : null; @SuppressWarnings("deprecation") // Class.newInstance
ObjectFactory result = (clas != null) ? (ObjectFactory) clas.newInstance() : null;
return result;
} }
@ -710,8 +712,9 @@ public class NamingManager {
if (factory == null) { if (factory == null) {
try { try {
factory = (InitialContextFactory) @SuppressWarnings("deprecation")
helper.loadClass(className).newInstance(); Object o = helper.loadClass(className).newInstance();
factory = (InitialContextFactory) o;
} catch (Exception e) { } catch (Exception e) {
NoInitialContextException ne = NoInitialContextException ne =
new NoInitialContextException( new NoInitialContextException(

View file

@ -238,10 +238,11 @@ public abstract class Preferences {
// dependent on the invoking thread. // dependent on the invoking thread.
// Checking AllPermission also seems wrong. // Checking AllPermission also seems wrong.
try { try {
return (PreferencesFactory) @SuppressWarnings("deprecation")
Class.forName(factoryName, false, Object result =Class.forName(factoryName, false,
ClassLoader.getSystemClassLoader()) ClassLoader.getSystemClassLoader())
.newInstance(); .newInstance();
return (PreferencesFactory)result;
} catch (Exception ex) { } catch (Exception ex) {
try { try {
// workaround for javaws, plugin, // workaround for javaws, plugin,
@ -250,11 +251,12 @@ public abstract class Preferences {
if (sm != null) { if (sm != null) {
sm.checkPermission(new java.security.AllPermission()); sm.checkPermission(new java.security.AllPermission());
} }
return (PreferencesFactory) @SuppressWarnings("deprecation")
Class.forName(factoryName, false, Object result = Class.forName(factoryName, false,
Thread.currentThread() Thread.currentThread()
.getContextClassLoader()) .getContextClassLoader())
.newInstance(); .newInstance();
return (PreferencesFactory) result;
} catch (Exception e) { } catch (Exception e) {
throw new InternalError( throw new InternalError(
"Can't instantiate Preferences factory " "Can't instantiate Preferences factory "
@ -299,9 +301,10 @@ public abstract class Preferences {
platformFactory = "java.util.prefs.FileSystemPreferencesFactory"; platformFactory = "java.util.prefs.FileSystemPreferencesFactory";
} }
try { try {
return (PreferencesFactory) @SuppressWarnings("deprecation")
Class.forName(platformFactory, false, Object result = Class.forName(platformFactory, false,
Preferences.class.getClassLoader()).newInstance(); Preferences.class.getClassLoader()).newInstance();
return (PreferencesFactory) result;
} catch (Exception e) { } catch (Exception e) {
throw new InternalError( throw new InternalError(
"Can't instantiate platform default Preferences factory " "Can't instantiate platform default Preferences factory "

View file

@ -272,6 +272,7 @@ public class ActivationID implements Serializable {
Class<? extends RemoteRef> refClass = Class<? extends RemoteRef> refClass =
Class.forName(RemoteRef.packagePrefix + "." + in.readUTF()) Class.forName(RemoteRef.packagePrefix + "." + in.readUTF())
.asSubclass(RemoteRef.class); .asSubclass(RemoteRef.class);
@SuppressWarnings("deprecation")
RemoteRef ref = refClass.newInstance(); RemoteRef ref = refClass.newInstance();
ref.readExternal(in); ref.readExternal(in);
activator = (Activator) activator = (Activator)

View file

@ -681,7 +681,9 @@ public class RMIClassLoader {
Class.forName(providerClassName, false, Class.forName(providerClassName, false,
ClassLoader.getSystemClassLoader()) ClassLoader.getSystemClassLoader())
.asSubclass(RMIClassLoaderSpi.class); .asSubclass(RMIClassLoaderSpi.class);
return providerClass.newInstance(); @SuppressWarnings("deprecation")
RMIClassLoaderSpi result = providerClass.newInstance();
return result;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new NoClassDefFoundError(e.getMessage()); throw new NoClassDefFoundError(e.getMessage());

View file

@ -439,18 +439,16 @@ public abstract class RemoteObject implements Remote, java.io.Serializable {
RemoteRef.packagePrefix + "." + refClassName; RemoteRef.packagePrefix + "." + refClassName;
Class<?> refClass = Class.forName(internalRefClassName); Class<?> refClass = Class.forName(internalRefClassName);
try { try {
ref = (RemoteRef) refClass.newInstance(); @SuppressWarnings("deprecation")
Object tmp = refClass.newInstance();
ref = (RemoteRef) tmp;
/* /*
* If this step fails, assume we found an internal * If this step fails, assume we found an internal
* class that is not meant to be a serializable ref * class that is not meant to be a serializable ref
* type. * type.
*/ */
} catch (InstantiationException e) { } catch (InstantiationException | IllegalAccessException | ClassCastException e) {
throw new ClassNotFoundException(internalRefClassName, e);
} catch (IllegalAccessException e) {
throw new ClassNotFoundException(internalRefClassName, e);
} catch (ClassCastException e) {
throw new ClassNotFoundException(internalRefClassName, e); throw new ClassNotFoundException(internalRefClassName, e);
} }
ref.readExternal(in); ref.readExternal(in);

View file

@ -2066,7 +2066,9 @@ public class Activation implements Serializable {
try { try {
Class<?> execPolicyClass = getRMIClass(execPolicyClassName); Class<?> execPolicyClass = getRMIClass(execPolicyClassName);
execPolicy = execPolicyClass.newInstance(); @SuppressWarnings("deprecation")
Object tmp = execPolicyClass.newInstance();
execPolicy = tmp;
execPolicyMethod = execPolicyMethod =
execPolicyClass.getMethod("checkExecCommand", execPolicyClass.getMethod("checkExecCommand",
ActivationGroupDesc.class, ActivationGroupDesc.class,

View file

@ -111,8 +111,9 @@ public final class TerminalFactory {
type = "PC/SC"; type = "PC/SC";
Provider sun = Security.getProvider("SunPCSC"); Provider sun = Security.getProvider("SunPCSC");
if (sun == null) { if (sun == null) {
Class<?> clazz = Class.forName("sun.security.smartcardio.SunPCSC"); @SuppressWarnings("deprecation")
sun = (Provider)clazz.newInstance(); Object o = Class.forName("sun.security.smartcardio.SunPCSC").newInstance();
sun = (Provider)o;
} }
factory = TerminalFactory.getInstance(type, null, sun); factory = TerminalFactory.getInstance(type, null, sun);
} catch (Exception e) { } catch (Exception e) {

View file

@ -2962,7 +2962,9 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern
SQLData obj = null; SQLData obj = null;
try { try {
ReflectUtil.checkPackageAccess(c); ReflectUtil.checkPackageAccess(c);
obj = (SQLData) c.newInstance(); @SuppressWarnings("deprecation")
Object tmp = c.newInstance();
obj = (SQLData) tmp;
} catch(Exception ex) { } catch(Exception ex) {
throw new SQLException("Unable to Instantiate: ", ex); throw new SQLException("Unable to Instantiate: ", ex);
} }
@ -5710,7 +5712,9 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern
SQLData obj = null; SQLData obj = null;
try { try {
ReflectUtil.checkPackageAccess(c); ReflectUtil.checkPackageAccess(c);
obj = (SQLData) c.newInstance(); @SuppressWarnings("deprecation")
Object tmp = c.newInstance();
obj = (SQLData) tmp;
} catch(Exception ex) { } catch(Exception ex) {
throw new SQLException("Unable to Instantiate: ", ex); throw new SQLException("Unable to Instantiate: ", ex);
} }

View file

@ -574,7 +574,9 @@ public class CachedRowSetWriter implements TransactionalWriter, Serializable {
SQLData obj = null; SQLData obj = null;
try { try {
ReflectUtil.checkPackageAccess(c); ReflectUtil.checkPackageAccess(c);
obj = (SQLData)c.newInstance(); @SuppressWarnings("deprecation")
Object tmp = c.newInstance();
obj = (SQLData)tmp;
} catch (Exception ex) { } catch (Exception ex) {
throw new SQLException("Unable to Instantiate: ", ex); throw new SQLException("Unable to Instantiate: ", ex);
} }

View file

@ -136,8 +136,9 @@ public class RowSetProvider {
} }
// getFactoryClass takes care of adding the read edge if // getFactoryClass takes care of adding the read edge if
// necessary // necessary
Class<?> c = getFactoryClass(factoryClassName, null, false); @SuppressWarnings("deprecation")
factory = (RowSetFactory) c.newInstance(); Object o = getFactoryClass(factoryClassName, null, false).newInstance();
factory = (RowSetFactory) o;
} }
} catch (Exception e) { } catch (Exception e) {
throw new SQLException( "RowSetFactory: " + factoryClassName + throw new SQLException( "RowSetFactory: " + factoryClassName +
@ -202,6 +203,7 @@ public class RowSetProvider {
// getFactoryClass takes care of adding the read edge if // getFactoryClass takes care of adding the read edge if
// necessary // necessary
Class<?> providerClass = getFactoryClass(factoryClassName, cl, false); Class<?> providerClass = getFactoryClass(factoryClassName, cl, false);
@SuppressWarnings("deprecation")
RowSetFactory instance = (RowSetFactory) providerClass.newInstance(); RowSetFactory instance = (RowSetFactory) providerClass.newInstance();
if (debug) { if (debug) {
trace("Created new instance of " + providerClass + trace("Created new instance of " + providerClass +

View file

@ -478,7 +478,9 @@ public class SQLInputImpl implements SQLInput {
SQLData obj = null; SQLData obj = null;
try { try {
ReflectUtil.checkPackageAccess(c); ReflectUtil.checkPackageAccess(c);
obj = (SQLData)c.newInstance(); @SuppressWarnings("deprecation")
Object tmp = c.newInstance();
obj = (SQLData)tmp;
} catch (Exception ex) { } catch (Exception ex) {
throw new SQLException("Unable to Instantiate: ", ex); throw new SQLException("Unable to Instantiate: ", ex);
} }

View file

@ -582,14 +582,12 @@ public class SyncFactory {
* there. * there.
**/ **/
c = Class.forName(providerID, true, cl); c = Class.forName(providerID, true, cl);
return (SyncProvider) c.newInstance(); @SuppressWarnings("deprecation")
Object result = c.newInstance();
return (SyncProvider)result;
} catch (IllegalAccessException e) { } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
throw new SyncFactoryException("IllegalAccessException: " + e.getMessage()); throw new SyncFactoryException("IllegalAccessException: " + e.getMessage());
} catch (InstantiationException e) {
throw new SyncFactoryException("InstantiationException: " + e.getMessage());
} catch (ClassNotFoundException e) {
throw new SyncFactoryException("ClassNotFoundException: " + e.getMessage());
} }
} }

View file

@ -152,7 +152,9 @@ public class SignatureAlgorithm extends Algorithm {
log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \"" log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \""
+ implementingClass + "\""); + implementingClass + "\"");
} }
return implementingClass.newInstance(); @SuppressWarnings("deprecation")
SignatureAlgorithmSpi result = implementingClass.newInstance();
return result;
} catch (IllegalAccessException ex) { } catch (IllegalAccessException ex) {
Object exArgs[] = { algorithmURI, ex.getMessage() }; Object exArgs[] = { algorithmURI, ex.getMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs, ex); throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs, ex);

View file

@ -115,7 +115,9 @@ public class Canonicalizer {
Class<? extends CanonicalizerSpi> implementingClass = Class<? extends CanonicalizerSpi> implementingClass =
canonicalizerHash.get(algorithmURI); canonicalizerHash.get(algorithmURI);
canonicalizerSpi = implementingClass.newInstance(); @SuppressWarnings("deprecation")
CanonicalizerSpi tmp = implementingClass.newInstance();
canonicalizerSpi = tmp;
canonicalizerSpi.reset = true; canonicalizerSpi.reset = true;
} catch (Exception e) { } catch (Exception e) {
Object exArgs[] = { algorithmURI }; Object exArgs[] = { algorithmURI };

View file

@ -182,6 +182,7 @@ public class KeyResolver {
public static void register(String className, boolean globalResolver) public static void register(String className, boolean globalResolver)
throws ClassNotFoundException, IllegalAccessException, InstantiationException { throws ClassNotFoundException, IllegalAccessException, InstantiationException {
JavaUtils.checkRegisterPermission(); JavaUtils.checkRegisterPermission();
@SuppressWarnings("deprecation")
KeyResolverSpi keyResolverSpi = KeyResolverSpi keyResolverSpi =
(KeyResolverSpi) Class.forName(className).newInstance(); (KeyResolverSpi) Class.forName(className).newInstance();
keyResolverSpi.setGlobalResolver(globalResolver); keyResolverSpi.setGlobalResolver(globalResolver);
@ -207,7 +208,9 @@ public class KeyResolver {
KeyResolverSpi keyResolverSpi = null; KeyResolverSpi keyResolverSpi = null;
Exception ex = null; Exception ex = null;
try { try {
keyResolverSpi = (KeyResolverSpi) Class.forName(className).newInstance(); @SuppressWarnings("deprecation")
Object tmp = Class.forName(className).newInstance();
keyResolverSpi = (KeyResolverSpi) tmp;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
ex = e; ex = e;
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -272,6 +275,7 @@ public class KeyResolver {
JavaUtils.checkRegisterPermission(); JavaUtils.checkRegisterPermission();
List<KeyResolver> keyResolverList = new ArrayList<KeyResolver>(classNames.size()); List<KeyResolver> keyResolverList = new ArrayList<KeyResolver>(classNames.size());
for (String className : classNames) { for (String className : classNames) {
@SuppressWarnings("deprecation")
KeyResolverSpi keyResolverSpi = KeyResolverSpi keyResolverSpi =
(KeyResolverSpi) Class.forName(className).newInstance(); (KeyResolverSpi) Class.forName(className).newInstance();
keyResolverSpi.setGlobalResolver(false); keyResolverSpi.setGlobalResolver(false);

View file

@ -110,7 +110,9 @@ public abstract class KeyResolverSpi {
KeyResolverSpi tmp = this; KeyResolverSpi tmp = this;
if (globalResolver) { if (globalResolver) {
try { try {
tmp = getClass().newInstance(); @SuppressWarnings("deprecation")
KeyResolverSpi krs = getClass().newInstance();
tmp = krs;
} catch (InstantiationException e) { } catch (InstantiationException e) {
throw new KeyResolverException("", e); throw new KeyResolverException("", e);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {

View file

@ -160,7 +160,9 @@ public final class Transform extends SignatureElementProxy {
throw new InvalidTransformException("signature.Transform.UnknownTransform", exArgs); throw new InvalidTransformException("signature.Transform.UnknownTransform", exArgs);
} }
try { try {
transformSpi = transformSpiClass.newInstance(); @SuppressWarnings("deprecation")
TransformSpi tmp = transformSpiClass.newInstance();
transformSpi = tmp;
} catch (InstantiationException ex) { } catch (InstantiationException ex) {
Object exArgs[] = { algorithmURI }; Object exArgs[] = { algorithmURI };
throw new InvalidTransformException( throw new InvalidTransformException(
@ -345,7 +347,9 @@ public final class Transform extends SignatureElementProxy {
} }
TransformSpi newTransformSpi = null; TransformSpi newTransformSpi = null;
try { try {
newTransformSpi = transformSpiClass.newInstance(); @SuppressWarnings("deprecation")
TransformSpi tmp = transformSpiClass.newInstance();
newTransformSpi = tmp;
} catch (InstantiationException ex) { } catch (InstantiationException ex) {
Object exArgs[] = { algorithmURI }; Object exArgs[] = { algorithmURI };
throw new InvalidTransformException( throw new InvalidTransformException(

View file

@ -99,8 +99,10 @@ public class ResourceResolver {
ResourceResolver resolverTmp = resolver; ResourceResolver resolverTmp = resolver;
if (!resolver.resolverSpi.engineIsThreadSafe()) { if (!resolver.resolverSpi.engineIsThreadSafe()) {
try { try {
resolverTmp = @SuppressWarnings("deprecation")
new ResourceResolver(resolver.resolverSpi.getClass().newInstance()); ResourceResolver tmp = new ResourceResolver(resolver.resolverSpi.getClass().newInstance());
resolverTmp = tmp;
;
} catch (InstantiationException e) { } catch (InstantiationException e) {
throw new ResourceResolverException("", e, context.attr, context.baseUri); throw new ResourceResolverException("", e, context.attr, context.baseUri);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -246,6 +248,7 @@ public class ResourceResolver {
public static void register(Class<? extends ResourceResolverSpi> className, boolean start) { public static void register(Class<? extends ResourceResolverSpi> className, boolean start) {
JavaUtils.checkRegisterPermission(); JavaUtils.checkRegisterPermission();
try { try {
@SuppressWarnings("deprecation")
ResourceResolverSpi resourceResolverSpi = className.newInstance(); ResourceResolverSpi resourceResolverSpi = className.newInstance();
register(resourceResolverSpi, start); register(resourceResolverSpi, start);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {

View file

@ -121,6 +121,7 @@ public class Translator extends AccessibleContext
Class<?> translatorClass = getTranslatorClass(o.getClass()); Class<?> translatorClass = getTranslatorClass(o.getClass());
if (translatorClass != null) { if (translatorClass != null) {
try { try {
@SuppressWarnings("deprecation")
Translator t = (Translator)translatorClass.newInstance(); Translator t = (Translator)translatorClass.newInstance();
t.setSource(o); t.setSource(o);
a = t; a = t;

View file

@ -148,6 +148,7 @@ public class AbstractCharsetProvider
true, true,
this.getClass().getClassLoader()); this.getClass().getClassLoader());
@SuppressWarnings("deprecation")
Charset cs = (Charset)c.newInstance(); Charset cs = (Charset)c.newInstance();
cache.put(csn, new SoftReference<Charset>(cs)); cache.put(csn, new SoftReference<Charset>(cs));
return cs; return cs;

View file

@ -88,8 +88,9 @@ public final class P11Util {
p = Security.getProvider(providerName); p = Security.getProvider(providerName);
if (p == null) { if (p == null) {
try { try {
Class<?> clazz = Class.forName(className); @SuppressWarnings("deprecation")
p = (Provider)clazz.newInstance(); Object o = Class.forName(className).newInstance();
p = (Provider)o;
} catch (Exception e) { } catch (Exception e) {
throw new ProviderException throw new ProviderException
("Could not find provider " + providerName, e); ("Could not find provider " + providerName, e);

View file

@ -1446,7 +1446,9 @@ public final class SunPKCS11 extends AuthProvider {
} }
return null; return null;
} }
return (CallbackHandler)c.newInstance(); @SuppressWarnings("deprecation")
Object result = c.newInstance();
return (CallbackHandler)result;
} }
}); });
// save it // save it

View file

@ -89,9 +89,10 @@ public abstract class HttpServerProvider {
if (cn == null) if (cn == null)
return false; return false;
try { try {
Class<?> c = Class.forName(cn, true, @SuppressWarnings("deprecation")
ClassLoader.getSystemClassLoader()); Object o = Class.forName(cn, true,
provider = (HttpServerProvider)c.newInstance(); ClassLoader.getSystemClassLoader()).newInstance();
provider = (HttpServerProvider)o;
return true; return true;
} catch (ClassNotFoundException | } catch (ClassNotFoundException |
IllegalAccessException | IllegalAccessException |

View file

@ -82,7 +82,9 @@ public class TerminalFactory
} }
else { else {
try { try {
t = (Terminal) Thread.currentThread().getContextClassLoader().loadClass(type).newInstance(); @SuppressWarnings("deprecation")
Object o = Thread.currentThread().getContextClassLoader().loadClass(type).newInstance();
t = (Terminal) o;
} }
catch (Exception e) { catch (Exception e) {
throw new IllegalArgumentException(MessageFormat.format("Invalid terminal type: {0}", type), e); throw new IllegalArgumentException(MessageFormat.format("Invalid terminal type: {0}", type), e);

View file

@ -61,6 +61,7 @@ public class ConsoleRunner
List<Completer> completorList = new ArrayList<Completer>(); List<Completer> completorList = new ArrayList<Completer>();
for (StringTokenizer tok = new StringTokenizer(completors, ","); tok.hasMoreTokens();) { for (StringTokenizer tok = new StringTokenizer(completors, ","); tok.hasMoreTokens();) {
@SuppressWarnings("deprecation")
Object obj = Class.forName(tok.nextToken()).newInstance(); Object obj = Class.forName(tok.nextToken()).newInstance();
completorList.add((Completer) obj); completorList.add((Completer) obj);
} }

View file

@ -128,7 +128,9 @@ public class ProcessAttachingConnector
if (lib.equals("dt_shmem")) { if (lib.equals("dt_shmem")) {
try { try {
Class<?> c = Class.forName("com.sun.tools.jdi.SharedMemoryTransportService"); Class<?> c = Class.forName("com.sun.tools.jdi.SharedMemoryTransportService");
ts = (TransportService)c.newInstance(); @SuppressWarnings("deprecation")
Object tmp = c.newInstance();
ts = (TransportService)tmp;
} catch (Exception x) { } } catch (Exception x) { }
} }
} }

View file

@ -53,17 +53,19 @@ public class RawCommandLineLauncher extends AbstractLauncher implements Launchin
super(); super();
try { try {
Class<?> c = Class.forName("com.sun.tools.jdi.SharedMemoryTransportService"); @SuppressWarnings("deprecation")
transportService = (TransportService)c.newInstance(); Object o =
Class.forName("com.sun.tools.jdi.SharedMemoryTransportService").newInstance();
transportService = (TransportService)o;
transport = new Transport() { transport = new Transport() {
public String name() { public String name() {
return "dt_shmem"; return "dt_shmem";
} }
}; };
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException |
} catch (UnsatisfiedLinkError x) { UnsatisfiedLinkError |
} catch (InstantiationException x) { InstantiationException |
} catch (IllegalAccessException x) { IllegalAccessException x) {
}; };
if (transportService == null) { if (transportService == null) {

View file

@ -64,18 +64,20 @@ public class SunCommandLineLauncher extends AbstractLauncher implements Launchin
* transport or the socket transport * transport or the socket transport
*/ */
try { try {
Class<?> c = Class.forName("com.sun.tools.jdi.SharedMemoryTransportService"); @SuppressWarnings("deprecation")
transportService = (TransportService)c.newInstance(); Object o =
Class.forName("com.sun.tools.jdi.SharedMemoryTransportService").newInstance();
transportService = (TransportService)o;
transport = new Transport() { transport = new Transport() {
public String name() { public String name() {
return "dt_shmem"; return "dt_shmem";
} }
}; };
usingSharedMemory = true; usingSharedMemory = true;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException |
} catch (UnsatisfiedLinkError x) { UnsatisfiedLinkError |
} catch (InstantiationException x) { InstantiationException |
} catch (IllegalAccessException x) { IllegalAccessException x) {
}; };
if (transportService == null) { if (transportService == null) {
transportService = new SocketTransportService(); transportService = new SocketTransportService();

View file

@ -46,7 +46,7 @@ public class LocaleDataProvider extends LocaleData.CommonResourceBundleProvider
Class<?> c = Class.forName(LocaleDataProvider.class.getModule(), bundleName); Class<?> c = Class.forName(LocaleDataProvider.class.getModule(), bundleName);
if (c != null && ResourceBundle.class.isAssignableFrom(c)) { if (c != null && ResourceBundle.class.isAssignableFrom(c)) {
try { try {
@SuppressWarnings("unchecked") @SuppressWarnings({"unchecked", "deprecation"})
ResourceBundle rb = ((Class<ResourceBundle>) c).newInstance(); ResourceBundle rb = ((Class<ResourceBundle>) c).newInstance();
return rb; return rb;
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException e) {