diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-01-21 12:16:18 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-01-21 12:16:18 +0100 |
commit | 785591af27e3bfe348e3c4a6b2e7124ab7bdad75 (patch) | |
tree | 0f9418e252bb598950321a315b730910734bc4f4 /config-model/src/main | |
parent | a0ba343a01db44795cce1c610d5d14d7fb450e71 (diff) |
Classify exceptions better to avoid unnecessary stack traces
Diffstat (limited to 'config-model/src/main')
52 files changed, 213 insertions, 210 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/ConfigModelRepo.java b/config-model/src/main/java/com/yahoo/config/model/ConfigModelRepo.java index 8d192414871..77b71a66118 100644 --- a/config-model/src/main/java/com/yahoo/config/model/ConfigModelRepo.java +++ b/config-model/src/main/java/com/yahoo/config/model/ConfigModelRepo.java @@ -153,7 +153,7 @@ public class ConfigModelRepo implements ConfigModelRepoAdder, Serializable, Iter Collection<ConfigModelBuilder> builders = configModelRegistry.resolve(xmlId); if (builders.isEmpty()) - throw new RuntimeException("Could not resolve tag <" + tagName + " version=\"" + tagVersion + "\"> to a config model component"); + throw new IllegalArgumentException("Could not resolve tag <" + tagName + " version=\"" + tagVersion + "\"> to a config model component"); for (ConfigModelBuilder builder : builders) { if ( ! model2Element.containsKey(builder)) { diff --git a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java index dac62ce7e1b..bb8c4141873 100644 --- a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java +++ b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java @@ -161,7 +161,7 @@ public class DeployState implements ConfigDefinitionStore { return hostsReader == null ? new SingleNodeProvisioner() : new HostsXmlProvisioner(hostsReader); } catch (IOException e) { - throw new IllegalStateException("Could not read hosts.xml", e); + throw new RuntimeException("Could not read hosts.xml", e); } } 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 47a5fb24a43..0ebc661f1d7 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 @@ -160,7 +160,7 @@ public abstract class AbstractConfigProducer<CHILD extends AbstractConfigProduce * because config IDs must be registered through setConfigId(). */ public final String getConfigId() { - if (configId == null) throw new RuntimeException("The system topology must be frozen first."); + if (configId == null) throw new IllegalStateException("The system topology must be frozen first."); return configId; } diff --git a/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java b/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java index c678618311e..c9a03dad65e 100644 --- a/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java +++ b/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java @@ -72,7 +72,7 @@ public class Hosts { for (Element hostE : XML.getChildren(doc.getDocumentElement(), "host")) { String name = hostE.getAttribute("name"); if (name.equals("")) { - throw new RuntimeException("Missing 'name' attribute for host."); + throw new IllegalArgumentException("Missing 'name' attribute for host."); } if ("localhost".equals(name)) { name = HostName.getLocalhost(); diff --git a/config-model/src/main/java/com/yahoo/documentmodel/DataTypeRepo.java b/config-model/src/main/java/com/yahoo/documentmodel/DataTypeRepo.java index 8848759b415..9f4eeeb44c9 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/DataTypeRepo.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/DataTypeRepo.java @@ -27,8 +27,8 @@ public class DataTypeRepo implements DataTypeCollection { public DataTypeRepo add(DataType type) { if (typeByName.containsKey(type.getName()) || typeById.containsKey(type.getId())) { - throw new IllegalStateException("Data type '" + type.getName() + "', id '" + - type.getId() + "' is already registered."); + throw new IllegalArgumentException("Data type '" + type.getName() + "', id '" + + type.getId() + "' is already registered."); } typeByName.put(type.getName(), type); typeById.put(type.getId(), type); @@ -43,9 +43,7 @@ public class DataTypeRepo implements DataTypeCollection { } public DataTypeRepo replace(DataType type) { - if (!typeByName.containsKey(type.getName()) || - !typeById.containsKey(type.getId())) - { + if (!typeByName.containsKey(type.getName()) || !typeById.containsKey(type.getId())) { throw new IllegalStateException("Data type '" + type.getName() + "' is not registered."); } var oldByName = typeByName.remove(type.getName()); diff --git a/config-model/src/main/java/com/yahoo/documentmodel/DocumentTypeRepo.java b/config-model/src/main/java/com/yahoo/documentmodel/DocumentTypeRepo.java index 42572ae763a..885db34510b 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/DocumentTypeRepo.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/DocumentTypeRepo.java @@ -28,10 +28,10 @@ public class DocumentTypeRepo implements DocumentTypeCollection { public DocumentTypeRepo add(NewDocumentType type) { if (typeByName.containsKey(type.getFullName())) { - throw new IllegalStateException("Document type " + type.toString() + " is already registered"); + throw new IllegalArgumentException("Document type " + type + " is already registered"); } if (typeById.containsKey(type.getFullName().getId())) { - throw new IllegalStateException("Document type " + type.toString() + " is already registered"); + throw new IllegalArgumentException("Document type " + type + " is already registered"); } typeByName.put(type.getFullName(), type); typeById.put(type.getFullName().getId(), type); diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/Index.java b/config-model/src/main/java/com/yahoo/searchdefinition/Index.java index 793fcc59f9d..14f07f224ab 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/Index.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/Index.java @@ -44,7 +44,7 @@ public class Index implements Cloneable, Serializable { private boolean prefix; /** The list of aliases (Strings) to this index name */ - private Set<String> aliases=new java.util.LinkedHashSet<>(1); + private Set<String> aliases = new java.util.LinkedHashSet<>(1); /** * The stemming setting of this field, or null to use the default. @@ -138,19 +138,18 @@ public class Index implements Cloneable, Serializable { } public String toString() { - String rankTypeName=rankType==null ? "(none)" : rankType.name(); - return - "index '" + name + - "' [ranktype: " + rankTypeName + - ", prefix: " + prefix + "]"; + String rankTypeName = rankType == null ? "(none)" : rankType.name(); + return "index '" + name + + "' [ranktype: " + rankTypeName + + ", prefix: " + prefix + "]"; } /** Makes a deep copy of this index */ @Override public Object clone() { try { - Index copy=(Index)super.clone(); - copy.aliases=new LinkedHashSet<>(this.aliases); + Index copy = (Index)super.clone(); + copy.aliases = new LinkedHashSet<>(this.aliases); return copy; } catch (CloneNotSupportedException e) { diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java index d484d32b02f..5f6bde3b791 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -830,7 +830,7 @@ public class RankProfile implements Cloneable { throw (ParseException)exception.initCause(e); } catch (IOException e) { - throw new RuntimeException("IOException parsing ranking expression '" + name + "'"); + throw new RuntimeException("IOException parsing ranking expression '" + name + "'", e); } } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java b/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java index aa43c00f461..ba34045e7de 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java @@ -76,12 +76,12 @@ public class SDDocumentTypeOrderer { SDDocumentType inherited; if (type.isStruct()) { inherited = owningDocument.allTypes().get(new NewDocumentType.Name(name.getName())); - if (inherited == null) throw new IllegalStateException("Struct '" + name + "' not found in " + owningDocument); + if (inherited == null) throw new IllegalArgumentException("Struct '" + name + "' not found in " + owningDocument); process(inherited, owningDocument); } else { inherited = createdSDTypes.get(name); - if (inherited == null) throw new IllegalStateException("Document type '" + name + "' not found"); + if (inherited == null) throw new IllegalArgumentException("Document type '" + name + "' not found"); process(inherited, inherited); } type.inherit(inherited); 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 30cb236984d..3a8268029d0 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 @@ -76,7 +76,7 @@ public abstract class Derived implements Exportable { protected abstract String getDerivedName(); /** Returns the value of getName if true, the given number as a string otherwise */ - protected String getIndex(int number,boolean labels) { + protected String getIndex(int number, boolean labels) { return labels ? getName() : String.valueOf(number); } @@ -87,12 +87,12 @@ public abstract class Derived implements Exportable { * @param toDirectory the directory to export to, or null * */ - public final void export(String toDirectory) - throws IOException { - Writer writer=null; + public final void export(String toDirectory) throws IOException { + Writer writer = null; try { - String fileName=getDerivedName() + ".cfg"; - if (toDirectory!=null) writer=IOUtils.createWriter(toDirectory + "/" + fileName,false); + String fileName = getDerivedName() + ".cfg"; + if (toDirectory != null) + writer = IOUtils.createWriter(toDirectory + "/" + fileName,false); try { exportBuilderConfig(writer); } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException e) { @@ -100,7 +100,7 @@ public abstract class Derived implements Exportable { } } finally { - if (writer!=null) IOUtils.closeWriter(writer); + if (writer != null) IOUtils.closeWriter(writer); } } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java index d7bcd295f09..f775c4e697d 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java @@ -408,7 +408,7 @@ public class RawRankProfile implements RankProfilesConfig.Producer { for (Map.Entry<String, String> queryFeatureType : queryFeatureTypes.entrySet()) { properties.add(new Pair<>("vespa.type.query." + queryFeatureType.getKey(), queryFeatureType.getValue())); } - if (properties.size() >= 1000000) throw new RuntimeException("Too many rank properties"); + if (properties.size() >= 1000000) throw new IllegalArgumentException("Too many rank properties"); distributeLargeExpressionsAsFiles(properties, largeRankExpressions); return properties; } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java index 5ac6dd46102..fce128d80f3 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java @@ -337,8 +337,8 @@ public final class Attribute implements Cloneable, Serializable { @SuppressWarnings("deprecation") private DataType createReferenceDataType() { - if (!referenceDocumentType.isPresent()) { - throw new IllegalStateException("Referenced document type is not set!"); + if (referenceDocumentType.isEmpty()) { + throw new IllegalStateException("Referenced document type is not set"); } StructuredDataType type = referenceDocumentType.get(); if (type instanceof DocumentType) { @@ -350,9 +350,9 @@ public final class Attribute implements Cloneable, Serializable { public DataType getDataType() { DataType dataType = toDataType(type); - if (collectionType.equals(Attribute.CollectionType.ARRAY)) { + if (collectionType == Attribute.CollectionType.ARRAY) { return DataType.getArray(dataType); - } else if (collectionType.equals(Attribute.CollectionType.WEIGHTEDSET)) { + } else if (collectionType == Attribute.CollectionType.WEIGHTEDSET) { return DataType.getWeightedSet(dataType, createIfNonExistent, removeIfZero); } else { return dataType; @@ -371,7 +371,7 @@ public final class Attribute implements Cloneable, Serializable { public boolean equals(Object object) { if (! (object instanceof Attribute)) return false; - Attribute other=(Attribute)object; + Attribute other = (Attribute)object; if (!this.name.equals(other.name)) return false; return isCompatible(other); } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/Matching.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/Matching.java index 691426ee413..d506b22297d 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/document/Matching.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/Matching.java @@ -102,8 +102,8 @@ public class Matching implements Cloneable, Serializable { } if (m.isTypeUserSet()) { this.setType(m.getType()); - if (m.getType()==Type.GRAM) - gramSize=m.gramSize; + if (m.getType() == Type.GRAM) + gramSize = m.gramSize; } if (m.getExactMatchTerminator() != null) { this.setExactMatchTerminator(m.getExactMatchTerminator()); @@ -125,8 +125,10 @@ public class Matching implements Cloneable, Serializable { this.exactMatchTerminator = exactMatchTerminator; } + @Override public String toString() { - return type + " matching [" + (type==Type.GRAM ? "gram size " + gramSize : "supports " + algorithm) + "], [exact-terminator "+exactMatchTerminator+"]"; + return type + " matching [" + (type==Type.GRAM ? "gram size " + gramSize : "supports " + algorithm) + + "], [exact-terminator "+exactMatchTerminator+"]"; } public Matching clone() { @@ -145,10 +147,10 @@ public class Matching implements Cloneable, Serializable { Matching other=(Matching)o; if ( ! other.type.equals(this.type)) return false; if ( ! other.algorithm.equals(this.algorithm)) return false; - if ( this.exactMatchTerminator==null && other.exactMatchTerminator!=null) return false; - if ( this.exactMatchTerminator!=null && ( ! this.exactMatchTerminator.equals(other.exactMatchTerminator)) ) + if ( this.exactMatchTerminator == null && other.exactMatchTerminator != null) return false; + if ( this.exactMatchTerminator != null && ( ! this.exactMatchTerminator.equals(other.exactMatchTerminator)) ) return false; - if ( gramSize!=other.gramSize) return false; + if ( gramSize != other.gramSize) return false; return true; } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/Ranking.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/Ranking.java index 7bfff2d56ee..235677cd05e 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/document/Ranking.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/Ranking.java @@ -69,7 +69,7 @@ public class Ranking implements Cloneable, Serializable { return (Ranking)super.clone(); } catch (CloneNotSupportedException e) { - throw new RuntimeException("Programming error",e); + throw new RuntimeException("Programming error", e); } } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java index 566342403d4..edb317f4a99 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java @@ -435,7 +435,7 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, config.setInputStream(new IndexingInput(script)); setIndexingScript(ScriptExpression.newInstance(config)); } catch (ParseException e) { - throw new RuntimeException("Failed to parser script '" + script + "'.", e); + throw new IllegalArgumentException("Failed to parse script '" + script + "'", e); } } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java index e11f7d370c5..df103dcb096 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java @@ -31,8 +31,8 @@ public class ImplicitSummaryFields extends Processor { private void addField(DocumentSummary docsum, SummaryField field, boolean validate) { if (validate && docsum.getSummaryField(field.getName()) != null) { - throw new IllegalStateException("Summary class '" + docsum.getName() + "' uses reserved field name '" + - field.getName() + "'."); + throw new IllegalArgumentException("Summary class '" + docsum.getName() + "' uses reserved field name '" + + field.getName() + "'."); } docsum.add(field); } diff --git a/config-model/src/main/java/com/yahoo/vespa/documentmodel/SearchField.java b/config-model/src/main/java/com/yahoo/vespa/documentmodel/SearchField.java index e146d3c8798..acfdd4f8671 100644 --- a/config-model/src/main/java/com/yahoo/vespa/documentmodel/SearchField.java +++ b/config-model/src/main/java/com/yahoo/vespa/documentmodel/SearchField.java @@ -8,10 +8,10 @@ import java.util.ArrayList; import java.util.List; /** - * @author baldersheim - * @since 2010-02-19 + * @author baldersheim */ public class SearchField extends Field { + /// Indicate if field shall be stored in memory for attribute usage. private boolean attribute = false; /// Indicate if the field is Vespa indexed. @@ -45,7 +45,6 @@ public class SearchField extends Field { validate(); } - @SuppressWarnings({ "deprecation" }) private void validate() { if (attribute || !indexed) { return; @@ -55,17 +54,14 @@ public class SearchField extends Field { if (DataType.STRING.equals(primiType) || DataType.URI.equals(primiType)) { return; } - throw new IllegalStateException("Expected type " + DataType.STRING.getName() + " for indexed field '" + - getName() + "', got " + fieldType.getName() + "."); + throw new IllegalArgumentException("Expected type " + DataType.STRING.getName() + " for indexed field '" + + getName() + "', got " + fieldType.getName() + "."); } - public SearchField setIndexed() { indexed = true; validate(); return this; } + public SearchField setIndexed() { indexed = true; validate(); return this; } public SearchField setAttribute() { attribute = true; validate(); return this; } public boolean isAttribute() { return attribute; } - /** - * True if field is Vespa indexed - * @return true if indexed - */ + public boolean isIndexed() { return indexed; } public SearchField addFeature(Feature feature) { featureList.add(feature); validate(); return this; } } diff --git a/config-model/src/main/java/com/yahoo/vespa/documentmodel/SummaryField.java b/config-model/src/main/java/com/yahoo/vespa/documentmodel/SummaryField.java index 0e7ee02d7ba..75a2a808a89 100644 --- a/config-model/src/main/java/com/yahoo/vespa/documentmodel/SummaryField.java +++ b/config-model/src/main/java/com/yahoo/vespa/documentmodel/SummaryField.java @@ -197,32 +197,30 @@ public class SummaryField extends Field implements Cloneable, TypedKey { * Returns a summary field which merges the settings in the given field * into this field * - * @param merge the field to merge with this, if null, the merged field is - * <code>this</code> field + * @param merge the field to merge with this, if null, the merged field is *this* field * @throws RuntimeException if the two fields can not be merged */ public SummaryField mergeWith(SummaryField merge) { - if (merge==null) return this; + if (merge == null) return this; if (this.isImplicit()) return merge; if (merge.isImplicit()) return this; if (!merge.getName().equals(getName())) throw new IllegalArgumentException(merge + " conflicts with " + this + ": different names"); - if (!merge.getTransform().equals(getTransform())) + if (merge.getTransform() != getTransform()) throw new IllegalArgumentException(merge + " conflicts with " + this + ": different transforms"); if (!merge.getDataType().equals(getDataType())) throw new IllegalArgumentException(merge + " conflicts with " + this + ": different types"); - if (!merge.isImplicit()) - setImplicit(false); + setImplicit(false); - if (isHeadOf(this.sourceIterator(),merge.sourceIterator())) { + if (isHeadOf(this.sourceIterator(), merge.sourceIterator())) { // Ok } - else if (isHeadOf(merge.sourceIterator(),this.sourceIterator())) { - sources=new LinkedHashSet<>(merge.sources); + else if (isHeadOf(merge.sourceIterator(), this.sourceIterator())) { + sources = new LinkedHashSet<>(merge.sources); } else { throw new IllegalArgumentException(merge + " conflicts with " + this + @@ -277,13 +275,14 @@ public class SummaryField extends Field implements Cloneable, TypedKey { return "'summary " + getName() + " type " + toLowerCase(getDataType().getName()) + "' in '" + getDestinationString() + "'"; } + @Override public SummaryField clone() { try { - SummaryField clone=(SummaryField)super.clone(); - if (this.sources!=null) - clone.sources=new LinkedHashSet<>(this.sources); - if (this.destinations!=null) - clone.destinations=new LinkedHashSet<>(destinations); + SummaryField clone = (SummaryField)super.clone(); + if (this.sources != null) + clone.sources = new LinkedHashSet<>(this.sources); + if (this.destinations != null) + clone.destinations = new LinkedHashSet<>(destinations); return clone; } catch (CloneNotSupportedException e) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java index 73b106ed393..78cbb722bc7 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java @@ -144,8 +144,8 @@ public abstract class AbstractService extends AbstractConfigProducer<AbstractCon throw new IllegalStateException("Service '" + getConfigId() + "' already initialized."); } if (hostResource == null) { - throw new RuntimeException("No host found for service '" + getServiceName() + "'. " + - "The hostalias is probably missing from hosts.xml."); + throw new IllegalArgumentException("No host found for service '" + getServiceName() + "'. " + + "The hostalias is probably missing from hosts.xml."); } id = getIndex(hostResource); ports = hostResource.allocateService(deployLogger, this, getInstanceWantedPort(userPort)); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/HostPorts.java b/config-model/src/main/java/com/yahoo/vespa/model/HostPorts.java index 07dc0a5f9e9..b31e6028c05 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/HostPorts.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/HostPorts.java @@ -193,9 +193,9 @@ public class HostPorts { String msg = (service.getClass().equals(otherService.getClass()) && service.requiresWantedPort()) ? "You must set port explicitly for all instances of this service type, except the first one. " : ""; - throw new RuntimeException(service.getServiceName() + " cannot reserve port " + port + - " on " + hostname + ": Already reserved for " + otherService.getServiceName() + - ". " + msg + "Next available port is: " + nextAvailablePort + " ports used: " + portDB); + throw new IllegalArgumentException(service.getServiceName() + " cannot reserve port " + port + + " on " + hostname + ": Already reserved for " + otherService.getServiceName() + + ". " + msg + "Next available port is: " + nextAvailablePort + " ports used: " + portDB); } private void noMoreAvailablePorts() { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/PortsMeta.java b/config-model/src/main/java/com/yahoo/vespa/model/PortsMeta.java index 70a238b4a0c..3420ab26e20 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/PortsMeta.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/PortsMeta.java @@ -14,7 +14,7 @@ import java.util.List; public class PortsMeta implements Serializable { /** A list of all ports. The list elements are lists of strings. */ - private List<LinkedList<String>> ports; + private final List<LinkedList<String>> ports; /** Remember the rpc admin port offset. */ private Integer rpcAdminOffset = null; @@ -35,8 +35,9 @@ public class PortsMeta implements Serializable { /** * Set up the port to tag, for chained usage. - * @param offset The relative port to tag. - * @return this portsmeta, to allow .tag calls. + * + * @param offset the relative port to tag + * @return this portsmeta, to allow .tag calls */ public PortsMeta on(int offset) { this.currentOffset = offset; @@ -45,8 +46,9 @@ public class PortsMeta implements Serializable { /** * Tag a previously setup port (using 'on') with the specified tag. - * @param meta The tag to apply to the current port. - * @return this portsmeta, to allow further .tag calls. + * + * @param meta the tag to apply to the current port + * @return this portsmeta, to allow further .tag calls */ public PortsMeta tag(String meta) { if (currentOffset == null) { @@ -57,9 +59,10 @@ public class PortsMeta implements Serializable { /** * Register a given metainfo string to the port at offset. + * * @param offset 0-based index to identify the port - * @param meta a String to be added to the given ports meta set. - * @return this for convenient chaining. + * @param meta a String to be added to the given ports meta set + * @return this for convenient chaining */ private PortsMeta register(int offset, String meta) { // Allocate new LinkedLists on each element up-to-and-including offset @@ -73,8 +76,9 @@ public class PortsMeta implements Serializable { /** * Check if the port at a specific offset contains a particular meta attribute. - * @param offset The relative port offset - * @param meta The meta info we want to check for + * + * @param offset the relative port offset + * @param meta the meta info we want to check for * @return boolean true if the specific port has registered the meta */ public boolean contains(int offset, String meta) { @@ -83,7 +87,8 @@ public class PortsMeta implements Serializable { /** * Get the number of ports with registered meta. - * @return the number of ports that have been registered. + * + * @return the number of ports that have been registered */ public int getNumPorts() { return ports.size(); @@ -91,21 +96,23 @@ public class PortsMeta implements Serializable { /** * Get an iterator of the Strings registered at the specific point. - * @param offset The relative offset to inquire about tags. + * + * @param offset the relative offset to inquire about tags * @return List of tags. */ public List<String> getTagsAt(int offset) { try { return ports.get(offset); } catch (IndexOutOfBoundsException e) { - throw new RuntimeException("Trying to get ports meta with offset " + offset + - ", which is outside the range 0 to " + ports.size(), e); + throw new IllegalArgumentException("Trying to get ports meta with offset " + offset + + ", which is outside the range 0 to " + ports.size(), e); } } /** * Get the offset to the rpc port used for admin. - * @return Integer the offset, or null if none set. + * + * @return the offset, or null if none set */ public Integer getRpcAdminOffset() { if (rpcAdminOffset == null) { 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 13b0f6216b2..91dbb56d20d 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 @@ -324,7 +324,7 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri for (var futureConvertedModel : futureModels) { try { futureConvertedModel.get(); - } catch (ExecutionException |InterruptedException e) { + } catch (ExecutionException | InterruptedException e) { throw new RuntimeException(e); } } @@ -620,7 +620,7 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri * @param configId the id to register with, not necessarily equal to descendant.getConfigId(). * @param descendant The configProducer descendant to add */ - public void addDescendant(String configId, AbstractConfigProducer descendant) { + public void addDescendant(String configId, AbstractConfigProducer<?> descendant) { if (id2producer.containsKey(configId)) { throw new RuntimeException ("Config ID '" + configId + "' cannot be reserved by an instance of class '" + diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java index bd8fefdda2e..f8e43790f02 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java @@ -158,7 +158,7 @@ public class VespaModelFactory implements ModelFactory { try { return new VespaModel(configModelRegistry, deployState); } catch (IOException | SAXException e) { - throw new RuntimeException(e); + throw new IllegalArgumentException(e); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidator.java index ef0a8ddda8e..66da43856b1 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ConstantTensorJsonValidator.java @@ -90,7 +90,7 @@ public class ConstantTensorJsonValidator { validateTensorValue(); } } else { - throw new InvalidConstantTensor(parser, "Only 'address' or 'value' fields are permitted within a cell object"); + throw new InvalidConstantTensorException(parser, "Only 'address' or 'value' fields are permitted within a cell object"); } } @@ -110,11 +110,11 @@ public class ConstantTensorJsonValidator { String dimensionName = parser.getCurrentName(); TensorType.Dimension dimension = tensorDimensions.get(dimensionName); if (dimension == null) { - throw new InvalidConstantTensor(parser, String.format("Tensor dimension '%s' does not exist", parser.getCurrentName())); + throw new InvalidConstantTensorException(parser, String.format("Tensor dimension '%s' does not exist", parser.getCurrentName())); } if (!cellDimensions.contains(dimensionName)) { - throw new InvalidConstantTensor(parser, String.format("Duplicate tensor dimension '%s'", parser.getCurrentName())); + throw new InvalidConstantTensorException(parser, String.format("Duplicate tensor dimension '%s'", parser.getCurrentName())); } cellDimensions.remove(dimensionName); @@ -122,7 +122,7 @@ public class ConstantTensorJsonValidator { } if (!cellDimensions.isEmpty()) { - throw new InvalidConstantTensor(parser, String.format("Tensor address missing dimension(s) %s", Joiner.on(", ").join(cellDimensions))); + throw new InvalidConstantTensorException(parser, String.format("Tensor address missing dimension(s) %s", Joiner.on(", ").join(cellDimensions))); } } @@ -134,7 +134,7 @@ public class ConstantTensorJsonValidator { private void validateLabel(TensorType.Dimension dimension) throws IOException { JsonToken token = parser.nextToken(); if (token != JsonToken.VALUE_STRING) - throw new InvalidConstantTensor(parser, String.format("Tensor label is not a string (%s)", token.toString())); + throw new InvalidConstantTensorException(parser, String.format("Tensor label is not a string (%s)", token.toString())); if (dimension instanceof TensorType.IndexedBoundDimension) { validateBoundIndex((TensorType.IndexedBoundDimension) dimension); @@ -148,7 +148,7 @@ public class ConstantTensorJsonValidator { try { int value = Integer.parseInt(parser.getValueAsString()); if (value >= dimension.size().get()) - throw new InvalidConstantTensor(parser, String.format("Index %s not within limits of bound dimension '%s'", value, dimension.name())); + throw new InvalidConstantTensorException(parser, String.format("Index %s not within limits of bound dimension '%s'", value, dimension.name())); } catch (NumberFormatException e) { throwCoordinateIsNotInteger(parser.getValueAsString(), dimension.name()); } @@ -166,14 +166,14 @@ public class ConstantTensorJsonValidator { } private void throwCoordinateIsNotInteger(String value, String dimensionName) { - throw new InvalidConstantTensor(parser, String.format("Index '%s' for dimension '%s' is not an integer", value, dimensionName)); + throw new InvalidConstantTensorException(parser, String.format("Index '%s' for dimension '%s' is not an integer", value, dimensionName)); } private void validateTensorValue() throws IOException { JsonToken token = parser.nextToken(); if (token != JsonToken.VALUE_NUMBER_FLOAT && token != JsonToken.VALUE_NUMBER_INT) { - throw new InvalidConstantTensor(parser, String.format("Tensor value is not a number (%s)", token.toString())); + throw new InvalidConstantTensorException(parser, String.format("Tensor value is not a number (%s)", token.toString())); } } @@ -187,7 +187,7 @@ public class ConstantTensorJsonValidator { private void assertTokenIs(JsonToken token, JsonToken wantedToken) { if (token != wantedToken) { - throw new InvalidConstantTensor(parser, String.format("Expected JSON token %s, but got %s", wantedToken.toString(), token.toString())); + throw new InvalidConstantTensorException(parser, String.format("Expected JSON token %s, but got %s", wantedToken.toString(), token.toString())); } } @@ -195,17 +195,17 @@ public class ConstantTensorJsonValidator { String actualFieldName = parser.getCurrentName(); if (!actualFieldName.equals(wantedFieldName)) { - throw new InvalidConstantTensor(parser, String.format("Expected field name '%s', got '%s'", wantedFieldName, actualFieldName)); + throw new InvalidConstantTensorException(parser, String.format("Expected field name '%s', got '%s'", wantedFieldName, actualFieldName)); } } - static class InvalidConstantTensor extends RuntimeException { + static class InvalidConstantTensorException extends IllegalArgumentException { - InvalidConstantTensor(JsonParser parser, String message) { + InvalidConstantTensorException(JsonParser parser, String message) { super(message + " " + parser.getCurrentLocation().toString()); } - InvalidConstantTensor(JsonParser parser, Exception base) { + InvalidConstantTensorException(JsonParser parser, Exception base) { super("Failed to parse JSON stream " + parser.getCurrentLocation().toString(), base); } @@ -220,7 +220,7 @@ public class ConstantTensorJsonValidator { try { lambda.invoke(); } catch (IOException e) { - throw new InvalidConstantTensor(parser, e); + throw new InvalidConstantTensorException(parser, e); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidator.java index e9b23461527..f741c59e414 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidator.java @@ -8,7 +8,7 @@ import com.yahoo.config.model.deploy.DeployState; import com.yahoo.path.Path; import com.yahoo.searchdefinition.RankingConstant; import com.yahoo.vespa.model.VespaModel; -import com.yahoo.vespa.model.application.validation.ConstantTensorJsonValidator.InvalidConstantTensor; +import com.yahoo.vespa.model.application.validation.ConstantTensorJsonValidator.InvalidConstantTensorException; import com.yahoo.vespa.model.search.NamedSchema; import java.io.FileNotFoundException; @@ -36,8 +36,8 @@ public class RankingConstantsValidator extends Validator { } } - static class TensorValidationFailed extends RuntimeException { - TensorValidationFailed(String message) { + static class TensorValidationException extends IllegalArgumentException { + TensorValidationException(String message) { super(message); } } @@ -51,14 +51,14 @@ public class RankingConstantsValidator extends Validator { for (RankingConstant rc : sd.getSearch().rankingConstants().asMap().values()) { try { validateRankingConstant(rc, applicationPackage); - } catch (InvalidConstantTensor | FileNotFoundException ex) { + } catch (InvalidConstantTensorException | FileNotFoundException ex) { exceptionMessageCollector.add(ex, rc.getName(), rc.getFileName()); } } } if (exceptionMessageCollector.exceptionsOccurred) { - throw new TensorValidationFailed(exceptionMessageCollector.combinedMessage); + throw new TensorValidationException(exceptionMessageCollector.combinedMessage); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/BinaryScaledAmountParser.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/BinaryScaledAmountParser.java index b163f9f0699..06747bdbd2c 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/BinaryScaledAmountParser.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/BinaryScaledAmountParser.java @@ -11,8 +11,9 @@ import java.util.regex.Pattern; * @author Tony Vaagenes */ public class BinaryScaledAmountParser { - //The pattern must match the one given in the schema - private static Pattern pattern = Pattern.compile("(\\d+(\\.\\d*)?)\\s*([kmgKMG])?"); + + // The pattern must match the one given in the schema + private static final Pattern pattern = Pattern.compile("(\\d+(\\.\\d*)?)\\s*([kmgKMG])?"); public static BinaryScaledAmount parse(String valueString) { Matcher matcher = pattern.matcher(valueString); @@ -34,4 +35,5 @@ public class BinaryScaledAmountParser { return BinaryPrefix.fromSymbol(binaryPrefixString.toUpperCase().charAt(0)); } } + } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/BinaryUnit.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/BinaryUnit.java index 1317f96e109..4a46b62d096 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/BinaryUnit.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/BinaryUnit.java @@ -10,8 +10,9 @@ import static com.yahoo.text.Lowercase.toLowerCase; * @author Tony Vaagenes */ public class BinaryUnit { - //The pattern must match the one given in the schema - private static Pattern pattern = Pattern.compile("(\\d+(\\.\\d*)?)\\s*([kmgKMG])?"); + + // The pattern must match the one given in the schema + private static final Pattern pattern = Pattern.compile("(\\d+(\\.\\d*)?)\\s*([kmgKMG])?"); public static double valueOf(String valueString) { Matcher matcher = pattern.matcher(valueString); @@ -28,13 +29,13 @@ public class BinaryUnit { } private static double unitToValue(char unit) { - final char units[] = {'k', 'm', 'g'}; - for (int i=0; i<units.length; ++i) { + char[] units = {'k', 'm', 'g'}; + for (int i = 0; i < units.length; ++i) { if (units[i] == unit) { return Math.pow(2, 10*(i+1)); } } - throw new RuntimeException("No such unit: '" + unit + "'"); + throw new IllegalArgumentException("No such unit: '" + unit + "'"); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/LegacyConfigModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/LegacyConfigModelBuilder.java index cecc258a3b8..40e457ba69b 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/LegacyConfigModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/LegacyConfigModelBuilder.java @@ -13,7 +13,6 @@ import org.w3c.dom.Element; * producer in between. This should not be used by new model plugins. * * @author Ulf Lilleengen - * @since 5.1 */ public abstract class LegacyConfigModelBuilder<MODEL extends ConfigModel> extends ConfigModelBuilder<MODEL> { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/VespaDomBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/VespaDomBuilder.java index 81923db15dd..cb19df16fd8 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/VespaDomBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/VespaDomBuilder.java @@ -69,20 +69,20 @@ public class VespaDomBuilder extends VespaModelBuilder { // TODO Move and change scope public static List<String> getHostAliases(NodeList hostAliases) { List<String> aliases = new LinkedList<>(); - for (int i=0; i < hostAliases.getLength(); i++) { + for (int i = 0; i < hostAliases.getLength(); i++) { Node n = hostAliases.item(i); if (! (n instanceof Element)) { continue; } Element e = (Element)n; if (! e.getNodeName().equals("alias")) { - throw new RuntimeException("Unexpected tag: '" + e.getNodeName() + "' at node " + - XML.getNodePath(e, " > ") + ", expected 'alias'."); + throw new IllegalArgumentException("Unexpected tag: '" + e.getNodeName() + "' at node " + + XML.getNodePath(e, " > ") + ", expected 'alias'."); } String alias = e.getFirstChild().getNodeValue(); if ((alias == null) || (alias.equals(""))) { - throw new RuntimeException("Missing value for the alias tag at node " + - XML.getNodePath(e, " > ") + "'."); + throw new IllegalArgumentException("Missing value for the alias tag at node " + + XML.getNodePath(e, " > ") + "'."); } aliases.add(alias); } @@ -113,7 +113,6 @@ public class VespaDomBuilder extends VespaModelBuilder { * include hostalias, baseport and user config overrides generically. * * @param <T> an {@link com.yahoo.config.model.producer.AbstractConfigProducer} - * @author vegardh */ public static abstract class DomConfigProducerBuilder<T extends AbstractConfigProducer<?>> { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/ComponentsBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/ComponentsBuilder.java index 560ede554e6..0d54b7b49f3 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/ComponentsBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/ComponentsBuilder.java @@ -134,15 +134,15 @@ public class ComponentsBuilder<T extends ChainedComponent<?>> { private void ensureNotDefinition(String componentName, Element componentSpec) { if (componentSpec.getAttributes().getLength() > 1 || !XML.getChildren(componentSpec).isEmpty()) - throw new RuntimeException("Expecting " + componentName + - " to be a reference to a global component with the same name," + - " so no additional attributes or nested elements are allowed"); + throw new IllegalArgumentException("Expecting " + componentName + + " to be a reference to a global component with the same name," + + " so no additional attributes or nested elements are allowed"); } private void ensureTypesMatch(ComponentType type1, ComponentType type2, String componentName) { if (!type1.equals(type2)) { - throw new RuntimeException("Two different types declared for the component with name '" + componentName + "' (" - + type1.name + " != " + type2.name + ")."); + throw new IllegalArgumentException("Two different types declared for the component with name '" + componentName + + "' (" + type1.name + " != " + type2.name + ")."); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/DomBuilderCreator.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/DomBuilderCreator.java index 92887bc3227..b62c1a01fa3 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/DomBuilderCreator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/DomBuilderCreator.java @@ -6,9 +6,11 @@ import java.lang.reflect.InvocationTargetException; /** * Utility class for instantiating a builder using reflection. + * * @author Tony Vaagenes */ public class DomBuilderCreator { + public static <T> T create(Class<T> builderClass, Object... parameters) { try { return getConstructor(builderClass).newInstance(parameters); @@ -23,4 +25,5 @@ public class DomBuilderCreator { assert(constructors.length == 1); return (Constructor<T>) constructors[0]; } + } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomProviderBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomProviderBuilder.java index 9db28c83a93..19c5c489f7e 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomProviderBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/chains/search/DomProviderBuilder.java @@ -157,7 +157,6 @@ public class DomProviderBuilder extends DomGenericTargetBuilder<Provider> { } } - @SuppressWarnings("deprecation") private Provider buildProvider(ChainSpecification specWithoutInnerSearchers, ProviderReader providerReader, FederationOptions federationOptions) { @@ -166,7 +165,7 @@ public class DomProviderBuilder extends DomGenericTargetBuilder<Provider> { } else if (LocalProviderSpec.includesType(providerReader.type)) { return buildLocalProvider(specWithoutInnerSearchers, providerReader, federationOptions); } else { - throw new RuntimeException("Unknown provider type '" + providerReader.type + "'"); + throw new IllegalArgumentException("Unknown provider type '" + providerReader.type + "'"); } } @@ -194,7 +193,7 @@ public class DomProviderBuilder extends DomGenericTargetBuilder<Provider> { private void ensureEmpty(ComponentId componentId, Object... objects) { for (Object object : objects) { if (object != null) { - throw new RuntimeException("Invalid provider option in provider '" + componentId + "': value='" + object + "'"); + throw new IllegalArgumentException("Invalid provider option in provider '" + componentId + "': value='" + object + "'"); } } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java index c73a3b2a676..3a2ca719460 100755 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java @@ -331,8 +331,8 @@ public abstract class ContainerCluster<CONTAINER extends Container> public SearchChains getSearchChains() { if (containerSearch == null) - throw new IllegalStateException("Search components not found in container cluster '" + getSubId() + - "': Add <search/> to the cluster in services.xml"); + throw new IllegalArgumentException("Search components not found in container cluster '" + getSubId() + + "': Add <search/> to the cluster in services.xml"); return containerSearch.getChains(); } @@ -371,8 +371,8 @@ public abstract class ContainerCluster<CONTAINER extends Container> public DocprocChains getDocprocChains() { if (containerDocproc == null) - throw new IllegalStateException("Document processing components not found in container cluster '" + getSubId() + - "': Add <document-processing/> to the cluster in services.xml"); + throw new IllegalArgumentException("Document processing components not found in container cluster '" + getSubId() + + "': Add <document-processing/> to the cluster in services.xml"); return containerDocproc.getChains(); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/component/AccessLogComponent.java b/config-model/src/main/java/com/yahoo/vespa/model/container/component/AccessLogComponent.java index e58adf8d6b9..78fea787b7c 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/component/AccessLogComponent.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/component/AccessLogComponent.java @@ -9,6 +9,8 @@ import com.yahoo.osgi.provider.model.ComponentModel; import com.yahoo.vespa.model.container.ApplicationContainerCluster; import com.yahoo.vespa.model.container.ContainerCluster; +import java.util.Objects; + /** * @author Tony Vaagenes * @author gjoranv @@ -52,7 +54,7 @@ public final class AccessLogComponent extends SimpleComponent implements AccessL Integer bufferSize) { super(new ComponentModel(accessLogClass(logType), null, "container-core", null)); - this.fileNamePattern = fileNamePattern; + this.fileNamePattern = Objects.requireNonNull(fileNamePattern, "File name pattern required when configuring access log"); this.rotationInterval = rotationInterval; this.compression = compressOnRotation; this.isHostedVespa = isHostedVespa; @@ -60,9 +62,6 @@ public final class AccessLogComponent extends SimpleComponent implements AccessL this.compressionType = compressionType; this.queueSize = (queueSize == null) ? 256 : queueSize; this.bufferSize = bufferSize; - - if (fileNamePattern == null) - throw new RuntimeException("File name pattern required when configuring access log."); } private static String accessLogClass(AccessLogType logType) { @@ -114,4 +113,5 @@ public final class AccessLogComponent extends SimpleComponent implements AccessL public String getFileNamePattern() { return fileNamePattern; } + } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/http/Http.java b/config-model/src/main/java/com/yahoo/vespa/model/container/http/Http.java index 59e8c493709..f5d1d3e6afd 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/http/Http.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/http/Http.java @@ -98,7 +98,7 @@ public class Http extends AbstractConfigProducer<AbstractConfigProducer<?>> impl for (FilterBinding binding: bindings) { if (filters.getComponent(binding.chainId()) == null && chains.getComponent(binding.chainId()) == null) - throw new RuntimeException("Can't find filter " + binding.chainId() + " for binding " + binding.binding()); + throw new IllegalArgumentException("Can't find filter " + binding.chainId() + " for binding " + binding.binding()); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/HttpBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/HttpBuilder.java index 1c0601915e9..13503906c04 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/HttpBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/HttpBuilder.java @@ -106,7 +106,7 @@ public class HttpBuilder extends VespaDomBuilder.DomConfigProducerBuilder<Http> .orElse(null); if (tenantDomain == null) { if (explicitDomain == null) { - throw new IllegalStateException("No Athenz domain provided for 'access-control'"); + throw new IllegalArgumentException("No Athenz domain provided for 'access-control'"); } deployState.getDeployLogger().logApplicationPackage(Level.WARNING, "Athenz tenant is not provided by deploy call. This will soon be handled as failure."); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTester.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTester.java index bf5bcbff360..6532fed9abf 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTester.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTester.java @@ -84,7 +84,7 @@ public class ModelsEvaluatorTester { return new ModelsEvaluator(rankProfilesConfig, rankingConstantsConfig, rankingExpressionsConfig, onnxModelsConfig, files); } catch (IOException | SAXException e) { - throw new RuntimeException(e); + throw new IllegalArgumentException(e); } finally { if (temporaryApplicationDir != null) { IOUtils.recursiveDeleteDir(temporaryApplicationDir); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/FederationSearcher.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/FederationSearcher.java index 55284c444e4..1abb62fedab 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/FederationSearcher.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/FederationSearcher.java @@ -208,14 +208,14 @@ public class FederationSearcher extends Searcher<FederationSearcherModel> implem Target target = targetResolver.resolve(targetSpec); if (target == null) { - throw new RuntimeException("Can't find source " + targetSpec.sourceSpec + - " used as a source for federation '" + getComponentId() + "'"); + throw new IllegalArgumentException("Can't find source " + targetSpec.sourceSpec + + " used as a source for federation '" + getComponentId() + "'"); } Target duplicate = resolvedTargets.put(target.id, target); if (duplicate != null && !duplicate.targetOptions.equals(target.targetOptions)) { - throw new RuntimeException("Search chain " + target.id + " added twice with different federation options" + - " to the federation searcher " + getComponentId()); + throw new IllegalArgumentException("Search chain " + target.id + " added twice with different federation options" + + " to the federation searcher " + getComponentId()); } } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SearchChains.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SearchChains.java index a733c2a0f30..a71e1936425 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SearchChains.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SearchChains.java @@ -41,9 +41,8 @@ public class SearchChains extends Chains<SearchChain> { private void setSearchClusterForLocalProvider(Map<String, ? extends AbstractSearchCluster> clusterIndexByName) { for (LocalProvider provider : localProviders()) { AbstractSearchCluster cluster = clusterIndexByName.get(provider.getClusterName()); - if (cluster == null) { - throw new RuntimeException("No searchable content cluster with id '" + provider.getClusterName() + "'"); - } + if (cluster == null) + throw new IllegalArgumentException("No searchable content cluster with id '" + provider.getClusterName() + "'"); provider.setSearchCluster(cluster); } } @@ -53,9 +52,8 @@ public class SearchChains extends Chains<SearchChain> { sourceGroup.validate(); if (getChainGroup().getComponentMap().containsKey(sourceGroup.getComponentId())) { - throw new RuntimeException( - String.format("Same id used for a source and another search chain/provider: '%s'", - sourceGroup.getComponentId())); + throw new IllegalArgumentException("Id '" + sourceGroup.getComponentId() + + "' is used both for a source and another search chain/provider"); } } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroup.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroup.java index 0be6675915c..7abb3111afd 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroup.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroup.java @@ -9,25 +9,21 @@ import java.util.LinkedHashSet; import java.util.Set; /** - * A set of sources with the same name, - * each associated with a different provider, - * that fills the same role. + * A set of sources with the same name, each associated with a different provider, that fills the same role. + * * @author Tony Vaagenes */ final class SourceGroup { + private final ComponentId id; private Source leader; - private final Set<Source> participants = - new LinkedHashSet<>(); + private final Set<Source> participants = new LinkedHashSet<>(); private void setLeader(Source leader) { assert (validMember(leader)); - if (this.leader != null) { - throw new IllegalStateException( - "There can not be two default providers for the source " - + id); - } + if (this.leader != null) + throw new IllegalArgumentException("There can not be two default providers for the source '" + id + "'"); this.leader = leader; } @@ -36,10 +32,8 @@ final class SourceGroup { assert (validMember(source)); assert (!source.equals(leader)); - if (!participants.add(source)) { - throw new RuntimeException("Source added twice to the same group " - + source); - } + if (!participants.add(source)) + throw new IllegalArgumentException("Source '" + source + "' added twice to the same group"); } private boolean validMember(Source leader) { @@ -55,8 +49,8 @@ final class SourceGroup { } public void add(Source source) { - assert source.getComponentId().equals(getComponentId()): - "Ids differ: " + source.getComponentId() + " -- " + getComponentId(); + if ( ! source.getComponentId().equals(getComponentId())) + throw new IllegalStateException("Ids differ: " + source.getComponentId() + " and " + getComponentId()); if (Source.GroupOption.leader == source.groupOption) { setLeader(source); @@ -89,7 +83,8 @@ final class SourceGroup { public void validate() { if (leader == null) - throw new IllegalStateException("Missing leader for the source " + getComponentId() + - ". One of the sources must use the attribute id instead of idref."); + throw new IllegalArgumentException("Missing leader for the source " + getComponentId() + + ". One of the sources must use the attribute id instead of idref."); } + } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilder.java index 5e1cf6db770..fbdefd0afb0 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilder.java @@ -43,7 +43,7 @@ public class BundleInstantiationSpecificationBuilder { for (String forbiddenClass: forbiddenClasses) { if (forbiddenClass.equals(instSpec.getClassName())) { - throw new RuntimeException("Setting up " + forbiddenClass + " manually is not supported."); + throw new IllegalArgumentException("Setting up " + forbiddenClass + " manually is not supported"); } } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java index 3bb1a9d2bf7..ca4ce666f90 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java @@ -281,7 +281,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { private void addCloudSecretStore(ApplicationContainerCluster cluster, Element secretStoreElement, DeployState deployState) { if ( ! deployState.isHosted()) return; if ( ! cluster.getZone().system().isPublic()) - throw new RuntimeException("cloud secret store is not supported in non-public system, please see documentation"); + throw new IllegalArgumentException("Cloud secret store is not supported in non-public system, see the documentation"); CloudSecretStore cloudSecretStore = new CloudSecretStore(); Map<String, TenantSecretStore> secretStoresByName = deployState.getProperties().tenantSecretStores() .stream() @@ -296,10 +296,10 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { TenantSecretStore secretStore = secretStoresByName.get(account); if (secretStore == null) - throw new RuntimeException("No configured secret store named " + account); + throw new IllegalArgumentException("No configured secret store named " + account); if (secretStore.getExternalId().isEmpty()) - throw new RuntimeException("No external ID has been set"); + throw new IllegalArgumentException("No external ID has been set"); cloudSecretStore.addConfig(account, region, secretStore.getAwsId(), secretStore.getRole(), secretStore.getExternalId().get()); } @@ -447,13 +447,14 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { if (deployState.endpointCertificateSecrets().isPresent()) { boolean authorizeClient = deployState.zone().system().isPublic(); if (authorizeClient && deployState.tlsClientAuthority().isEmpty()) { - throw new RuntimeException("Client certificate authority security/clients.pem is missing - see: https://cloud.vespa.ai/en/security-model#data-plane"); + throw new IllegalArgumentException("Client certificate authority security/clients.pem is missing - " + + "see: https://cloud.vespa.ai/en/security-model#data-plane"); } EndpointCertificateSecrets endpointCertificateSecrets = deployState.endpointCertificateSecrets().get(); boolean enforceHandshakeClientAuth = cluster.getHttp().getAccessControl() .map(accessControl -> accessControl.clientAuthentication) - .map(clientAuth -> clientAuth.equals(AccessControl.ClientAuthentication.need)) + .map(clientAuth -> clientAuth == AccessControl.ClientAuthentication.need) .orElse(false); connectorFactory = authorizeClient @@ -632,14 +633,14 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { private void checkVersion(Element spec) { String version = spec.getAttribute("version"); - if ( ! Version.fromString(version).equals(new Version(1))) { - throw new RuntimeException("Expected container version to be 1.0, but got " + version); - } + if ( ! Version.fromString(version).equals(new Version(1))) + throw new IllegalArgumentException("Expected container version to be 1.0, but got " + version); } private void checkTagName(Element spec, DeployLogger logger) { if (spec.getTagName().equals(DEPRECATED_CONTAINER_TAG)) { - logger.logApplicationPackage(WARNING, "'" + DEPRECATED_CONTAINER_TAG + "' is deprecated as tag name. Use '" + CONTAINER_TAG + "' instead."); + logger.logApplicationPackage(WARNING, "'" + DEPRECATED_CONTAINER_TAG + + "' is deprecated as tag name. Use '" + CONTAINER_TAG + "' instead."); } } @@ -1020,9 +1021,15 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { AthenzService service = spec.instance(app.getApplicationId().instance()) .flatMap(instanceSpec -> instanceSpec.athenzService(zone.environment(), zone.region())) .or(() -> spec.athenzService()) - .orElseThrow(() -> new RuntimeException("Missing Athenz service configuration in instance '" + app.getApplicationId().instance() + "'")); + .orElseThrow(() -> new IllegalArgumentException("Missing Athenz service configuration in instance '" + + app.getApplicationId().instance() + "'")); String zoneDnsSuffix = zone.environment().value() + "-" + zone.region().value() + "." + athenzDnsSuffix; - IdentityProvider identityProvider = new IdentityProvider(domain, service, getLoadBalancerName(loadBalancerName, configServerSpecs), ztsUrl, zoneDnsSuffix, zone); + IdentityProvider identityProvider = new IdentityProvider(domain, + service, + getLoadBalancerName(loadBalancerName, configServerSpecs), + ztsUrl, + zoneDnsSuffix, + zone); cluster.addComponent(identityProvider); cluster.getContainers().forEach(container -> { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/Content.java b/config-model/src/main/java/com/yahoo/vespa/model/content/Content.java index 533364d80c3..e69dd9abf47 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/Content.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/Content.java @@ -243,8 +243,8 @@ public class Content extends ConfigModel { String indexingClusterName = cluster.getIndexingClusterName(); ContainerModel containerModel = findByName(indexingClusterName, containers); if (containerModel == null) - throw new RuntimeException("Content cluster '" + cluster.getClusterName() + "' refers to docproc " + - "cluster '" + indexingClusterName + "', but this cluster does not exist."); + throw new IllegalArgumentException("Content cluster '" + cluster.getClusterName() + "' refers to docproc " + + "cluster '" + indexingClusterName + "', but this cluster does not exist."); addIndexingChainsTo(containerModel.getCluster(), cluster); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/ContentSearchCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/content/ContentSearchCluster.java index d0cba617cfc..602b3c0ed3a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/ContentSearchCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/ContentSearchCluster.java @@ -252,8 +252,8 @@ public class ContentSearchCluster extends AbstractConfigProducer<SearchCluster> NamedSchema searchDefinition = schemaDefinitionXMLHandler.getResponsibleSearchDefinition(deployState.getSchemas()); if (searchDefinition == null) - throw new RuntimeException("Schema '" + schemaDefinitionXMLHandler.getName() + "' referenced in " + - this + " does not exist"); + throw new IllegalArgumentException("Schema '" + schemaDefinitionXMLHandler.getName() + "' referenced in " + + this + " does not exist"); // TODO: remove explicit building of user configs when the complete content model is built using builders. sc.getLocalSDS().add(new AbstractSearchCluster.SchemaSpec(searchDefinition, @@ -265,11 +265,11 @@ public class ContentSearchCluster extends AbstractConfigProducer<SearchCluster> private void addCluster(AbstractSearchCluster sc) { if (clusters.containsKey(sc.getClusterName())) { - throw new IllegalArgumentException("I already have registered cluster '" + sc.getClusterName() + "'"); + throw new IllegalArgumentException("Duplicate cluster '" + sc.getClusterName() + "'"); } if (sc instanceof IndexedSearchCluster) { if (indexedCluster != null) { - throw new IllegalArgumentException("I already have one indexed cluster named '" + indexedCluster.getClusterName()); + throw new IllegalArgumentException("Duplicate indexed cluster '" + indexedCluster.getClusterName() + "'"); } indexedCluster = (IndexedSearchCluster)sc; } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/StorageGroup.java b/config-model/src/main/java/com/yahoo/vespa/model/content/StorageGroup.java index a07a36d800b..de50ba6ea21 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/StorageGroup.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/StorageGroup.java @@ -211,7 +211,7 @@ public class StorageGroup { Optional<ModelElement> nodes = getNodes(clusterElement); if (group.isPresent() && nodes.isPresent()) - throw new IllegalStateException("Both group and nodes exists, only one of these tags is legal"); + throw new IllegalArgumentException("Both <group> and <nodes> is specified: Only one of these tags can be used in the same configuration"); if (group.isPresent() && (group.get().stringAttribute("name") != null || group.get().integerAttribute("distribution-key") != null)) deployState.getDeployLogger().logApplicationPackage(Level.INFO, "'distribution-key' attribute on a content cluster's root group is ignored"); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java index 628cf6bb4c7..4a88e02be45 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java @@ -142,7 +142,7 @@ public class ContentCluster extends AbstractConfigProducer<AbstractConfigProduce setupSearchCluster(c.search, contentElement, deployState.getDeployLogger()); if (c.search.hasIndexedCluster() && !(c.persistenceFactory instanceof ProtonEngine.Factory) ) - throw new RuntimeException("Indexed search requires proton as engine"); + throw new IllegalArgumentException("Indexed search requires proton as engine"); if (documentsElement != null) { ModelElement e = documentsElement.child("document-processing"); @@ -220,14 +220,14 @@ public class ContentCluster extends AbstractConfigProducer<AbstractConfigProduce if (distribution != null) { String attr = distribution.stringAttribute("type"); if (attr != null) { - if (attr.toLowerCase().equals("strict")) { + if (attr.equalsIgnoreCase("strict")) { c.distributionMode = DistributionMode.STRICT; - } else if (attr.toLowerCase().equals("loose")) { + } else if (attr.equalsIgnoreCase("loose")) { c.distributionMode = DistributionMode.LOOSE; - } else if (attr.toLowerCase().equals("legacy")) { + } else if (attr.equalsIgnoreCase("legacy")) { c.distributionMode = DistributionMode.LEGACY; } else { - throw new IllegalStateException("Distribution type " + attr + " not supported."); + throw new IllegalArgumentException("Distribution type " + attr + " not supported."); } } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/SearchDefinitionBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/SearchDefinitionBuilder.java index d80cb0056fa..f45bc8f4eca 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/SearchDefinitionBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/SearchDefinitionBuilder.java @@ -23,7 +23,7 @@ public class SearchDefinitionBuilder { if (documentType != null) { docTypes.put(documentType.getName(), documentType); } else { - throw new RuntimeException("Document type '" + name + "' not found in application package"); + throw new IllegalArgumentException("Document type '" + name + "' not found in application package"); } } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/routing/DocumentProtocol.java b/config-model/src/main/java/com/yahoo/vespa/model/routing/DocumentProtocol.java index e642da6176e..754800a42e1 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/routing/DocumentProtocol.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/routing/DocumentProtocol.java @@ -317,7 +317,7 @@ public final class DocumentProtocol implements Protocol, DocprocChain defaultChain = getDefaultChain(containerCluster.getDocproc()); if (defaultChain != null) { if (result != null) - throw new RuntimeException("Only a single default docproc chain is allowed across all container clusters"); + throw new IllegalArgumentException("Only a single default docproc chain is allowed across all container clusters"); result = defaultChain; } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/search/StreamingSearchCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/search/StreamingSearchCluster.java index 7b328acdc98..bacba9ea61d 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/search/StreamingSearchCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/search/StreamingSearchCluster.java @@ -87,12 +87,13 @@ public class StreamingSearchCluster extends SearchCluster implements if (local.size() == 1) { deriveSingleSearchDefinition(local.get(0).getSearchDefinition().getSearch(), deployState); } else if (local.size() > 1){ - throw new IllegalStateException("Logical indexes are not supported: Got " + local.size() + " search definitions, expected 1"); + throw new IllegalArgumentException("Only a single schema is supported, got " + local.size()); } } private void deriveSingleSearchDefinition(Schema localSchema, DeployState deployState) { if (!localSchema.getName().equals(docTypeName)) { - throw new IllegalStateException("Mismatch between document type name (" + docTypeName + ") and name of search definition (" + localSchema.getName() + ")"); + throw new IllegalArgumentException("Document type name '" + docTypeName + + "' must be the same as the schema name '" + localSchema.getName() + "'"); } this.sdConfig = new DerivedConfiguration(localSchema, deployState.getDeployLogger(), deployState.getProperties(), diff --git a/config-model/src/main/java/com/yahoo/vespa/model/search/Tuning.java b/config-model/src/main/java/com/yahoo/vespa/model/search/Tuning.java index c6d94ccfea0..2f28da60e7b 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/search/Tuning.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/search/Tuning.java @@ -294,7 +294,7 @@ public class Tuning extends AbstractConfigProducer<Tuning> implements ProtonConf public void getConfig(ProtonConfig.Summary.Log.Chunk.Builder chunk) { if (outputInt) { - if (maxSize!=null) chunk.maxbytes(maxSize.intValue()); + if (maxSize != null) chunk.maxbytes(maxSize.intValue()); } else { throw new IllegalStateException("Fix this, chunk does not have long types"); } @@ -305,6 +305,7 @@ public class Tuning extends AbstractConfigProducer<Tuning> implements ProtonConf } public static class LogStore { + public Long maxFileSize = null; public Component chunk = null; public Double minFileSizeFactor = null; 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 7dabefeec47..9f049f727d6 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 @@ -14,6 +14,7 @@ import java.util.Set; * @author Tony Vaagenes */ public class FreezableMap<K, V> implements Map<K, V> { + private boolean frozen = false; private Map<K, V> map; @@ -85,7 +86,7 @@ public class FreezableMap<K, V> implements Map<K, V> { public void freeze() { if (frozen) - throw new RuntimeException("The map has already been frozen."); + throw new IllegalStateException("The map has already been frozen"); frozen = true; map = Collections.unmodifiableMap(map); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/utils/internal/ReflectionUtil.java b/config-model/src/main/java/com/yahoo/vespa/model/utils/internal/ReflectionUtil.java index 799107ea763..3ba536b4e9b 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/utils/internal/ReflectionUtil.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/utils/internal/ReflectionUtil.java @@ -23,8 +23,7 @@ import java.util.stream.Collectors; */ public final class ReflectionUtil { - private ReflectionUtil() { - } + private ReflectionUtil() {} public static Set<ConfigKey<?>> getAllConfigsProduced(Class<? extends ConfigProducer> producerClass, String configId) { // TypeToken is @Beta in guava, so consider implementing a simple recursive method instead. @@ -64,6 +63,7 @@ public final class ReflectionUtil { /** * Compares the config instances and lists any differences that will require service restart. + * * @param from The previous config. * @param to The new config. * @return An object describing the difference. @@ -91,13 +91,9 @@ public final class ReflectionUtil { } private static ConfigKey<?> createConfigKeyFromInstance(Class<?> configInstClass, String configId) { - try { - String defName = ConfigInstance.getDefName(configInstClass); - String defNamespace = ConfigInstance.getDefNamespace(configInstClass); - return new ConfigKey<>(defName, configId, defNamespace); - } catch (IllegalArgumentException | SecurityException e) { - throw new RuntimeException(e); - } + String defName = ConfigInstance.getDefName(configInstClass); + String defNamespace = ConfigInstance.getDefNamespace(configInstClass); + return new ConfigKey<>(defName, configId, defNamespace); } private static boolean isConcreteProducer(Class<?> producerInterface) { |