-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CORE: Validate Type for String Settings #33503
Changes from 3 commits
b4b78dc
9f3ab94
a3073cc
eda6e87
1ec003a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,6 +245,30 @@ public String get(String setting, String defaultValue) { | |
return retVal == null ? defaultValue : retVal; | ||
} | ||
|
||
/** | ||
* Returns the setting value associated with the setting key. If it does not exists, | ||
* returns the default value provided. | ||
*/ | ||
public String get(String setting, String defaultValue, boolean isList) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be package private? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea I think so will adjust in a bit :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
Object value = settings.get(setting); | ||
if(value != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
if (value instanceof List) { | ||
if (isList == false) { | ||
throw new IllegalArgumentException( | ||
"Found list type value for setting [" + setting + "] but but did not expect a list for it." | ||
); | ||
} | ||
} else if (isList) { | ||
throw new IllegalArgumentException( | ||
"Expected list type value for setting [" + setting + "] but found [" + value.getClass() + ']' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that will fail compilation? 😇 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compiles just fine for me? :) What am I missing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, never mind, I misread. Sorry for that. 😄 |
||
); | ||
} | ||
return toString(value); | ||
} else { | ||
return defaultValue; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the setting value (as float) associated with the setting key. If it does not exists, | ||
* returns the default value provided. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having an isListSetting, since this is already package private anyways, can this just check
instanceof ListSetting
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yea it could :) -> will change to that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@original-brownbear @rjernst See my diff, we need to expose
Setting#isListSetting
inAbstractScopedSettings
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its implementation though can be
final
and be an instance of check againstListSetting
.