From 82f734885a1c290c9ecf4beff2ca05e157620422 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Sat, 10 Jun 2017 09:15:12 +0200 Subject: Revert "Set the default constructor on config classes private." --- .../main/java/com/yahoo/config/InnerNodeVector.java | 10 +++------- .../com/yahoo/vespa/model/InstanceResolver.java | 21 +++++---------------- .../com/yahoo/config/codegen/ConfigGenerator.scala | 2 +- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/config-lib/src/main/java/com/yahoo/config/InnerNodeVector.java b/config-lib/src/main/java/com/yahoo/config/InnerNodeVector.java index eec2d3cd500..72ca0138a53 100644 --- a/config-lib/src/main/java/com/yahoo/config/InnerNodeVector.java +++ b/config-lib/src/main/java/com/yahoo/config/InnerNodeVector.java @@ -1,8 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.util.List; /** @@ -40,11 +38,9 @@ public class InnerNodeVector extends NodeVector { @SuppressWarnings("unchecked") protected NODE createNew() { try { - Constructor ctor = defaultNode.getClass().getDeclaredConstructor(); - ctor.setAccessible(true); - return (NODE) ctor.newInstance(); - } catch (InvocationTargetException | IllegalAccessException | InstantiationException | NoSuchMethodException e) { - throw new ConfigurationRuntimeException(e); + return (NODE) defaultNode.getClass().newInstance(); + } catch (IllegalAccessException | InstantiationException ex) { + throw new ConfigurationRuntimeException(ex); } } 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 ab095ec8d42..9c761e425a7 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 @@ -1,26 +1,17 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model; -import com.yahoo.config.ConfigBuilder; -import com.yahoo.config.ConfigInstance; -import com.yahoo.config.ConfigurationRuntimeException; +import com.yahoo.config.*; import com.yahoo.config.codegen.CNode; import com.yahoo.config.codegen.ConfigGenerator; import com.yahoo.config.codegen.InnerCNode; import com.yahoo.config.codegen.LeafCNode; import com.yahoo.log.LogLevel; -import com.yahoo.vespa.config.ConfigDefinitionKey; -import com.yahoo.vespa.config.ConfigKey; -import com.yahoo.vespa.config.ConfigPayload; -import com.yahoo.vespa.config.ConfigPayloadBuilder; -import com.yahoo.vespa.config.ConfigTransformer; -import com.yahoo.vespa.config.GenericConfig; import com.yahoo.vespa.config.buildergen.ConfigDefinition; import com.yahoo.yolean.Exceptions; +import com.yahoo.vespa.config.*; -import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; import java.util.Map; @@ -176,7 +167,7 @@ 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) { + static ConfigInstance getInstance(ConfigDefinitionKey cKey, ClassLoader instanceLoader) { String className = ConfigGenerator.createClassName(cKey.getName()); Class clazz; String fullClassName = packageName(cKey) + "." + className; @@ -187,10 +178,8 @@ class InstanceResolver { } Object i; try { - Constructor configConstructor = clazz.getDeclaredConstructor(); - configConstructor.setAccessible(true); - i = configConstructor.newInstance(); - } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { + i = clazz.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { throw new ConfigurationRuntimeException(e); } if (!(i instanceof ConfigInstance)) { diff --git a/configgen/src/main/scala/com/yahoo/config/codegen/ConfigGenerator.scala b/configgen/src/main/scala/com/yahoo/config/codegen/ConfigGenerator.scala index 6eb4d424cc0..716f2a60c33 100644 --- a/configgen/src/main/scala/com/yahoo/config/codegen/ConfigGenerator.scala +++ b/configgen/src/main/scala/com/yahoo/config/codegen/ConfigGenerator.scala @@ -194,7 +194,7 @@ object ConfigGenerator { | * Replaced by {link} | */ |@Deprecated - |private {nodeClass(inner)}() {{ + |public {nodeClass(inner)}() {{ | this(new Builder(), false); |}} .text.stripMargin.trim -- cgit v1.2.3