38
38
import org .apache .lucene .search .spell .LevenshteinDistance ;
39
39
import org .apache .lucene .util .CollectionUtil ;
40
40
import org .opensearch .ExceptionsHelper ;
41
- import org .opensearch .InvalidArgumentException ;
42
41
import org .opensearch .common .collect .Tuple ;
43
42
import org .opensearch .common .regex .Regex ;
44
43
@@ -100,16 +99,14 @@ protected AbstractScopedSettings(
100
99
Map <String , Setting <?>> keySettings = new HashMap <>();
101
100
for (Setting <?> setting : settingsSet ) {
102
101
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 ());
106
103
}
107
104
validateSettingKey (setting );
108
105
109
106
if (setting .hasComplexMatcher ()) {
110
107
Setting <?> overlappingSetting = findOverlappingSetting (setting , complexMatchers );
111
108
if (overlappingSetting != null ) {
112
- throw new InvalidArgumentException (
109
+ throw new SettingsException (
113
110
"complex setting key: ["
114
111
+ setting .getKey ()
115
112
+ "] overlaps existing setting key: ["
@@ -130,7 +127,7 @@ protected void validateSettingKey(Setting<?> setting) {
130
127
if (isValidKey (setting .getKey ()) == false
131
128
&& (setting .isGroupSetting () && isValidGroupKey (setting .getKey ()) || isValidAffixKey (setting .getKey ())) == false
132
129
|| setting .getKey ().endsWith (".0" )) {
133
- throw new InvalidArgumentException ("illegal settings key: [" + setting .getKey () + "]" );
130
+ throw new SettingsException ("illegal settings key: [" + setting .getKey () + "]" );
134
131
}
135
132
}
136
133
@@ -232,7 +229,7 @@ public synchronized Settings applySettings(Settings newSettings) {
232
229
*/
233
230
public synchronized <T > void addSettingsUpdateConsumer (Setting <T > setting , Consumer <T > consumer , Consumer <T > validator ) {
234
231
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 () + "]" );
236
233
}
237
234
addSettingsUpdater (setting .newUpdater (consumer , logger , validator ));
238
235
}
@@ -395,7 +392,7 @@ public void apply(Map<String, Settings> values, Settings current, Settings previ
395
392
private void ensureSettingIsRegistered (Setting .AffixSetting <?> setting ) {
396
393
final Setting <?> registeredSetting = this .complexMatchers .get (setting .getKey ());
397
394
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 () + "]" );
399
396
}
400
397
}
401
398
@@ -411,7 +408,7 @@ public synchronized <T> void addAffixMapUpdateConsumer(
411
408
) {
412
409
final Setting <?> registeredSetting = this .complexMatchers .get (setting .getKey ());
413
410
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 () + "]" );
415
412
}
416
413
addSettingsUpdater (setting .newAffixMapUpdater (consumer , logger , validator ));
417
414
}
@@ -444,10 +441,10 @@ public synchronized <A, B> void addSettingsUpdateConsumer(
444
441
BiConsumer <A , B > validator
445
442
) {
446
443
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 () + "]" );
448
445
}
449
446
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 () + "]" );
451
448
}
452
449
addSettingsUpdater (Setting .compoundUpdater (consumer , validator , a , b , logger ));
453
450
}
@@ -544,7 +541,7 @@ public final void validate(
544
541
* @param key the key of the setting to validate
545
542
* @param settings the settings
546
543
* @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
548
545
*/
549
546
void validate (final String key , final Settings settings , final boolean validateDependencies ) {
550
547
validate (key , settings , validateDependencies , false );
@@ -557,7 +554,7 @@ void validate(final String key, final Settings settings, final boolean validateD
557
554
* @param settings the settings
558
555
* @param validateDependencies true if dependent settings should be validated
559
556
* @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
561
558
*/
562
559
void validate (
563
560
final String key ,
@@ -589,7 +586,7 @@ void validate(
589
586
msg += " please check that any required plugins are installed, or check the breaking changes documentation for removed "
590
587
+ "settings" ;
591
588
}
592
- throw new InvalidArgumentException (msg );
589
+ throw new SettingsException (msg );
593
590
} else {
594
591
Set <Setting .SettingDependency > settingsDependencies = setting .getSettingsDependencies (key );
595
592
if (setting .hasComplexMatcher ()) {
@@ -606,7 +603,7 @@ void validate(
606
603
dependency .getKey (),
607
604
setting .getKey ()
608
605
);
609
- throw new InvalidArgumentException (message );
606
+ throw new SettingsException (message );
610
607
}
611
608
// validate the dependent setting value
612
609
settingDependency .validate (setting .getKey (), setting .get (settings ), dependency .get (settings ));
@@ -615,11 +612,11 @@ void validate(
615
612
// the only time that validateInternalOrPrivateIndex should be true is if this call is coming via the update settings API
616
613
if (validateInternalOrPrivateIndex ) {
617
614
if (setting .isInternalIndex ()) {
618
- throw new InvalidArgumentException (
615
+ throw new SettingsException (
619
616
"can not update internal setting [" + setting .getKey () + "]; this setting is managed via a dedicated API"
620
617
);
621
618
} else if (setting .isPrivateIndex ()) {
622
- throw new InvalidArgumentException (
619
+ throw new SettingsException (
623
620
"can not update private setting [" + setting .getKey () + "]; this setting is managed by OpenSearch"
624
621
);
625
622
}
@@ -766,12 +763,12 @@ public Settings diff(Settings source, Settings defaultSettings) {
766
763
*/
767
764
public <T > T get (Setting <T > setting ) {
768
765
if (setting .getProperties ().contains (scope ) == false ) {
769
- throw new InvalidArgumentException (
766
+ throw new SettingsException (
770
767
"settings scope doesn't match the setting scope [" + this .scope + "] not in [" + setting .getProperties () + "]"
771
768
);
772
769
}
773
770
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" );
775
772
}
776
773
return setting .get (this .lastSettingsApplied , settings );
777
774
}
@@ -780,7 +777,7 @@ public <T> T get(Setting<T> setting) {
780
777
* Updates a target settings builder with new, updated or deleted settings from a given settings builder.
781
778
* <p>
782
779
* 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.
784
781
* </p>
785
782
*
786
783
* @param toApply the new settings to apply
@@ -844,17 +841,17 @@ private boolean updateSettings(Settings toApply, Settings.Builder target, Settin
844
841
toRemove .add (key );
845
842
// we don't set changed here it's set after we apply deletes below if something actually changed
846
843
} else if (get (key ) == null ) {
847
- throw new InvalidArgumentException (type + " setting [" + key + "], not recognized" );
844
+ throw new SettingsException (type + " setting [" + key + "], not recognized" );
848
845
} else if (isDelete == false && canUpdate .test (key )) {
849
846
get (key ).validateWithoutDependencies (toApply ); // we might not have a full picture here do to a dependency validation
850
847
settingsBuilder .copy (key , toApply );
851
848
updates .copy (key , toApply );
852
849
changed |= toApply .get (key ).equals (target .get (key )) == false ;
853
850
} else {
854
851
if (isFinalSetting (key )) {
855
- throw new InvalidArgumentException ("final " + type + " setting [" + key + "], not updateable" );
852
+ throw new SettingsException ("final " + type + " setting [" + key + "], not updateable" );
856
853
} else {
857
- throw new InvalidArgumentException (type + " setting [" + key + "], not dynamically updateable" );
854
+ throw new SettingsException (type + " setting [" + key + "], not dynamically updateable" );
858
855
}
859
856
}
860
857
}
0 commit comments