diff options
author | gjoranv <gv@oath.com> | 2018-05-04 14:29:22 +0200 |
---|---|---|
committer | gjoranv <gv@oath.com> | 2018-05-04 15:46:10 +0200 |
commit | bb1e0c4d8440efadb077ab86b6c4a3e4e04b2213 (patch) | |
tree | bb8261283f8e3aa20665296d1d623bfc11f5a43b /config-model/src/main/java/com | |
parent | b2d563b727b59878b68766a2ba7367d6925bcd36 (diff) |
Java 9: Class.newInstance() is deprecated.
Diffstat (limited to 'config-model/src/main/java/com')
5 files changed, 18 insertions, 23 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/producer/AbstractConfigProducer.java b/config-model/src/main/java/com/yahoo/config/model/producer/AbstractConfigProducer.java index 4096eeb0168..ffb71ec76d8 100644 --- a/config-model/src/main/java/com/yahoo/config/model/producer/AbstractConfigProducer.java +++ b/config-model/src/main/java/com/yahoo/config/model/producer/AbstractConfigProducer.java @@ -328,7 +328,7 @@ public abstract class AbstractConfigProducer<CHILD extends AbstractConfigProduce /** * New Builder instance if m is getConfig(SomeConfig.Builder), or null */ - private ConfigInstance.Builder getBuilderIfIsGetConfig(Method m) throws InstantiationException, IllegalAccessException { + private ConfigInstance.Builder getBuilderIfIsGetConfig(Method m) throws ReflectiveOperationException { if (!"getConfig".equals(m.getName())) return null; Type[] params = m.getParameterTypes(); if (params.length!=1) return null; @@ -336,7 +336,7 @@ public abstract class AbstractConfigProducer<CHILD extends AbstractConfigProduce if (!(param instanceof Class)) return null; Class<?> paramClass = (Class<?>) param; if (!(ConfigInstance.Builder.class.isAssignableFrom(paramClass))) return null; - return (ConfigInstance.Builder) paramClass.newInstance(); + return (ConfigInstance.Builder) paramClass.getDeclaredConstructor().newInstance(); } public void dump(PrintStream out) { diff --git a/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java b/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java index d1e899f3763..8edc6c1042d 100644 --- a/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java +++ b/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java @@ -93,9 +93,9 @@ public class MockRoot extends AbstractConfigProducerRoot { @SuppressWarnings("unchecked") public <T extends ConfigInstance> T getConfig(Class<T> configClass, String configId) { try { - ConfigInstance.Builder builder = getConfig(getBuilder(configClass).newInstance(), configId); + ConfigInstance.Builder builder = getConfig(getBuilder(configClass).getDeclaredConstructor().newInstance(), configId); return configClass.getConstructor(builder.getClass()).newInstance(builder); - } catch (InstantiationException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/Derived.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/Derived.java index cbeb658120a..7cfcf422e80 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/Derived.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/Derived.java @@ -1,19 +1,19 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchdefinition.derived; -import com.yahoo.document.Field; -import com.yahoo.searchdefinition.document.ImmutableSDField; -import com.yahoo.searchdefinition.document.SDDocumentType; -import com.yahoo.searchdefinition.document.SDField; import com.yahoo.config.ConfigInstance; import com.yahoo.config.ConfigInstance.Builder; +import com.yahoo.document.Field; import com.yahoo.io.IOUtils; import com.yahoo.searchdefinition.Index; import com.yahoo.searchdefinition.Search; +import com.yahoo.searchdefinition.document.ImmutableSDField; +import com.yahoo.searchdefinition.document.SDDocumentType; +import com.yahoo.searchdefinition.document.SDField; import com.yahoo.text.StringUtilities; + import java.io.IOException; import java.io.Writer; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; @@ -98,10 +98,7 @@ public abstract class Derived implements Exportable { if (toDirectory!=null) writer=IOUtils.createWriter(toDirectory + "/" + fileName,false); try { exportBuilderConfig(writer); - } catch (ClassNotFoundException | InstantiationException - | IllegalAccessException | NoSuchMethodException - | SecurityException | IllegalArgumentException - | InvocationTargetException e) { + } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException e) { throw new RuntimeException(e); } } @@ -114,13 +111,13 @@ public abstract class Derived implements Exportable { * Checks what this is a producer of, instantiate that and export to writer */ // TODO move to ReflectionUtil, and move that to unexported pkg - private void exportBuilderConfig(Writer writer) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException, IOException { + private void exportBuilderConfig(Writer writer) throws ReflectiveOperationException, SecurityException, IllegalArgumentException, IOException { for (Class<?> intf : getClass().getInterfaces()) { if (ConfigInstance.Producer.class.isAssignableFrom(intf)) { Class<?> configClass = intf.getEnclosingClass(); String builderClassName = configClass.getCanonicalName()+"$Builder"; Class<?> builderClass = Class.forName(builderClassName); - ConfigInstance.Builder builder = (Builder) builderClass.newInstance(); + ConfigInstance.Builder builder = (Builder) builderClass.getDeclaredConstructor().newInstance(); Method getConfig = getClass().getMethod("getConfig", builderClass); getConfig.invoke(this, builder); ConfigInstance inst = (ConfigInstance) configClass.getConstructor(builderClass).newInstance(builder); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java index 7d784363c89..868f092fc01 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java @@ -258,11 +258,9 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri return constructor.newInstance(builder); } - private static Builder newBuilder(Class<? extends ConfigInstance> configClass) - throws ClassNotFoundException, InstantiationException, IllegalAccessException { - + private static Builder newBuilder(Class<? extends ConfigInstance> configClass) throws ReflectiveOperationException { Class builderClazz = configClass.getClassLoader().loadClass(configClass.getName() + "$Builder"); - return (Builder)builderClazz.newInstance(); + return (Builder)builderClazz.getDeclaredConstructor().newInstance(); } /** @@ -383,8 +381,8 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri } Object i; try { - i = clazz.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + i = clazz.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { throw new ConfigurationRuntimeException(e); } if (!(i instanceof ConfigInstance.Builder)) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/utils/FreezableMap.java b/config-model/src/main/java/com/yahoo/vespa/model/utils/FreezableMap.java index 5ea32ead34f..828387292c0 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/utils/FreezableMap.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/utils/FreezableMap.java @@ -17,8 +17,8 @@ public class FreezableMap<K, V> implements Map<K, V> { @SuppressWarnings("unchecked") public FreezableMap(Class<LinkedHashMap> mapClass) { try { - map = mapClass.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + map = mapClass.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } } |