Skip to content

Commit

Permalink
Implement review comments for #1876
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden authored and remkop committed Dec 20, 2022
1 parent 291f072 commit fa994b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private static String stacktrace(Exception e) {
}

private boolean tryProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Model.Messages.loadBundles = false;
Model.Messages.setLoadBundles(false);
new AnnotationValidator(processingEnv).validateAnnotations(roundEnv);

Context context = new Context();
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -11599,7 +11599,7 @@ public <T> T getExtension(Class<T> cls) {
* @see CommandSpec#qualifiedName(String)
* @since 3.6 */
public static class Messages {
public static boolean loadBundles = true;
private static boolean loadBundles = true;
private final CommandSpec spec;
private final String bundleBaseName;
private final ResourceBundle rb;
Expand All @@ -11621,7 +11621,7 @@ public Messages(CommandSpec spec, String baseName, ResourceBundle rb) {
}
}
private static ResourceBundle createBundle(String baseName) {
if ( loadBundles ) {
if (loadBundles) {
return ResourceBundle.getBundle(baseName);
} else {
return new ResourceBundle() {
Expand All @@ -11631,8 +11631,7 @@ protected Object handleGetObject(String key) {
}
@Override
public Enumeration<String> getKeys() {
return new Vector<String>().elements();
}
return Collections.emptyEnumeration(); }
};
}
}
Expand Down Expand Up @@ -11662,6 +11661,18 @@ private static Set<String> keys(ResourceBundle rb) {
for (Enumeration<String> k = rb.getKeys(); k.hasMoreElements(); keys.add(k.nextElement()));
return keys;
}

/**
* During annotation processing, resource bundles may not be available on the
* classpath and thereby cause failures. This method allows for disabling
* loading of resource bundles during annotation processing, preventing such
* errors.
* @since 4.7.1
* @param loadBundles true if bundles should be loaded (default), false if bundles should not be loaded
*/
public static final void setLoadBundles(boolean loadBundles) {
Messages.loadBundles = loadBundles;
}

/** Returns a copy of the specified Messages object with the CommandSpec replaced by the specified one.
* @param spec the CommandSpec of the returned Messages
Expand Down

0 comments on commit fa994b2

Please sign in to comment.