Skip to content

Commit 13c2e30

Browse files
authored
Merge pull request #237 from avaje/feature/add-missing-nullable
Add missing @nullable annotations on internal methods
2 parents 51be902 + ff30542 commit 13c2e30

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

avaje-config/src/main/java/io/avaje/config/Configuration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ interface ExpressionEval {
569569
/**
570570
* Evaluate a configuration expression.
571571
*/
572-
String eval(String expression);
572+
@Nullable
573+
String eval(@Nullable String expression);
573574
}
574575

575576
/**
@@ -818,11 +819,13 @@ interface Entry {
818819
/**
819820
* Return the source of the entry.
820821
*/
822+
@Nullable
821823
String source();
822824

823825
/**
824826
* Return the String value of the entry.
825827
*/
828+
@Nullable
826829
String value();
827830
}
828831
}

avaje-config/src/main/java/io/avaje/config/CoreConfiguration.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ final class CoreConfiguration implements Configuration {
4040
private final List<ConfigurationPlugin> plugins;
4141

4242
private boolean loadedSystemProperties;
43-
private FileWatch watcher;
44-
private Timer timer;
43+
private @Nullable FileWatch watcher;
44+
private @Nullable Timer timer;
4545
private final String pathPrefix;
4646

4747
CoreConfiguration(CoreComponents components, CoreEntry.CoreMap entries) {
@@ -259,7 +259,8 @@ public String getNullable(String key) {
259259
}
260260

261261
@Override
262-
public String getNullable(String key, String defaultValue) {
262+
@Nullable
263+
public String getNullable(String key, @Nullable String defaultValue) {
263264
requireNonNull(key, "key is required");
264265
return properties.entry(key, defaultValue).value();
265266
}
@@ -268,7 +269,7 @@ public String getNullable(String key, String defaultValue) {
268269
public String get(String key, String defaultValue) {
269270
requireNonNull(key, "key is required");
270271
requireNonNull(defaultValue, "defaultValue is required, use getOptional() instead");
271-
return properties.entry(key, defaultValue).value();
272+
return requireNonNull(properties.entry(key, defaultValue).value());
272273
}
273274

274275
@Override
@@ -277,7 +278,7 @@ public Optional<String> getOptional(String key) {
277278
}
278279

279280
@Override
280-
public Optional<String> getOptional(String key, String defaultValue) {
281+
public Optional<String> getOptional(String key, @Nullable String defaultValue) {
281282
return Optional.ofNullable(getNullable(key, defaultValue));
282283
}
283284

@@ -504,6 +505,7 @@ int size() {
504505
return entries.size();
505506
}
506507

508+
@Nullable
507509
String eval(String value) {
508510
return eval.eval(value);
509511
}
@@ -527,7 +529,7 @@ CoreEntry entry(String key) {
527529
return _entry(key, null);
528530
}
529531

530-
CoreEntry entry(String key, String defaultValue) {
532+
CoreEntry entry(String key, @Nullable String defaultValue) {
531533
return _entry(key, defaultValue);
532534
}
533535

@@ -576,7 +578,7 @@ private static String systemValue(String key) {
576578
void loadIntoSystemProperties(Set<String> excludedSet) {
577579
entries.forEach((key, entry) -> {
578580
if (!excludedSet.contains(key) && !entry.isNull()) {
579-
System.setProperty(key, entry.value());
581+
System.setProperty(key, requireNonNull(entry.value()));
580582
}
581583
});
582584
}

avaje-config/src/main/java/io/avaje/config/CoreEntry.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ final class CoreEntry implements Configuration.Entry {
2020
*/
2121
static final CoreEntry NULL_ENTRY = new CoreEntry();
2222

23-
private final String value;
23+
private @Nullable final String value;
2424
private final boolean boolValue;
25-
private final String source;
25+
private @Nullable final String source;
2626

2727
/**
2828
* Return a new empty entryMap for entries.
@@ -80,6 +80,7 @@ boolean needsEvaluation() {
8080
}
8181

8282
@Override
83+
@Nullable
8384
public String value() {
8485
return value;
8586
}
@@ -89,6 +90,7 @@ boolean boolValue() {
8990
}
9091

9192
@Override
93+
@Nullable
9294
public String source() {
9395
return source;
9496
}

avaje-config/src/main/java/io/avaje/config/CoreExpressionEval.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package io.avaje.config;
22

3+
import org.jspecify.annotations.Nullable;
4+
35
import java.util.Properties;
46

7+
import static java.util.Objects.requireNonNull;
8+
59
/**
610
* Helper used to evaluate expressions such as ${CATALINA_HOME}.
711
* <p>
@@ -51,14 +55,15 @@ static CoreEntry.CoreMap evalFor(CoreEntry.CoreMap map) {
5155
private CoreEntry.CoreMap evalAll() {
5256
sourceMap.forEach((key, entry) -> {
5357
if (entry.needsEvaluation()) {
54-
sourceMap.put(key, eval(entry.value()), entry.source());
58+
sourceMap.put(key, eval(entry.value()), requireNonNull(entry.source()));
5559
}
5660
});
5761
return sourceMap;
5862
}
5963

6064
@Override
61-
public String eval(String val) {
65+
@Nullable
66+
public String eval(@Nullable String val) {
6267
return val == null ? null : evalRecurse(val);
6368
}
6469

0 commit comments

Comments
 (0)