diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-10-27 00:21:57 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-10-27 00:21:57 +0200 |
commit | 4ad1d0ca013b925858597c559ab4efb02c30dd4a (patch) | |
tree | dcb83bab5359f7f508e9ecb9a919e831046ccdff | |
parent | 0d4c548f548ee7fd904eb5cabc4c0a68cbad85ec (diff) |
Use IllegalArgumentException when appropriate
15 files changed, 241 insertions, 236 deletions
diff --git a/config-lib/abi-spec.json b/config-lib/abi-spec.json index 2cc1cb2b67b..f22f1279063 100644 --- a/config-lib/abi-spec.json +++ b/config-lib/abi-spec.json @@ -1,11 +1,11 @@ { - "com.yahoo.config.BooleanNode" : { - "superClass" : "com.yahoo.config.LeafNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.BooleanNode": { + "superClass": "com.yahoo.config.LeafNode", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()", "public void <init>(boolean)", "public java.lang.Boolean value()", @@ -14,28 +14,28 @@ "protected boolean doSetValue(java.lang.String)", "public bridge synthetic java.lang.Object value()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.ChangesRequiringRestart$CompareFunc" : { - "superClass" : "java.lang.Object", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.ChangesRequiringRestart$CompareFunc": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ "public", "interface", "abstract" ], - "methods" : [ + "methods": [ "public abstract com.yahoo.config.ChangesRequiringRestart getChangesRequiringRestart(com.yahoo.config.Node, com.yahoo.config.Node)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.ChangesRequiringRestart" : { - "superClass" : "java.lang.Object", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.ChangesRequiringRestart": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>(java.lang.String)", "public java.lang.String getName()", "public com.yahoo.config.ChangesRequiringRestart compare(com.yahoo.config.Node, com.yahoo.config.Node, java.lang.String, java.lang.String)", @@ -46,30 +46,30 @@ "public java.lang.String toString(java.lang.String)", "public boolean needsRestart()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.ConfigBuilder" : { - "superClass" : "java.lang.Object", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.ConfigBuilder": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ "public", "interface", "abstract" ], - "methods" : [ ], - "fields" : [ ] + "methods": [], + "fields": [] }, - "com.yahoo.config.ConfigInstance$Builder" : { - "superClass" : "java.lang.Object", - "interfaces" : [ + "com.yahoo.config.ConfigInstance$Builder": { + "superClass": "java.lang.Object", + "interfaces": [ "com.yahoo.config.ConfigBuilder" ], - "attributes" : [ + "attributes": [ "public", "interface", "abstract" ], - "methods" : [ + "methods": [ "public abstract boolean dispatchGetConfig(com.yahoo.config.ConfigInstance$Producer)", "public abstract java.lang.String getDefName()", "public abstract java.lang.String getDefNamespace()", @@ -77,55 +77,55 @@ "public boolean getApplyOnRestart()", "public void setApplyOnRestart(boolean)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.ConfigInstance$Producer" : { - "superClass" : "java.lang.Object", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.ConfigInstance$Producer": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ "public", "interface", "abstract" ], - "methods" : [ ], - "fields" : [ ] + "methods": [], + "fields": [] }, - "com.yahoo.config.ConfigInstance" : { - "superClass" : "com.yahoo.config.InnerNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.ConfigInstance": { + "superClass": "com.yahoo.config.InnerNode", + "interfaces": [], + "attributes": [ "public", "abstract" ], - "methods" : [ + "methods": [ "public void <init>()", "public static java.lang.String getDefName(java.lang.Class)", "public static java.lang.String getDefNamespace(java.lang.Class)", "public static java.util.List serialize(com.yahoo.config.InnerNode)", "public static void serialize(com.yahoo.config.InnerNode, com.yahoo.config.Serializer)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.ConfigurationRuntimeException" : { - "superClass" : "java.lang.RuntimeException", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.ConfigurationRuntimeException": { + "superClass": "java.lang.RuntimeException", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>(java.lang.String)", "public void <init>(java.lang.String, java.lang.Throwable)", "public void <init>(java.lang.Throwable)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.DoubleNode" : { - "superClass" : "com.yahoo.config.LeafNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.DoubleNode": { + "superClass": "com.yahoo.config.LeafNode", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()", "public void <init>(double)", "public java.lang.Double value()", @@ -134,30 +134,30 @@ "protected boolean doSetValue(java.lang.String)", "public bridge synthetic java.lang.Object value()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.EnumNode" : { - "superClass" : "com.yahoo.config.LeafNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.EnumNode": { + "superClass": "com.yahoo.config.LeafNode", + "interfaces": [], + "attributes": [ "public", "abstract" ], - "methods" : [ + "methods": [ "public void <init>()", "public void <init>(boolean)", "public java.lang.String toString()", "public java.lang.String getValue()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.FileNode" : { - "superClass" : "com.yahoo.config.LeafNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.FileNode": { + "superClass": "com.yahoo.config.LeafNode", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()", "public void <init>(java.lang.String)", "public com.yahoo.config.FileReference value()", @@ -166,16 +166,16 @@ "protected boolean doSetValue(java.lang.String)", "public bridge synthetic java.lang.Object value()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.FileReference" : { - "superClass" : "java.lang.Object", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.FileReference": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ "public", "final" ], - "methods" : [ + "methods": [ "public void <init>(java.lang.String)", "public java.lang.String value()", "public boolean equals(java.lang.Object)", @@ -185,16 +185,16 @@ "public static java.util.Map toValueMap(java.util.Map)", "public static com.yahoo.config.FileReference mockFileReferenceForUnitTesting(java.io.File)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.InnerNode" : { - "superClass" : "com.yahoo.config.Node", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.InnerNode": { + "superClass": "com.yahoo.config.Node", + "interfaces": [], + "attributes": [ "public", "abstract" ], - "methods" : [ + "methods": [ "public void <init>()", "public java.lang.String toString()", "public void postInitialize(java.lang.String)", @@ -204,26 +204,26 @@ "protected final java.util.Map getChildrenWithVectorsFlattened()", "protected static java.util.Map getAllDescendantLeafNodes(com.yahoo.config.InnerNode)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.InnerNodeVector" : { - "superClass" : "com.yahoo.config.NodeVector", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.InnerNodeVector": { + "superClass": "com.yahoo.config.NodeVector", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>(java.util.List)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.IntegerNode" : { - "superClass" : "com.yahoo.config.LeafNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.IntegerNode": { + "superClass": "com.yahoo.config.LeafNode", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()", "public void <init>(int)", "public java.lang.Integer value()", @@ -232,18 +232,18 @@ "protected boolean doSetValue(java.lang.String)", "public bridge synthetic java.lang.Object value()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.LeafNode" : { - "superClass" : "com.yahoo.config.Node", - "interfaces" : [ + "com.yahoo.config.LeafNode": { + "superClass": "com.yahoo.config.Node", + "interfaces": [ "java.lang.Cloneable" ], - "attributes" : [ + "attributes": [ "public", "abstract" ], - "methods" : [ + "methods": [ "protected void <init>()", "protected void <init>(boolean)", "public java.lang.Object value()", @@ -251,22 +251,23 @@ "public abstract java.lang.String getValue()", "protected final boolean setValue(java.lang.String)", "protected abstract boolean doSetValue(java.lang.String)", - "protected java.lang.Object clone()", + "protected com.yahoo.config.LeafNode clone()", "public boolean equals(java.lang.Object)", - "public int hashCode()" + "public int hashCode()", + "protected bridge synthetic java.lang.Object clone()" ], - "fields" : [ + "fields": [ "protected boolean initialized", "protected java.lang.Object value" ] }, - "com.yahoo.config.LeafNodeMaps" : { - "superClass" : "java.lang.Object", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.LeafNodeMaps": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()", "public static java.util.Map asValueMap(java.util.Map)", "public static java.util.Map asNodeMap(java.util.Map, com.yahoo.config.LeafNode)", @@ -275,15 +276,15 @@ "public static java.util.Map asUrlNodeMap(java.util.Map)", "public static java.util.Map asModelNodeMap(java.util.Map)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.LeafNodeVector" : { - "superClass" : "com.yahoo.config.NodeVector", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.LeafNodeVector": { + "superClass": "com.yahoo.config.NodeVector", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>(java.util.List, com.yahoo.config.LeafNode)", "public java.util.List asList()", "public static com.yahoo.config.LeafNodeVector createFileNodeVector(java.util.Collection)", @@ -291,15 +292,15 @@ "public static com.yahoo.config.LeafNodeVector createUrlNodeVector(java.util.Collection)", "public static com.yahoo.config.LeafNodeVector createModelNodeVector(java.util.Collection)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.LongNode" : { - "superClass" : "com.yahoo.config.LeafNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.LongNode": { + "superClass": "com.yahoo.config.LeafNode", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()", "public void <init>(long)", "public java.lang.Long value()", @@ -308,15 +309,15 @@ "protected boolean doSetValue(java.lang.String)", "public bridge synthetic java.lang.Object value()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.ModelNode" : { - "superClass" : "com.yahoo.config.LeafNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.ModelNode": { + "superClass": "com.yahoo.config.LeafNode", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()", "public void <init>(com.yahoo.config.ModelReference)", "public java.lang.String getValue()", @@ -326,15 +327,15 @@ "public static java.util.List toModelReferences(java.util.List)", "public static java.util.Map toModelReferenceMap(java.util.Map)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.ModelReference" : { - "superClass" : "java.lang.Object", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.ModelReference": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public java.util.Optional modelId()", "public java.util.Optional url()", "public java.util.Optional path()", @@ -349,43 +350,43 @@ "public static com.yahoo.config.ModelReference unresolved(java.util.Optional, java.util.Optional, java.util.Optional)", "public static com.yahoo.config.ModelReference resolved(java.nio.file.Path)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.Node" : { - "superClass" : "java.lang.Object", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.Node": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ "public", "abstract" ], - "methods" : [ + "methods": [ "public void <init>()", "public void postInitialize(java.lang.String)", "protected java.lang.Object clone()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.NodeVector$ReadOnlyException" : { - "superClass" : "java.lang.RuntimeException", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.NodeVector$ReadOnlyException": { + "superClass": "java.lang.RuntimeException", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.NodeVector" : { - "superClass" : "java.lang.Object", - "interfaces" : [ + "com.yahoo.config.NodeVector": { + "superClass": "java.lang.Object", + "interfaces": [ "java.util.List" ], - "attributes" : [ + "attributes": [ "public", "abstract" ], - "methods" : [ + "methods": [ "public void <init>()", "public int length()", "public void add(int, java.lang.Object)", @@ -414,17 +415,17 @@ "public java.lang.Object[] toArray()", "public java.lang.Object[] toArray(java.lang.Object[])" ], - "fields" : [ + "fields": [ "protected final java.util.ArrayList vector" ] }, - "com.yahoo.config.PathNode" : { - "superClass" : "com.yahoo.config.LeafNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.PathNode": { + "superClass": "com.yahoo.config.LeafNode", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()", "public void <init>(com.yahoo.config.FileReference)", "public java.nio.file.Path value()", @@ -436,15 +437,15 @@ "public static java.util.Map toFileReferenceMap(java.util.Map)", "public bridge synthetic java.lang.Object value()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.ReferenceNode" : { - "superClass" : "com.yahoo.config.LeafNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.ReferenceNode": { + "superClass": "com.yahoo.config.LeafNode", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()", "public void <init>(java.lang.String)", "public java.lang.String value()", @@ -454,17 +455,17 @@ "public void postInitialize(java.lang.String)", "public bridge synthetic java.lang.Object value()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.Serializer" : { - "superClass" : "java.lang.Object", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.Serializer": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ "public", "interface", "abstract" ], - "methods" : [ + "methods": [ "public abstract com.yahoo.config.Serializer createInner(java.lang.String)", "public abstract com.yahoo.config.Serializer createArray(java.lang.String)", "public abstract com.yahoo.config.Serializer createInner()", @@ -480,15 +481,15 @@ "public abstract void serialize(int)", "public abstract void serialize(java.lang.String)" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.StringNode" : { - "superClass" : "com.yahoo.config.LeafNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.StringNode": { + "superClass": "com.yahoo.config.LeafNode", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()", "public void <init>(java.lang.String)", "public java.lang.String value()", @@ -498,15 +499,15 @@ "protected boolean doSetValue(java.lang.String)", "public bridge synthetic java.lang.Object value()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.UrlNode" : { - "superClass" : "com.yahoo.config.LeafNode", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.UrlNode": { + "superClass": "com.yahoo.config.LeafNode", + "interfaces": [], + "attributes": [ "public" ], - "methods" : [ + "methods": [ "public void <init>()", "public void <init>(com.yahoo.config.UrlReference)", "public void <init>(java.lang.String)", @@ -519,16 +520,16 @@ "public static java.util.Map toUrlReferenceMap(java.util.Map)", "public bridge synthetic java.lang.Object value()" ], - "fields" : [ ] + "fields": [] }, - "com.yahoo.config.UrlReference" : { - "superClass" : "java.lang.Object", - "interfaces" : [ ], - "attributes" : [ + "com.yahoo.config.UrlReference": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ "public", "final" ], - "methods" : [ + "methods": [ "public void <init>(java.lang.String)", "public java.lang.String value()", "public static com.yahoo.config.UrlReference valueOf(java.lang.String)", @@ -536,6 +537,6 @@ "public boolean equals(java.lang.Object)", "public java.lang.String toString()" ], - "fields" : [ ] + "fields": [] } }
\ No newline at end of file diff --git a/config-lib/src/main/java/com/yahoo/config/ConfigurationRuntimeException.java b/config-lib/src/main/java/com/yahoo/config/ConfigurationRuntimeException.java index cd5576db9f0..ed757c6dea9 100644 --- a/config-lib/src/main/java/com/yahoo/config/ConfigurationRuntimeException.java +++ b/config-lib/src/main/java/com/yahoo/config/ConfigurationRuntimeException.java @@ -4,8 +4,8 @@ package com.yahoo.config; /** * This exception is thrown on internal errors in the configuration system. */ -@SuppressWarnings("serial") public class ConfigurationRuntimeException extends RuntimeException { + public ConfigurationRuntimeException(String message) { super(message); } diff --git a/config-lib/src/main/java/com/yahoo/config/LeafNode.java b/config-lib/src/main/java/com/yahoo/config/LeafNode.java index 8aa97cef4ee..0463631e4f6 100644 --- a/config-lib/src/main/java/com/yahoo/config/LeafNode.java +++ b/config-lib/src/main/java/com/yahoo/config/LeafNode.java @@ -4,7 +4,7 @@ package com.yahoo.config; /** * Superclass for all leaf nodes in a {@link ConfigInstance}. * <p> - * Subclasses represents leaf nodes with different types. These + * Subclasses represent leaf nodes with different types. These * implementations should implement method value() with return-value * corresponding to the actual type. * @@ -73,9 +73,9 @@ public abstract class LeafNode<T> extends Node implements Cloneable { * @return a new instance similar to this object. */ @Override - protected Object clone() { + protected LeafNode<?> clone() { try { - return super.clone(); + return (LeafNode<?>) super.clone(); } catch (CloneNotSupportedException e) { throw new ConfigurationRuntimeException(e); } @@ -83,10 +83,8 @@ public abstract class LeafNode<T> extends Node implements Cloneable { @Override public boolean equals(Object o) { - if (! (o instanceof LeafNode)) - return false; + if (! (o instanceof LeafNode<?> other)) return false; - LeafNode<?> other = (LeafNode)o; return value == null ? other.value == null : value().equals(other.value); } @@ -102,4 +100,5 @@ public abstract class LeafNode<T> extends Node implements Cloneable { void serialize(Serializer serializer) { serializer.serialize(getValue()); } + } 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 2d40f493e54..a13eebf0042 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 @@ -520,7 +520,8 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Mode throw new ConfigurationRuntimeException(e); } if (!(i instanceof ConfigInstance.Builder)) { - throw new ConfigurationRuntimeException(fullClassName + " is not a ConfigInstance.Builder, can not produce config for the name '" + key.getName() + "'."); + throw new ConfigurationRuntimeException(fullClassName + " is not a ConfigInstance.Builder, " + + "can not produce config for the name '" + key.getName() + "'."); } return (ConfigInstance.Builder) i; } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilder.java index ee1771cfbfc..5d17619b526 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilder.java @@ -54,19 +54,19 @@ public class DomConfigPayloadBuilder { public static ConfigDefinitionKey parseConfigName(Element configE) { if (!configE.getNodeName().equals("config")) { - throw new ConfigurationRuntimeException("The root element must be 'config', but was '" + configE.getNodeName() + "'"); + throw new IllegalArgumentException("The root element must be 'config', but was '" + configE.getNodeName() + "'"); } if (!configE.hasAttribute("name")) { - throw new ConfigurationRuntimeException + throw new IllegalArgumentException ("The 'config' element must have a 'name' attribute that matches the name of the config definition"); } String elementString = configE.getAttribute("name"); if (!elementString.contains(".")) { - throw new ConfigurationRuntimeException("The config name '" + elementString + - "' contains illegal characters. Only names with the pattern " + - namespacePattern.pattern() + "." + namePattern.pattern() + " are legal."); + throw new IllegalArgumentException("The config name '" + elementString + + "' contains illegal characters. Only names with the pattern " + + namespacePattern.pattern() + "." + namePattern.pattern() + " are legal."); } Tuple2<String, String> t = ConfigUtils.getNameAndNamespaceFromString(elementString); @@ -74,15 +74,15 @@ public class DomConfigPayloadBuilder { String xmlNamespace = t.second; if (!validName(xmlName)) { - throw new ConfigurationRuntimeException("The config name '" + xmlName + - "' contains illegal characters. Only names with the pattern " + - namePattern.toString() + " are legal."); + throw new IllegalArgumentException("The config name '" + xmlName + + "' contains illegal characters. Only names with the pattern " + + namePattern.toString() + " are legal."); } if (!validNamespace(xmlNamespace)) { - throw new ConfigurationRuntimeException("The config namespace '" + xmlNamespace + - "' contains illegal characters. Only namespaces with the pattern " + - namespacePattern.toString() + " are legal."); + throw new IllegalArgumentException("The config namespace '" + xmlNamespace + + "' contains illegal characters. Only namespaces with the pattern " + + namespacePattern.toString() + " are legal."); } return new ConfigDefinitionKey(xmlName, xmlNamespace); } @@ -123,12 +123,12 @@ public class DomConfigPayloadBuilder { String name = extractName(element); String value = XML.getValue(element); if (value == null) { - throw new ConfigurationRuntimeException("Element '" + name + "' must have either children or a value"); + throw new IllegalArgumentException("Element '" + name + "' must have either children or a value"); } if ("item".equals(name)) { if (parentName == null) - throw new ConfigurationRuntimeException("<item> is a reserved keyword for array and map elements"); + throw new IllegalArgumentException("<item> is a reserved keyword for array and map elements"); if (element.hasAttribute("key")) { payloadBuilder.getMap(parentName).put(element.getAttribute("key"), value); } else { @@ -190,7 +190,7 @@ public class DomConfigPayloadBuilder { parseElement(child, payloadBuilder, name); } } else { - throw new ConfigurationRuntimeException("<item> is a reserved keyword for array and map elements"); + throw new IllegalArgumentException("<item> is a reserved keyword for array and map elements"); } } } @@ -209,8 +209,8 @@ public class DomConfigPayloadBuilder { parseComplex(currElem, children, payloadBuilder, parentName); } } catch (Exception exception) { - throw new ConfigurationRuntimeException("Error parsing element at " + XML.getNodePath(currElem, " > ") + - ": " + Exceptions.toMessageString(exception)); + throw new IllegalArgumentException("Error parsing element at " + XML.getNodePath(currElem, " > ") + + ": " + Exceptions.toMessageString(exception)); } } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilderTest.java index e788fe5fc54..e9e52ba78cd 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilderTest.java @@ -129,7 +129,7 @@ public class DomConfigPayloadBuilderTest { try { new DomConfigPayloadBuilder(null).build(configRoot); fail("Expected exception for wrong tag name."); - } catch (ConfigurationRuntimeException e) { + } catch (IllegalArgumentException e) { assertEquals("The root element must be 'config', but was 'configs'", e.getMessage()); } } @@ -141,7 +141,7 @@ public class DomConfigPayloadBuilderTest { try { new DomConfigPayloadBuilder(null).build(configRoot); fail("Expected exception for mismatch between def-name and xml name attribute."); - } catch (ConfigurationRuntimeException e) { + } catch (IllegalArgumentException e) { assertEquals("The 'config' element must have a 'name' attribute that matches the name of the config definition", e.getMessage()); } } @@ -158,7 +158,7 @@ public class DomConfigPayloadBuilderTest { @Test void testNameParsingInvalidName() { - assertThrows(ConfigurationRuntimeException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { Element configRoot = getDocument(new StringReader("<config name=\" function-test\" version=\"1\">" + "<int_val>1</int_val> +" + "</config>")); @@ -168,7 +168,7 @@ public class DomConfigPayloadBuilderTest { @Test void testNameParsingInvalidNamespace() { - assertThrows(ConfigurationRuntimeException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { Element configRoot = getDocument(new StringReader("<config name=\"_foo.function-test\" version=\"1\">" + "<int_val>1</int_val> +" + "</config>")); @@ -221,7 +221,7 @@ public class DomConfigPayloadBuilderTest { @Test void require_that_item_is_reserved_in_root() { - assertThrows(ConfigurationRuntimeException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { Element configRoot = getDocument( "<config name=\"test.arraytypes\" version=\"1\">" + " <item>13</item>" + @@ -232,7 +232,7 @@ public class DomConfigPayloadBuilderTest { @Test void require_that_exceptions_are_issued() throws FileNotFoundException { - assertThrows(ConfigurationRuntimeException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { Element configRoot = getDocument( "<config name=\"test.simpletypes\">" + "<longval>invalid</longval>" + diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java index 994bdef5898..08e5c22c4e1 100644 --- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java +++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java @@ -153,7 +153,7 @@ class RpcConfigSourceClient implements ConfigSourceClient, Runnable { subscriber.subscribe(); subscribers.put(configCacheKey, subscriber); } catch (ConfigurationRuntimeException e) { - log.log(Level.INFO, "Subscribe for '" + configCacheKey + "' failed, closing subscriber"); + log.log(Level.INFO, "Subscribe for '" + configCacheKey + "' failed, closing subscriber", e); subscriber.cancel(); } } diff --git a/config/src/main/java/com/yahoo/config/subscription/CfgConfigPayloadBuilder.java b/config/src/main/java/com/yahoo/config/subscription/CfgConfigPayloadBuilder.java index 1a110fe8e6c..bdb0b03df05 100644 --- a/config/src/main/java/com/yahoo/config/subscription/CfgConfigPayloadBuilder.java +++ b/config/src/main/java/com/yahoo/config/subscription/CfgConfigPayloadBuilder.java @@ -19,6 +19,7 @@ import static java.util.logging.Level.FINEST; * @author hmusum */ public class CfgConfigPayloadBuilder { + private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(CfgConfigPayloadBuilder.class.getName()); /** @@ -39,7 +40,7 @@ public class CfgConfigPayloadBuilder { parseLine(line, lineNum, payloadBuilder); lineNum++; } - log.log(FINEST, () -> "payload=" + payloadBuilder.toString()); + log.log(FINEST, () -> "payload=" + payloadBuilder); return payloadBuilder; } @@ -53,8 +54,8 @@ public class CfgConfigPayloadBuilder { log.log(FINE, () -> "Got field without value in line " + lineNum + ": " + line + ", skipping"); return; } - field=field.trim(); - value=value.trim(); + field = field.trim(); + value = value.trim(); validateField(field, trimmedLine, lineNum); validateValue(value, trimmedLine, lineNum); List<String> fields = parseFieldList(field); @@ -96,7 +97,7 @@ public class CfgConfigPayloadBuilder { Pair<String, String> parseFieldAndValue(String line) { String field=null; String value; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); boolean inMapKey = false; for (char c : line.toCharArray()) { if (c=='{') inMapKey=true; @@ -104,7 +105,7 @@ public class CfgConfigPayloadBuilder { if (c==' ' && !inMapKey) { if (field==null) { field = sb.toString(); - sb = new StringBuffer(); + sb = new StringBuilder(); continue; } } @@ -117,14 +118,14 @@ public class CfgConfigPayloadBuilder { // split on dot, but not if inside { } (map key) List<String> parseFieldList(String field) { List<String> ret = new ArrayList<>(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); boolean inMapKey = false; for (char c : field.toCharArray()) { if (c=='{') inMapKey=true; if (c=='}') inMapKey=false; if (c=='.' && !inMapKey) { ret.add(sb.toString()); - sb = new StringBuffer(); + sb = new StringBuilder(); continue; } sb.append(c); @@ -137,7 +138,7 @@ public class CfgConfigPayloadBuilder { private void validateField(String field, String line, int lineNum) { if (field.length() == 0) { throw new ConfigurationRuntimeException("Error on line " + lineNum + ": " + line + "\n" + - "'" + field + "' is not a valid field name"); + "'" + field + "' is not a valid field name"); } } @@ -145,7 +146,7 @@ public class CfgConfigPayloadBuilder { private void validateValue(String value, String line, int lineNum) { if (value.length() == 0) { throw new ConfigurationRuntimeException("Error on line " + lineNum + ": " + line + "\n" + - "'" + value + "' is not a valid value"); + "'" + value + "' is not a valid value"); } } @@ -192,4 +193,5 @@ public class CfgConfigPayloadBuilder { return 0; } } + } diff --git a/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java b/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java index 858dc46f77a..0ef99930dde 100644 --- a/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java +++ b/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java @@ -98,7 +98,8 @@ public class JRTConfigRequester implements RequestWaiter { Connection connection = connectionPool.getCurrent(); Request request = req.getRequest(); request.setContext(new RequestContext(sub, req, connection)); - if (!req.validateParameters()) throw new ConfigurationRuntimeException("Error in parameters for config request: " + req); + if (!req.validateParameters()) + throw new ConfigurationRuntimeException("Error in parameters for config request: " + req); Duration jrtClientTimeout = getClientTimeout(req); log.log(FINE, () -> "Requesting config for " + sub + " on connection " + connection diff --git a/config/src/main/java/com/yahoo/vespa/config/protocol/DefContent.java b/config/src/main/java/com/yahoo/vespa/config/protocol/DefContent.java index 00e5bfa24d3..a84604fceb6 100644 --- a/config/src/main/java/com/yahoo/vespa/config/protocol/DefContent.java +++ b/config/src/main/java/com/yahoo/vespa/config/protocol/DefContent.java @@ -51,7 +51,8 @@ public class DefContent { } /** - * The def file payload of the actual class of the given config + * The def file payload of the actual class of the given config. + * * @param configClass the class of a generated config instance * @return a String array with the config definition (one line per element) */ diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java index 0b409d38196..5ceeb83d2d3 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java @@ -157,8 +157,8 @@ public class Application implements ModelResult { // This can happen in cases where services ask for config that no longer exist before they have been able // to reconfigure themselves log.log(Level.INFO, TenantRepository.logPre(getId()) + - ": Error resolving instance for builder '" + cacheBuilderClassNameForErrorReport + - "', returning empty config: " + Exceptions.toMessageString(e)); + ": Error resolving instance for builder '" + cacheBuilderClassNameForErrorReport + + "', returning empty config: " + Exceptions.toMessageString(e)); payload = ConfigPayload.fromBuilder(new ConfigPayloadBuilder()); } if (def.getCNode() != null) diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigInstanceBuilder.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigInstanceBuilder.java index 1167f32caf5..d99d9a7e017 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigInstanceBuilder.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigInstanceBuilder.java @@ -109,7 +109,8 @@ class ConfigInstanceBuilder { private static Class<? extends ConfigInstance> getConfigClass(Class<? extends ConfigInstance.Builder> builderClass) { Class<?> configClass = builderClass.getEnclosingClass(); if (configClass == null || ! ConfigInstance.class.isAssignableFrom(configClass)) { - throw new ConfigurationRuntimeException("Builder class " + builderClass + " has enclosing class " + configClass + ", which is not a ConfigInstance"); + throw new ConfigurationRuntimeException("Builder class " + builderClass + " has enclosing class " + + configClass + ", which is not a ConfigInstance"); } return (Class<? extends ConfigInstance>) configClass; } diff --git a/container-core/src/main/java/com/yahoo/container/di/Container.java b/container-core/src/main/java/com/yahoo/container/di/Container.java index 5913c5e79d1..8e9874f272e 100644 --- a/container-core/src/main/java/com/yahoo/container/di/Container.java +++ b/container-core/src/main/java/com/yahoo/container/di/Container.java @@ -213,7 +213,7 @@ public class Container { ComponentsConfig componentsConfig = getConfig(componentsConfigKey, configsIncludingBootstrapConfigs); if (componentsConfig == null) { throw new ConfigurationRuntimeException("The set of all configs does not include a valid 'components' config. Config set: " - + configsIncludingBootstrapConfigs.keySet()); + + configsIncludingBootstrapConfigs.keySet()); } addNodes(componentsConfig, graph); injectNodes(componentsConfig, graph); diff --git a/container-search/src/main/java/com/yahoo/search/statistics/ElapsedTime.java b/container-search/src/main/java/com/yahoo/search/statistics/ElapsedTime.java index a2249f8a740..5ba8963c78c 100644 --- a/container-search/src/main/java/com/yahoo/search/statistics/ElapsedTime.java +++ b/container-search/src/main/java/com/yahoo/search/statistics/ElapsedTime.java @@ -25,19 +25,18 @@ public class ElapsedTime { // safe than sorry. It also covers in SearchHandler where the same Execution instance // is used for search and fill. /** A map used as a set to store the time track of all the Execution instances for a Result */ - private Set<TimeTracker> tracks = new TinyIdentitySet<>(8); + private final Set<TimeTracker> tracks = new TinyIdentitySet<>(8); public void add(TimeTracker track) { tracks.add(track); } private long fetcher(Activity toFetch, TimeTracker fetchFrom) { - switch (toFetch) { - case SEARCH: return fetchFrom.searchTime(); - case FILL: return fetchFrom.fillTime(); - case PING: return fetchFrom.pingTime(); - default: return 0L; - } + return switch (toFetch) { + case SEARCH -> fetchFrom.searchTime(); + case FILL -> fetchFrom.fillTime(); + case PING -> fetchFrom.pingTime(); + }; } /** diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/MetricsResponse.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/MetricsResponse.java index d100e3bdd95..9e28a9d85bb 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/MetricsResponse.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/MetricsResponse.java @@ -60,7 +60,7 @@ public class MetricsResponse { private void consumeNode(Inspector nodeObject, NodeList applicationNodes, NodeRepository nodeRepository) { String hostname = nodeObject.field("hostname").asString(); Optional<Node> node = applicationNodes.node(hostname); - if (node.isEmpty()) return; // Node is not part of this cluster any more + if (node.isEmpty()) return; // Node is not part of this cluster any longer ListMap<String, Double> nodeValues = new ListMap<>(); Instant at = consumeNodeMetrics(nodeObject.field("node"), nodeValues); |