Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

private String resolve(@NonNull String key) {
String env = envValue(key);
if (env != null) {
return env;
}
if (env != null) return env;
String sys = System.getProperty(prefix + "." + key);
if (sys != null && !sys.isEmpty()) return sys;
return properties.getProperty(prefix + "." + key);
}

Expand All @@ -51,7 +51,13 @@
public Configuration(@NonNull String prefix) {
this.prefix = prefix;
this.properties = new Properties();
URL resource = getClass().getResource("/app.properties");
// Try thread context classloader first (works well in app servers and Spring Boot)
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
URL resource = (tccl != null) ? tccl.getResource("app.properties") : null;
if (resource == null) {
// Fallback to this class' loader
resource = getClass().getResource("/app.properties");
}
if (resource != null) {
try (InputStream in = resource.openStream()) {
if (in != null) {
Expand Down Expand Up @@ -109,7 +115,7 @@

public boolean getBoolean(@NonNull String key) {
String value = resolve(key);
return value != null ? Boolean.parseBoolean(value) : false;

Check warning on line 118 in phoenixd-base/src/main/java/xyz/tcheeric/phoenixd/common/rest/util/Configuration.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Simplifiable conditional expression

`value != null ? Boolean.parseBoolean(value) : false` can be simplified to 'value != null \&\& Boolean.parseBoolean(value)'
}

public String get(@NonNull String key, @NonNull String defaultValue) {
Expand Down
Loading