Use multiple catch, try-with-resources, replace system.out and e.printStackTrace

This commit is contained in:
mezz committed 2017-06-27 22:57:10 -07:00
1 parent 10ca404e9e
commit 93025510ae
27 files changed
+62 -132

No files matched your search

@@ -108,7 +108,6 @@ import net.minecraftforge.fml.common.toposort.ModSortingException;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.registries.GameData;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.LWJGLUtil;
@@ -300,17 +299,12 @@ public class FMLClientHandler implements IFMLSidedHandler
Class<?> optifineConfig = Class.forName("Config", false, Loader.instance().getModClassLoader());
String optifineVersion = (String) optifineConfig.getField("VERSION").get(null);
Map<String,Object> dummyOptifineMeta = ImmutableMap.<String,Object>builder().put("name", "Optifine").put("version", optifineVersion).build();
InputStream optifineModInfoInputStream = getClass().getResourceAsStream("optifinemod.info");
try
try (InputStream optifineModInfoInputStream = getClass().getResourceAsStream("optifinemod.info"))
{
ModMetadata optifineMetadata = MetadataCollection.from(optifineModInfoInputStream, "optifine").getMetadataForId("optifine", dummyOptifineMeta);
optifineContainer = new DummyModContainer(optifineMetadata);
FMLLog.log.info("Forge Mod Loader has detected optifine {}, enabling compatibility features", optifineContainer.getVersion());
}
finally
{
IOUtils.closeQuietly(optifineModInfoInputStream);
}
}
catch (Exception e)
{
@@ -148,21 +148,15 @@ public class SplashProgress
if (!parent.exists())
parent.mkdirs();
FileReader r = null;
config = new Properties();
try
try (FileReader r = new FileReader(configFile))
{
r = new FileReader(configFile);
config.load(r);
}
catch(IOException e)
{
FMLLog.log.info("Could not load splash.properties, will create a default one");
}
finally
{
IOUtils.closeQuietly(r);
}
//Some system do not support this and have weird effects so we need to detect and disable by default.
//The user can always force enable it if they want to take the responsibility for bugs.
@@ -191,20 +185,14 @@ public class SplashProgress
File miscPackFile = new File(Minecraft.getMinecraft().mcDataDir, getString("resourcePackPath", "resources"));
FileWriter w = null;
try
try (FileWriter w = new FileWriter(configFile))
{
w = new FileWriter(configFile);
config.store(w, "Splash screen properties");
}
catch(IOException e)
{
FMLLog.log.error("Could not save the splash.properties file", e);
}
finally
{
IOUtils.closeQuietly(w);
}
miscPack = createResourcePack(miscPackFile);
@@ -240,7 +228,7 @@ public class SplashProgress
}
catch (LWJGLException e)
{
e.printStackTrace();
FMLLog.log.error("Error starting SplashProgress:", e);
disableSplash(e);
}
@@ -537,7 +525,7 @@ public class SplashProgress
}
catch (LWJGLException e)
{
e.printStackTrace();
FMLLog.log.error("Error setting GL context:", e);
throw new RuntimeException(e);
}
glClearColor((float)((backgroundColor >> 16) & 0xFF) / 0xFF, (float)((backgroundColor >> 8) & 0xFF) / 0xFF, (float)(backgroundColor & 0xFF) / 0xFF, 1);
@@ -564,7 +552,7 @@ public class SplashProgress
}
catch (LWJGLException e)
{
e.printStackTrace();
FMLLog.log.error("Error releasing GL context:", e);
throw new RuntimeException(e);
}
finally
@@ -629,7 +617,7 @@ public class SplashProgress
}
catch (LWJGLException e)
{
e.printStackTrace();
FMLLog.log.error("Error setting GL context:", e);
throw new RuntimeException(e);
}
}
@@ -650,7 +638,7 @@ public class SplashProgress
}
catch (LWJGLException e)
{
e.printStackTrace();
FMLLog.log.error("Error releasing GL context:", e);
throw new RuntimeException(e);
}
lock.unlock();
@@ -672,7 +660,7 @@ public class SplashProgress
}
catch (Exception e)
{
e.printStackTrace();
FMLLog.log.error("Error finishing SplashProgress:", e);
disableSplash(e);
}
}
@@ -719,10 +707,8 @@ public class SplashProgress
enabled = false;
config.setProperty("enabled", "false");
FileWriter w = null;
try
try (FileWriter w = new FileWriter(configFile))
{
w = new FileWriter(configFile);
config.store(w, "Splash screen properties");
}
catch(IOException e)
@@ -730,10 +716,6 @@ public class SplashProgress
FMLLog.log.error("Could not save the splash.properties file", e);
return false;
}
finally
{
IOUtils.closeQuietly(w);
}
return true;
}
@@ -837,7 +819,7 @@ public class SplashProgress
}
catch(IOException e)
{
e.printStackTrace();
FMLLog.log.error("Error reading texture from file: {}", location, e);
throw new RuntimeException(e);
}
finally
@@ -41,6 +41,7 @@ import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.PostConfigChangedEvent;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
@@ -344,7 +345,7 @@ public class GuiConfig extends GuiScreen
}
catch (Throwable e)
{
e.printStackTrace();
FMLLog.log.error("Error performing GuiConfig action:", e);
}
if (flag)
@@ -128,8 +128,7 @@ public class GuiConfigEntries extends GuiListExtended
}
catch (Throwable e)
{
FMLLog.log.fatal("There was a critical error instantiating the custom IConfigEntry for config element {}.", configElement.getName());
e.printStackTrace();
FMLLog.log.error("There was a critical error instantiating the custom IConfigEntry for config element {}.", configElement.getName(), e);
}
else if (configElement.isProperty())
{
@@ -33,6 +33,7 @@ import net.minecraft.util.text.TextFormatting;
import static net.minecraftforge.fml.client.config.GuiUtils.RESET_CHAR;
import static net.minecraftforge.fml.client.config.GuiUtils.UNDO_CHAR;
import net.minecraftforge.fml.common.FMLLog;
import org.lwjgl.input.Keyboard;
/**
@@ -128,7 +129,7 @@ public class GuiEditArray extends GuiScreen
}
catch (Throwable e)
{
e.printStackTrace();
FMLLog.log.error("Error performing GuiEditArray action:", e);
}
this.mc.displayGuiScreen(this.parentScreen);
}
@@ -30,6 +30,7 @@ import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.common.FMLLog;
import static net.minecraftforge.fml.client.config.GuiUtils.RESET_CHAR;
import static net.minecraftforge.fml.client.config.GuiUtils.UNDO_CHAR;
@@ -128,7 +129,7 @@ public class GuiSelectString extends GuiScreen
}
catch (Throwable e)
{
e.printStackTrace();
FMLLog.log.error("Error performing GuiSelectString action:", e);
}
this.mc.displayGuiScreen(this.parentScreen);
}