浏览代码

changed resolveText() to throw Exceptions
removed fxApplication scope

Jan-Peter Klein 8 月之前
父节点
当前提交
c471289fb5

+ 10 - 6
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<Stage> okAction = Stage::close;
 		private Consumer<Stage> cancelAction = Stage::close;
 
-		@Inject
 		public Builder(ResourceBundle resourceBundle) {
 			this.resourceBundle = resourceBundle;
 		}

+ 0 - 1
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);
 	}