-
Notifications
You must be signed in to change notification settings - Fork 818
同时检查 JarPath 是否包含 !
#5272
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
base: main
Are you sure you want to change the base?
同时检查 JarPath 是否包含 !
#5272
Conversation
|
|
||
| private static void checkDirectoryPath() { | ||
| String currentDir = System.getProperty("user.dir", ""); | ||
| String thisJarPath = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请检查 CodeSource 是否为 null。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds an additional startup validation to prevent launching HMCL from locations that contain !, extending the existing working-directory check to also cover the HMCL jar path to avoid downstream runtime errors.
Changes:
- Read the HMCL jar path from
Main.classCodeSource and check whether it contains!. - Show an error dialog and exit when the jar path contains
!(in addition to the existing working-directory check).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| private static void checkDirectoryPath() { | ||
| String currentDir = System.getProperty("user.dir", ""); | ||
| String thisJarPath = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(); |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main.class.getProtectionDomain().getCodeSource().getLocation() can be null in some classloading scenarios; calling .getPath() unconditionally introduces a new potential NPE during startup. Consider retrieving the CodeSource/Location with null + SecurityException handling (and only computing the jar path after the working-dir check) so checkDirectoryPath() never crashes before showing an error dialog.
| SwingUtils.initLookAndFeel(); | ||
| System.err.println("The jar path contains an exclamation mark: " + thisJarPath); | ||
| // No Chinese translation because both Swing and JavaFX cannot render Chinese character properly when exclamation mark exists in the path. | ||
| SwingUtils.showErrorDialog("Exclamation mark(!) is not allowed in the path where HMCL is in.\n" + "The path is " + currentDir); |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the jar-path ! branch, the dialog prints currentDir instead of thisJarPath, which will mislead users about which path is invalid. Use the jar path variable (and consider aligning the wording with the stderr message).
| SwingUtils.showErrorDialog("Exclamation mark(!) is not allowed in the path where HMCL is in.\n" + "The path is " + currentDir); | |
| SwingUtils.showErrorDialog("Exclamation mark(!) is not allowed in the jar path.\n" + "The path is " + thisJarPath); |
| private static void checkDirectoryPath() { | ||
| String currentDir = System.getProperty("user.dir", ""); | ||
| String thisJarPath = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(); |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new jar-path validation is startup-critical but currently hard to test because checkDirectoryPath() is private and exits the JVM/UI-calls directly. Consider extracting the core validation into a package-private pure method (e.g., taking currentDir and jarPath and returning an optional error) and add unit tests for both working-dir and jar-path cases.
突然发现不光运行路径,Jar路径也不能包括
!,否则也会报错之前运行路径的检查也需要保留,否则 JavaFX 可能会无法加载 css 样式