Skip to content

Commit

Permalink
Don't load resource bundles during annotation processing (fixes #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 1f26852 commit 291f072
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import picocli.CommandLine.Command;
import picocli.CommandLine.IFactory;
import picocli.CommandLine.Mixin;
import picocli.CommandLine.Model;
import picocli.CommandLine.Model.ArgGroupSpec;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Model.IAnnotatedElement;
Expand Down Expand Up @@ -179,7 +180,7 @@ private static String stacktrace(Exception e) {
}

private boolean tryProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

Model.Messages.loadBundles = false;
new AnnotationValidator(processingEnv).validateAnnotations(roundEnv);

Context context = new Context();
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -11599,6 +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 final CommandSpec spec;
private final String bundleBaseName;
private final ResourceBundle rb;
Expand All @@ -11620,7 +11621,20 @@ public Messages(CommandSpec spec, String baseName, ResourceBundle rb) {
}
}
private static ResourceBundle createBundle(String baseName) {
return ResourceBundle.getBundle(baseName);
if ( loadBundles ) {
return ResourceBundle.getBundle(baseName);
} else {
return new ResourceBundle() {
@Override
protected Object handleGetObject(String key) {
return null;
}
@Override
public Enumeration<String> getKeys() {
return new Vector<String>().elements();
}
};
}
}
private static String extractName(ResourceBundle rb) {
try { // ResourceBundle.getBaseBundleName was introduced in Java 8
Expand Down

0 comments on commit 291f072

Please sign in to comment.