-
Notifications
You must be signed in to change notification settings - Fork 968
Fix/declarative config no exceptions #8079
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
Changes from 3 commits
df9a72b
6eed41c
2012cd9
153c5d1
f6e7582
df0a7b7
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 |
|---|---|---|
|
|
@@ -156,18 +156,21 @@ private static boolean isMap(Object object) { | |
| @Nullable | ||
| @Override | ||
| public String getString(String name) { | ||
| Objects.requireNonNull(name, "name"); | ||
|
Contributor
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. The only doubt I have here is that the result of getString(null) will be NPE with quite cryptic message "name".
Contributor
Author
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. Good catch, updated the message to be more descriptive. Thanks! |
||
| return stringOrNull(simpleEntries.get(name), name); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Boolean getBoolean(String name) { | ||
| Objects.requireNonNull(name, "name"); | ||
| return booleanOrNull(simpleEntries.get(name), name); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Integer getInt(String name) { | ||
| Objects.requireNonNull(name, "name"); | ||
| Object value = simpleEntries.get(name); | ||
| if (value instanceof Integer) { | ||
| return (Integer) value; | ||
|
|
@@ -184,19 +187,22 @@ public Integer getInt(String name) { | |
| @Nullable | ||
| @Override | ||
| public Long getLong(String name) { | ||
| Objects.requireNonNull(name, "name"); | ||
| return longOrNull(simpleEntries.get(name), name); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Double getDouble(String name) { | ||
| Objects.requireNonNull(name, "name"); | ||
| return doubleOrNull(simpleEntries.get(name), name); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| @SuppressWarnings("unchecked") | ||
| public <T> List<T> getScalarList(String name, Class<T> scalarType) { | ||
| Objects.requireNonNull(name, "name"); | ||
| if (!SUPPORTED_SCALAR_TYPES.contains(scalarType)) { | ||
| throw new DeclarativeConfigException( | ||
| "Unsupported scalar type " | ||
|
|
@@ -291,12 +297,14 @@ private static Double doubleOrNull(@Nullable Object value, String name) { | |
| @Nullable | ||
| @Override | ||
| public DeclarativeConfigProperties getStructured(String name) { | ||
| Objects.requireNonNull(name, "name"); | ||
| return mapEntries.get(name); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public List<DeclarativeConfigProperties> getStructuredList(String name) { | ||
| Objects.requireNonNull(name, "name"); | ||
| List<YamlDeclarativeConfigProperties> value = listEntries.get(name); | ||
| if (value != null) { | ||
| return Collections.unmodifiableList(value); | ||
|
|
@@ -315,7 +323,8 @@ public Set<String> getPropertyKeys() { | |
|
|
||
| @Override | ||
| public String toString() { | ||
| StringJoiner joiner = new StringJoiner(", ", "YamlDeclarativeConfigProperties{", "}"); | ||
| StringJoiner joiner = | ||
| new StringJoiner(", ", YamlDeclarativeConfigProperties.class.getSimpleName() + "{", "}"); | ||
| simpleEntries.forEach((key, value) -> joiner.add(key + "=" + value)); | ||
| listEntries.forEach((key, value) -> joiner.add(key + "=" + value)); | ||
| mapEntries.forEach((key, value) -> joiner.add(key + "=" + value)); | ||
|
|
||
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.
For consistency I'd recommend adding here also:
Objects.requireNonNull(defaultValue, "Null default value");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.
Makes sense, added the null check for
defaultValuetoo.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.
We need to get consistent about whether or not we do this. We rely on
javax.annotation.Nullableannotation, the assumption that params and returns are non-null unless otherwise specified, leveraging thenet.ltgt.nullawayerror prone plugin to validate at build time. Of course, at runtime there is no guarantee that callers adhere to these annotations, and so we have code like this which checks for null despite the params being non-null according to the annotations.We need to be consistent about:
Let's hold off here until we get some repo level guidance on this. ConfigProperties, the env var / sys property analog of
DeclarativeConfigProperties, has the exact same method and does not do this null check.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.
Created #8173 to track.