3838import org .apache .lucene .search .spell .LevenshteinDistance ;
3939import org .apache .lucene .util .CollectionUtil ;
4040import org .opensearch .ExceptionsHelper ;
41- import org .opensearch .InvalidArgumentException ;
4241import org .opensearch .common .collect .Tuple ;
4342import org .opensearch .common .regex .Regex ;
4443
@@ -100,16 +99,14 @@ protected AbstractScopedSettings(
10099 Map <String , Setting <?>> keySettings = new HashMap <>();
101100 for (Setting <?> setting : settingsSet ) {
102101 if (setting .getProperties ().contains (scope ) == false ) {
103- throw new InvalidArgumentException (
104- "Setting " + setting + " must be a " + scope + " setting but has: " + setting .getProperties ()
105- );
102+ throw new SettingsException ("Setting " + setting + " must be a " + scope + " setting but has: " + setting .getProperties ());
106103 }
107104 validateSettingKey (setting );
108105
109106 if (setting .hasComplexMatcher ()) {
110107 Setting <?> overlappingSetting = findOverlappingSetting (setting , complexMatchers );
111108 if (overlappingSetting != null ) {
112- throw new InvalidArgumentException (
109+ throw new SettingsException (
113110 "complex setting key: ["
114111 + setting .getKey ()
115112 + "] overlaps existing setting key: ["
@@ -130,7 +127,7 @@ protected void validateSettingKey(Setting<?> setting) {
130127 if (isValidKey (setting .getKey ()) == false
131128 && (setting .isGroupSetting () && isValidGroupKey (setting .getKey ()) || isValidAffixKey (setting .getKey ())) == false
132129 || setting .getKey ().endsWith (".0" )) {
133- throw new InvalidArgumentException ("illegal settings key: [" + setting .getKey () + "]" );
130+ throw new SettingsException ("illegal settings key: [" + setting .getKey () + "]" );
134131 }
135132 }
136133
@@ -232,7 +229,7 @@ public synchronized Settings applySettings(Settings newSettings) {
232229 */
233230 public synchronized <T > void addSettingsUpdateConsumer (Setting <T > setting , Consumer <T > consumer , Consumer <T > validator ) {
234231 if (setting != get (setting .getKey ())) {
235- throw new InvalidArgumentException ("Setting is not registered for key [" + setting .getKey () + "]" );
232+ throw new SettingsException ("Setting is not registered for key [" + setting .getKey () + "]" );
236233 }
237234 addSettingsUpdater (setting .newUpdater (consumer , logger , validator ));
238235 }
@@ -395,7 +392,7 @@ public void apply(Map<String, Settings> values, Settings current, Settings previ
395392 private void ensureSettingIsRegistered (Setting .AffixSetting <?> setting ) {
396393 final Setting <?> registeredSetting = this .complexMatchers .get (setting .getKey ());
397394 if (setting != registeredSetting ) {
398- throw new InvalidArgumentException ("Setting is not registered for key [" + setting .getKey () + "]" );
395+ throw new SettingsException ("Setting is not registered for key [" + setting .getKey () + "]" );
399396 }
400397 }
401398
@@ -411,7 +408,7 @@ public synchronized <T> void addAffixMapUpdateConsumer(
411408 ) {
412409 final Setting <?> registeredSetting = this .complexMatchers .get (setting .getKey ());
413410 if (setting != registeredSetting ) {
414- throw new InvalidArgumentException ("Setting is not registered for key [" + setting .getKey () + "]" );
411+ throw new SettingsException ("Setting is not registered for key [" + setting .getKey () + "]" );
415412 }
416413 addSettingsUpdater (setting .newAffixMapUpdater (consumer , logger , validator ));
417414 }
@@ -444,10 +441,10 @@ public synchronized <A, B> void addSettingsUpdateConsumer(
444441 BiConsumer <A , B > validator
445442 ) {
446443 if (a != get (a .getKey ())) {
447- throw new InvalidArgumentException ("Setting is not registered for key [" + a .getKey () + "]" );
444+ throw new SettingsException ("Setting is not registered for key [" + a .getKey () + "]" );
448445 }
449446 if (b != get (b .getKey ())) {
450- throw new InvalidArgumentException ("Setting is not registered for key [" + b .getKey () + "]" );
447+ throw new SettingsException ("Setting is not registered for key [" + b .getKey () + "]" );
451448 }
452449 addSettingsUpdater (Setting .compoundUpdater (consumer , validator , a , b , logger ));
453450 }
@@ -544,7 +541,7 @@ public final void validate(
544541 * @param key the key of the setting to validate
545542 * @param settings the settings
546543 * @param validateDependencies true if dependent settings should be validated
547- * @throws IllegalArgumentException if the setting is invalid
544+ * @throws SettingsException if the setting is invalid
548545 */
549546 void validate (final String key , final Settings settings , final boolean validateDependencies ) {
550547 validate (key , settings , validateDependencies , false );
@@ -557,7 +554,7 @@ void validate(final String key, final Settings settings, final boolean validateD
557554 * @param settings the settings
558555 * @param validateDependencies true if dependent settings should be validated
559556 * @param validateInternalOrPrivateIndex true if internal index settings should be validated
560- * @throws IllegalArgumentException if the setting is invalid
557+ * @throws SettingsException if the setting is invalid
561558 */
562559 void validate (
563560 final String key ,
@@ -589,7 +586,7 @@ void validate(
589586 msg += " please check that any required plugins are installed, or check the breaking changes documentation for removed "
590587 + "settings" ;
591588 }
592- throw new InvalidArgumentException (msg );
589+ throw new SettingsException (msg );
593590 } else {
594591 Set <Setting .SettingDependency > settingsDependencies = setting .getSettingsDependencies (key );
595592 if (setting .hasComplexMatcher ()) {
@@ -606,7 +603,7 @@ void validate(
606603 dependency .getKey (),
607604 setting .getKey ()
608605 );
609- throw new InvalidArgumentException (message );
606+ throw new SettingsException (message );
610607 }
611608 // validate the dependent setting value
612609 settingDependency .validate (setting .getKey (), setting .get (settings ), dependency .get (settings ));
@@ -615,11 +612,11 @@ void validate(
615612 // the only time that validateInternalOrPrivateIndex should be true is if this call is coming via the update settings API
616613 if (validateInternalOrPrivateIndex ) {
617614 if (setting .isInternalIndex ()) {
618- throw new InvalidArgumentException (
615+ throw new SettingsException (
619616 "can not update internal setting [" + setting .getKey () + "]; this setting is managed via a dedicated API"
620617 );
621618 } else if (setting .isPrivateIndex ()) {
622- throw new InvalidArgumentException (
619+ throw new SettingsException (
623620 "can not update private setting [" + setting .getKey () + "]; this setting is managed by OpenSearch"
624621 );
625622 }
@@ -766,12 +763,12 @@ public Settings diff(Settings source, Settings defaultSettings) {
766763 */
767764 public <T > T get (Setting <T > setting ) {
768765 if (setting .getProperties ().contains (scope ) == false ) {
769- throw new InvalidArgumentException (
766+ throw new SettingsException (
770767 "settings scope doesn't match the setting scope [" + this .scope + "] not in [" + setting .getProperties () + "]"
771768 );
772769 }
773770 if (get (setting .getKey ()) == null ) {
774- throw new InvalidArgumentException ("setting " + setting .getKey () + " has not been registered" );
771+ throw new SettingsException ("setting " + setting .getKey () + " has not been registered" );
775772 }
776773 return setting .get (this .lastSettingsApplied , settings );
777774 }
@@ -780,7 +777,7 @@ public <T> T get(Setting<T> setting) {
780777 * Updates a target settings builder with new, updated or deleted settings from a given settings builder.
781778 * <p>
782779 * Note: This method will only allow updates to dynamic settings. if a non-dynamic setting is updated an
783- * {@link IllegalArgumentException } is thrown instead.
780+ * {@link SettingsException } is thrown instead.
784781 * </p>
785782 *
786783 * @param toApply the new settings to apply
@@ -844,17 +841,17 @@ private boolean updateSettings(Settings toApply, Settings.Builder target, Settin
844841 toRemove .add (key );
845842 // we don't set changed here it's set after we apply deletes below if something actually changed
846843 } else if (get (key ) == null ) {
847- throw new InvalidArgumentException (type + " setting [" + key + "], not recognized" );
844+ throw new SettingsException (type + " setting [" + key + "], not recognized" );
848845 } else if (isDelete == false && canUpdate .test (key )) {
849846 get (key ).validateWithoutDependencies (toApply ); // we might not have a full picture here do to a dependency validation
850847 settingsBuilder .copy (key , toApply );
851848 updates .copy (key , toApply );
852849 changed |= toApply .get (key ).equals (target .get (key )) == false ;
853850 } else {
854851 if (isFinalSetting (key )) {
855- throw new InvalidArgumentException ("final " + type + " setting [" + key + "], not updateable" );
852+ throw new SettingsException ("final " + type + " setting [" + key + "], not updateable" );
856853 } else {
857- throw new InvalidArgumentException (type + " setting [" + key + "], not dynamically updateable" );
854+ throw new SettingsException (type + " setting [" + key + "], not dynamically updateable" );
858855 }
859856 }
860857 }
0 commit comments