Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't load resource bundles during annotation processing (fixes #1876) #1878

Merged
merged 3 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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;
rsenden marked this conversation as resolved.
Show resolved Hide resolved
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 ) {
rsenden marked this conversation as resolved.
Show resolved Hide resolved
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();
rsenden marked this conversation as resolved.
Show resolved Hide resolved
}
};
}
}
private static String extractName(ResourceBundle rb) {
try { // ResourceBundle.getBaseBundleName was introduced in Java 8
Expand Down