Skip to content

Commit

Permalink
[#2291] Bugfix: NullPointerException when using PropertiesDefaultProv…
Browse files Browse the repository at this point in the history
…ider

Closes #2291
  • Loading branch information
remkop committed Aug 31, 2024
1 parent 2e7ce24 commit a856a14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Artifacts in this release are signed by Remko Popma (6601 E5C0 8DCC BB96).

* [#2335] Bugfix: Module info missing in all jars except the main picocli jar file. Thanks to [Oliver B. Fischer](https://github.com/obfischer) for raising this.
* [#2331] Bugfix: AutoComplete with jline3 was showing hidden commands. Thanks to [clebertsuconic](https://github.com/clebertsuconic) for raising this.
* [#2291] Bugfix: NullPointerException when using PropertiesDefaultProvider. Thanks to [JessHolle](https://github.com/JessHolle) for raising this.
* [#2290] DOC: User guide, CDI 2.0 (JSR 365) section: fix example and add warning about dynamic proxies. Thanks to [Mert Zeybekler](https://github.com/Mert-Z) for the pull request.


Expand Down
21 changes: 13 additions & 8 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -19006,15 +19006,20 @@ private static Properties loadProperties(CommandSpec commandSpec) {
if (userObject == null) {
userObject = commandSpec.commandLine;
}
URL resource = userObject.getClass().getClassLoader().getResource(propertiesFileName);
if (resource != null) {
try {
return createProperties(resource.openStream(), resource.toString(), commandSpec);
} catch (Exception ex) {
tracer().warn("PropertiesDefaultProvider could not read defaults from %s: %s", resource, ex);
}
ClassLoader cl = userObject.getClass().getClassLoader();
if (cl == null) {
tracer().debug("No class loader for %s; PropertiesDefaultProvider defaults configuration file %s cannot be found on classpath or user home or specified location", userObject.getClass().getName(), propertiesFileName);
} else {
tracer().debug("PropertiesDefaultProvider defaults configuration file %s does not exist on classpath or user home or specified location", propertiesFileName);
URL resource = cl.getResource(propertiesFileName);
if (resource != null) {
try {
return createProperties(resource.openStream(), resource.toString(), commandSpec);
} catch (Exception ex) {
tracer().warn("PropertiesDefaultProvider could not read defaults from %s: %s", resource, ex);
}
} else {
tracer().debug("PropertiesDefaultProvider defaults configuration file %s does not exist on classpath or user home or specified location", propertiesFileName);
}
}
}
}
Expand Down

0 comments on commit a856a14

Please sign in to comment.