summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-10-27 00:21:57 +0200
committerJon Bratseth <bratseth@gmail.com>2022-10-27 00:21:57 +0200
commit4ad1d0ca013b925858597c559ab4efb02c30dd4a (patch)
treedcb83bab5359f7f508e9ecb9a919e831046ccdff /config-model
parent0d4c548f548ee7fd904eb5cabc4c0a68cbad85ec (diff)
Use IllegalArgumentException when appropriate
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java3
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilder.java32
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilderTest.java12
3 files changed, 24 insertions, 23 deletions
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>" +