diff --git a/src/main/java/org/cryptomator/ui/controls/CustomDialog.java b/src/main/java/org/cryptomator/ui/controls/CustomDialog.java index 2bb0d9757..a3d2d2753 100644 --- a/src/main/java/org/cryptomator/ui/controls/CustomDialog.java +++ b/src/main/java/org/cryptomator/ui/controls/CustomDialog.java @@ -11,6 +11,7 @@ import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Modality; import javafx.stage.Stage; +import java.util.IllegalFormatException; import java.util.ResourceBundle; import java.util.function.Consumer; @@ -19,7 +20,7 @@ public class CustomDialog { private static final Logger LOG = LoggerFactory.getLogger(CustomDialog.class); private final ResourceBundle resourceBundle; - private Stage dialogStage; + private final Stage dialogStage; CustomDialog(Builder builder) { this.resourceBundle = builder.resourceBundle; @@ -56,10 +57,14 @@ public class CustomDialog { } private String resolveText(String key, String[] args) { - String text = (key == null || key.isEmpty() || !resourceBundle.containsKey(key)) - ? String.format("N/A - Key '%s' not found", key) - : resourceBundle.getString(key); - return args != null && args.length > 0 ? String.format(text, (Object[]) args) : text; + if (key == null || key.isEmpty() || !resourceBundle.containsKey(key)) { + throw new IllegalArgumentException(String.format("Invalid key: '%s'. Key not found in ResourceBundle.", key)); } + String text = resourceBundle.getString(key); + try { + return args != null && args.length > 0 ? String.format(text, (Object[]) args) : text; + } catch (IllegalFormatException e) { + throw new IllegalArgumentException("Formatting error: Check if arguments match placeholders in the text.", e); + } } public static class Builder { @@ -77,7 +82,6 @@ public class CustomDialog { private Consumer okAction = Stage::close; private Consumer cancelAction = Stage::close; - @Inject public Builder(ResourceBundle resourceBundle) { this.resourceBundle = resourceBundle; } diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java index 92042bf50..98d152fa1 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java @@ -73,7 +73,6 @@ abstract class FxApplicationModule { } @Provides - @FxApplicationScoped static CustomDialog.Builder provideCustomDialog(ResourceBundle resourceBundle) { return new CustomDialog.Builder(resourceBundle); }