Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8264138: Replace uses of Class.newInstance #491

Closed
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -935,14 +935,12 @@ public void processAttribute(String prefix, String localName, String value)
try {
if (controllerFactory == null) {
ReflectUtil.checkPackageAccess(type);
setController(type.newInstance());
setController(type.getDeclaredConstructor().newInstance());
} else {
setController(controllerFactory.call(type));
}
} catch (InstantiationException exception) {
throw constructLoadException(exception);
} catch (IllegalAccessException exception) {
throw constructLoadException(exception);
} catch (Exception e) {
throw constructLoadException(e);
}
}
} else {
@@ -1018,11 +1016,9 @@ public Object constructValue() throws IOException {
if (value == null) {
try {
ReflectUtil.checkPackageAccess(type);
value = type.newInstance();
} catch (InstantiationException exception) {
throw constructLoadException(exception);
} catch (IllegalAccessException exception) {
throw constructLoadException(exception);
value = type.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw constructLoadException(e);
}
}
}
@@ -1328,11 +1324,9 @@ public Object constructValue() throws LoadException {
if (value == null) {
try {
ReflectUtil.checkPackageAccess(type);
value = type.newInstance();
} catch (InstantiationException exception) {
throw constructLoadException(exception);
} catch (IllegalAccessException exception) {
throw constructLoadException(exception);
value = type.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw constructLoadException(e);
Copy link
Member

@kevinrushforth kevinrushforth May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite equivalent, since it will now wrap a RuntimeException in a LoadException, but I think that's OK in this case.

}
}
root = value;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@ public static synchronized PlatformFactory getPlatformFactory() {
String factory = "com.sun.glass.ui." + platform.toLowerCase(Locale.ROOT) + "."+ platform + "PlatformFactory";
// System.out.println("Loading Glass Factory " + factory);
Class c = Class.forName(factory);
instance = (PlatformFactory) c.newInstance();
instance = (PlatformFactory) c.getDeclaredConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
System.out.println("Failed to load Glass factory class");
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -105,7 +105,7 @@ public static synchronized NativePlatform getNativePlatform() {
throw new IllegalArgumentException("Unrecognized Monocle platform: "
+ factoryClassName);
}
NativePlatformFactory npf = (NativePlatformFactory) clazz.newInstance();
NativePlatformFactory npf = (NativePlatformFactory) clazz.getDeclaredConstructor().newInstance();
if (npf.matches() &&
npf.getMajorVersion() == majorVersion &&
npf.getMinorVersion() == minorVersion) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -73,7 +73,7 @@ void addNamedFilter(String filterName) {
+ filterName + "TouchFilter";
}
ClassLoader loader = Thread.currentThread().getContextClassLoader();
addFilter((TouchFilter) loader.loadClass(filterName).newInstance());
addFilter((TouchFilter) loader.loadClass(filterName).getDeclaredConstructor().newInstance());
}
} catch (Exception e) {
System.err.println(
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -258,7 +258,7 @@ public static synchronized Toolkit getToolkit() {
+ forcedToolkit);
}

TOOLKIT = (Toolkit)clz.newInstance();
TOOLKIT = (Toolkit)clz.getDeclaredConstructor().newInstance();
if (TOOLKIT.init()) {
if (printToolkit) {
System.err.println("JavaFX: using " + forcedToolkit);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -96,7 +96,7 @@ private static class FactoryLoader implements PrivilegedAction<GLFactory> {
public GLFactory run() {
GLFactory factory = null;
try {
factory = (GLFactory) Class.forName(factoryClassName).newInstance();
factory = (GLFactory) Class.forName(factoryClassName).getDeclaredConstructor().newInstance();
} catch (Throwable t) {
System.err.println("GLFactory.static - Platform: "
+ System.getProperty("os.name")
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -450,7 +450,7 @@ private static ShaderSource createShaderSource(String name) {
Class klass = null;
try {
klass = Class.forName(name);
return (ShaderSource)klass.newInstance();
return (ShaderSource)klass.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException e) {
System.err.println(name + " class not found");
return null;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -89,7 +89,7 @@ public synchronized static PSWRenderer createJSWInstance(Screen screen) {
PSWRenderer ret = null;
try {
Class klass = Class.forName(rootPkg + ".impl.sw.java.JSWRendererDelegate");
RendererDelegate delegate = (RendererDelegate)klass.newInstance();
RendererDelegate delegate = (RendererDelegate)klass.getDeclaredConstructor().newInstance();
ret = new PSWRenderer(screen, delegate);
} catch (Throwable e) {}
return ret;
@@ -104,7 +104,7 @@ public synchronized static PSWRenderer createJSWInstance(ResourceFactory factory
PSWRenderer ret = null;
try {
Class klass = Class.forName(rootPkg + ".impl.sw.java.JSWRendererDelegate");
RendererDelegate delegate = (RendererDelegate)klass.newInstance();
RendererDelegate delegate = (RendererDelegate)klass.getDeclaredConstructor().newInstance();
ret = new PSWRenderer(factory, delegate);
} catch (Throwable e) {}
return ret;
@@ -128,7 +128,7 @@ private synchronized static PSWRenderer createSSEInstance(Screen screen) {
PSWRenderer ret = null;
try {
Class klass = Class.forName(rootPkg + ".impl.sw.sse.SSERendererDelegate");
RendererDelegate delegate = (RendererDelegate)klass.newInstance();
RendererDelegate delegate = (RendererDelegate)klass.getDeclaredConstructor().newInstance();
ret = new PSWRenderer(screen, delegate);
} catch (Throwable e) {}
return ret;