aboutsummaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorgjoranv <gv@yahoo-inc.com>2017-06-13 12:25:54 +0200
committergjoranv <gv@yahoo-inc.com>2017-06-13 13:09:53 +0200
commitb89f20ebbf012a621ecf529addd5a35c313f3103 (patch)
treef1f5510ceeaee3784ca52ed9786a3f6b042f12a1 /config-model
parent1356dcb12bc58375cc3801ed1e3c72d97f8cfe70 (diff)
Remove last known usage of the default ctor on config classes.
- Do not create a config instance just to retrieve its class.
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/InstanceResolver.java26
1 files changed, 9 insertions, 17 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/InstanceResolver.java b/config-model/src/main/java/com/yahoo/vespa/model/InstanceResolver.java
index e983f794e76..051f0e9e52e 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/InstanceResolver.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/InstanceResolver.java
@@ -59,9 +59,8 @@ class InstanceResolver {
ConfigDefinitionKey defKey = new ConfigDefinitionKey(key);
try {
if (targetDef != null) applyDef(builder, targetDef);
- ConfigInstance instance = getInstance(defKey, builder.getClass().getClassLoader());
- Class<? extends ConfigInstance> clazz = instance.getClass();
- return clazz.getConstructor(new Class<?>[]{builder.getClass()}).newInstance(builder);
+ Class<? extends ConfigInstance> clazz = getConfigClass(defKey, builder.getClass().getClassLoader());
+ return clazz.getConstructor(builder.getClass()).newInstance(builder);
} catch (Exception e) {
throw new ConfigurationRuntimeException(e);
}
@@ -158,27 +157,20 @@ class InstanceResolver {
* @param cKey a ConfigKey
* @return a {@link ConfigInstance} or null if not available in classpath
*/
- private static ConfigInstance getInstance(ConfigDefinitionKey cKey, ClassLoader instanceLoader) {
+ @SuppressWarnings("unchecked")
+ private static Class<? extends ConfigInstance> getConfigClass(ConfigDefinitionKey cKey, ClassLoader instanceLoader) {
String className = ConfigGenerator.createClassName(cKey.getName());
- Class<?> clazz;
String fullClassName = packageName(cKey) + "." + className;
+ Class<?> clazz;
try {
clazz = instanceLoader != null ? instanceLoader.loadClass(fullClassName) : Class.forName(fullClassName);
} catch (ClassNotFoundException e) {
- return null;
- }
- Object i;
- try {
- Constructor<?> configConstructor = clazz.getDeclaredConstructor();
- configConstructor.setAccessible(true);
- i = configConstructor.newInstance();
- } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
- throw new ConfigurationRuntimeException(e);
+ throw new ConfigurationRuntimeException("Could not find config class for key " + cKey, e);
}
- if (!(i instanceof ConfigInstance)) {
- throw new ConfigurationRuntimeException(fullClassName + " is not a ConfigInstance, can not produce config for the name '" + cKey.getName() + "'.");
+ if (! ConfigInstance.class.isAssignableFrom(clazz)) {
+ throw new ConfigurationRuntimeException(fullClassName + " is not a ConfigInstance subclass, can not produce config for " + cKey);
}
- return (ConfigInstance) i;
+ return (Class<? extends ConfigInstance>) clazz;
}
static String packageName(ConfigDefinitionKey cKey) {