Thatsmusic99 / HeadsPlus-Archived

A Minecraft heads plugin with many different features that make it unique in multiple ways.
https://www.spigotmc.org/resources/headsplus-1-8-x-1-12-x.40265/
MIT License
11 stars 6 forks source link

JSONFile#create assumes data folder exists #7

Closed jamesremuscat closed 6 years ago

jamesremuscat commented 6 years ago

Short summary of issue

When running HeadsPlus on a server for the first time, java.io.IOException: No such file or directory is thrown from Favourites#create called from HeadsPlus.java:312.

Server version

git-Bukkit-1ef1ffd (MC: 1.13)

HeadsPlus version

4.8.9

Detailed description (how you found it, what you were doing at the time)

Installing plugin to a fresh server with no other plugins installed.

Expected behaviour

HeadsPlus to check data folder exists (and/or wait for it to be created and/or create it) before attempting to write to it

Actual behaviour

HP tries to write to data folder before it exists.

java.io.IOException: No such file or directory
  at java.io.UnixFileSystem.createFileExclusively(Native Method)
  at java.io.File.createNewFile(File.java:1012)
  at io.github.thatsmusic99.headsplus.storage.JSONFile.create(JSONFile.java:21)
  at io.github.thatsmusic99.headsplus.HeadsPlus.setupJSON(HeadsPlus.java:312)
  at io.github.thatsmusic99.headsplus.HeadsPlus.onEnable(HeadsPlus.java:102)
  at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264)
  at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:331)
  at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:402)
  at org.bukkit.craftbukkit.v1_13_R1.CraftServer.enablePlugin(CraftServer.java:412)
  at org.bukkit.craftbukkit.v1_13_R1.CraftServer.enablePlugins(CraftServer.java:338)
  at net.minecraft.server.v1_13_R1.MinecraftServer.m(MinecraftServer.java:553)
  at net.minecraft.server.v1_13_R1.MinecraftServer.g_(MinecraftServer.java:515)
  at net.minecraft.server.v1_13_R1.MinecraftServer.a(MinecraftServer.java:414)
  at net.minecraft.server.v1_13_R1.DedicatedServer.init(DedicatedServer.java:264)
  at net.minecraft.server.v1_13_R1.MinecraftServer.run(MinecraftServer.java:664)
  at java.lang.Thread.run(Thread.java:745)

Steps to reproduce

Load plugin JAR into fresh server's plugins folder; start server.

Any last notes?

Bukkit's docs say that getDataFolder():

Returns the folder that the plugin data's files are located in. The folder may not yet exist.

Might just be a race condition and in this instance this code just happened to execute before the data folder was created; restarting the server once the data folder had been created then works fine and the favourites.json file is created as it should be.

Thatsmusic99 commented 6 years ago

Odd, I thought it would do everything automatically... does the HeadsPlus folder exist, and if it does, is there a folder in there called "storage"? I'll test this now - then again, that sucks with Java, not mentioning what exists and what doesn't...

Thatsmusic99 commented 6 years ago

Reproduced using 1.13 Spigot. Will make a quick fix now.

Thatsmusic99 commented 6 years ago

The issue I found here was not the fact that the plugin couldn't find its own data folder - that was created fine. The storage folder where favourites.json is created, however, was not, hence why the plugin retaliated by breaking.

If the data folder wasn't there, however, you would end up with a second error as the plugin tries to create a debug report regarding the error that was thrown. Mostly because not everyone knows how to handle bug reporting, and I've already had one close shave on the Spigot reviews. So far, I've been lucky.

In the meantime. Just fixed this and will upload the new jar to Spigot (version 4.8.9.1). Thank you for your cooperation on reporting this.