Based on 1.11.2 decompiled using MCP 9.35 rc1
The bug
Some file opening methods do not work when Minecraft is launched with a gameDir
containing dots.
Affected situations
List might be incomplete
Last updated for 1.11.2
opening screenshots (
net.minecraft.util.ScreenShotHelper.saveScreenshot(File, String, int, int, Framebuffer)
)opening crash reports
net.minecraft.client.Minecraft.displayCrashReport(CrashReport)
net.minecraft.server.MinecraftServer.run()
parts of realms (?) (
net.minecraft.realms.Realms.getGameDirectoryPath()
)
How to reproduce (old Java launcher)
Create a profile with the following game directory
./game-data
Start Minecraft with the profile
Take a screenshot and try to open it by clicking on the message in chat
→ The file is not opened
Additionally something like the following will appear in the Game Output
of your launcher:
20:02:05] [Client thread/ERROR]: Couldn't open link: Failed to open file:/LAUNCHER_PATH/./game-data/screenshots/2017-02-04_19.58.40.png. Error message: The system cannot find the file specified.
Code analysis
This happens because the affected methods call the method java.io.File.getAbsolutePath()
for the screenshot file path which does not resolve dots. Instead the method java.io.File.getCanonicalPath()
could be used.
Linked issues
is duplicated by 1
Comments 6
Yes, I am still able to reproduce this. Your comment sounds like you create folders with a dot in the name (like .minecraft
), which work perfectly fine. The problem occurs when you use dots as relative path directories.
When does the method call
java.io.File.getAbsolutePath()
actually return an absolute path which isn't a canonical path? Every canonical path is also an absolute path, but not the other way around.
Your second sentence explains that, did you possibly switch the words by accident? Anyways, consider for example the following example with home
as current directory:
System.out.println(new java.io.File("./test").getAbsolutePath()); // "home/./test"
try {
System.out.println(new java.io.File("./test").getCanonicalPath()); // "home/test"
}
catch (java.io.IOException ioException) {
ioException.printStackTrace();
}
@unknown As I've already mentioned in my comment, I've also tried to reproduce it with dots in relative game directory paths, including "./game-data", but I still can't get it to work like that. The only occasion in which it didn't work for me was when I tried to reproduce it in MCP. Am I doing something wrong? Here's a video of me trying to reproduce the bug with "./test". (I also can't get it to work in 1.12.)
Also thanks for explaining the exact difference between an absolute and a canonical path again, I think I got it now. However, I still can't get my head
around why I can only get this to work inside of MCP.
Maybe it is caused by the new launcher. Can you please check which game directory is set when you try to edit the created profile again. I used the old Java launcher and was able to reproduce this in 1.12.
I just checked the game directory path of the profile I created and it says C:\Users\bemoty\AppData\Roaming\.minecraft\test
. Are you able to reproduce it in the new launcher? If not, this might actually be caused by the old launcher or, respectively, by starting the game manually without converting the absolute game directory path to a canonical one.
If this is the case, most users won't even notice this bug since they are using the normal Minecraft launcher which converts the path automatically. For occasions in which the game is started without converting the absolute game directory path to a canonical one before startup (ex. MCP) this should be fixed by replacing the getAbsolutePath()
method with getCanonicalPath()
though.
Are you sure the dot in the gameDir is causing these game functions to break? I just tried to reproduce the bug in game directories with dots at various different places in their names (also ./game-data) and I've not been able to reproduce it a single time.
When does the method call
java.io.File.getAbsolutePath()
actually return an absolute path which isn't a canonical path? Every canonical path is also an absolute path, but not the other way around.