mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Tidy internals, use cls.getDeclaredConstructor().newInstance();
This commit is contained in:
1 parent
356af08f68
commit
76b02ff56a
3 files changed
+3
-7
No files matched your search
@@ -10,10 +10,9 @@ class ClassUtil {
|
|||||||
* Return a new instance of the class using the default constructor.
|
* Return a new instance of the class using the default constructor.
|
||||||
*/
|
*/
|
||||||
static Object newInstance(String className) {
|
static Object newInstance(String className) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class<?> cls = forName(className);
|
Class<?> cls = forName(className);
|
||||||
return cls.newInstance();
|
return cls.getDeclaredConstructor().newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String msg = "Error constructing " + className;
|
String msg = "Error constructing " + className;
|
||||||
throw new IllegalArgumentException(msg, e);
|
throw new IllegalArgumentException(msg, e);
|
||||||
@@ -27,7 +26,6 @@ class ClassUtil {
|
|||||||
return new ClassLoadContext().forName(name);
|
return new ClassLoadContext().forName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to wrap the context and caller classLoaders (to use/try both).
|
* Helper to wrap the context and caller classLoaders (to use/try both).
|
||||||
*/
|
*/
|
||||||
@@ -48,7 +46,6 @@ class ClassUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> forName(String name) throws ClassNotFoundException {
|
public Class<?> forName(String name) throws ClassNotFoundException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return Class.forName(name, true, contextLoader);
|
return Class.forName(name, true, contextLoader);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
@@ -59,7 +56,6 @@ class ClassUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ public class BootupClasses implements Predicate<Class<?>> {
|
|||||||
public void runServerConfigStartup(DatabaseConfig config) {
|
public void runServerConfigStartup(DatabaseConfig config) {
|
||||||
for (Class<?> cls : serverConfigStartupCandidates) {
|
for (Class<?> cls : serverConfigStartupCandidates) {
|
||||||
try {
|
try {
|
||||||
ServerConfigStartup newInstance = (ServerConfigStartup) cls.newInstance();
|
ServerConfigStartup newInstance = (ServerConfigStartup) cls.getDeclaredConstructor().newInstance();
|
||||||
newInstance.onStart(config);
|
newInstance.onStart(config);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// assume that the desired behavior is to fail - add your own try catch if needed
|
// assume that the desired behavior is to fail - add your own try catch if needed
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ class BeanDescriptorElementEmbedded<T> extends BeanDescriptorElement<T> {
|
|||||||
BeanDescriptorElementEmbedded(BeanDescriptorMap owner, DeployBeanDescriptor<T> deploy, ElementHelp elementHelp) {
|
BeanDescriptorElementEmbedded(BeanDescriptorMap owner, DeployBeanDescriptor<T> deploy, ElementHelp elementHelp) {
|
||||||
super(owner, deploy, elementHelp);
|
super(owner, deploy, elementHelp);
|
||||||
try {
|
try {
|
||||||
this.prototype = (EntityBean) beanType.newInstance();
|
this.prototype = (EntityBean) beanType.getDeclaredConstructor().newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalStateException("Unable to create entity bean prototype for "+beanType);
|
throw new IllegalStateException("Unable to create entity bean prototype for "+beanType);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user