Clean up uses of deprecated library functions (#4130)

Avoid catching and rethrowing runtime exceptions
Append error messages to exceptions instead of the log
This commit is contained in:
Ben Staddon authored and mezz committed 2017-07-12 21:50:28 -07:00
1 parent ead0e81025
commit 0fde64ac38
44 files changed
+118 -232

No files matched your search

@@ -25,6 +25,7 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.UUID;
@@ -33,7 +34,6 @@ import javax.annotation.Nullable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.io.Files;
@@ -56,7 +56,7 @@ public final class UsernameCache {
private static Map<UUID, String> map = Maps.newHashMap();
private static final Charset charset = Charsets.UTF_8;
private static final Charset charset = StandardCharsets.UTF_8;
private static final File saveFile = new File( /* The minecraft dir */(File) FMLInjectionData.data()[6], "usernamecache.json");
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
@@ -130,9 +130,9 @@ public class Capability<T>
}
catch (Exception e)
{
Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
return null;
}
/**
@@ -26,12 +26,10 @@ import java.util.IdentityHashMap;
import java.util.List;
import java.util.concurrent.Callable;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.Type;
import java.util.function.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -39,8 +37,6 @@ import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.discovery.ASMDataTable;
import javax.annotation.Nullable;
public enum CapabilityManager
{
INSTANCE;
@@ -62,7 +58,7 @@ public enum CapabilityManager
try {
return implementation.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw Throwables.propagate(e);
throw new RuntimeException(e);
}
});
}
@@ -26,11 +26,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.apache.logging.log4j.Level;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
@@ -307,10 +304,10 @@ public class ConfigManager
{
newInstance = f.get(instance);
}
catch (Exception e)
catch (IllegalAccessException e)
{
//This should never happen. Previous checks should eliminate this.
Throwables.propagate(e);
throw new RuntimeException(e);
}
String sub = (category.isEmpty() ? "" : category + ".") + getName(f).toLowerCase(Locale.ENGLISH);
@@ -76,7 +76,7 @@ public class Configuration
private static final String CONFIG_VERSION_MARKER = "~CONFIG_VERSION";
private static final Pattern CONFIG_START = Pattern.compile("START: \"([^\\\"]+)\"");
private static final Pattern CONFIG_END = Pattern.compile("END: \"([^\\\"]+)\"");
public static final CharMatcher allowedProperties = CharMatcher.JAVA_LETTER_OR_DIGIT.or(CharMatcher.anyOf(ALLOWED_CHARS));
public static final CharMatcher allowedProperties = CharMatcher.javaLetterOrDigit().or(CharMatcher.anyOf(ALLOWED_CHARS));
private static Configuration PARENT = null;
File file;
@@ -11,7 +11,6 @@ import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.Set;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import net.minecraftforge.common.config.Config.RangeDouble;
@@ -84,9 +83,9 @@ public abstract class FieldWrapper implements IFieldWrapper
throw new IllegalArgumentException(String.format("The map '%s' of class '%s' must have the key type String!", field.getName(),
field.getDeclaringClass().getCanonicalName()), cce);
}
catch (Exception e)
catch (IllegalAccessException e)
{
Throwables.propagate(e);
throw new RuntimeException(e);
}
ParameterizedType type = (ParameterizedType) field.getGenericType();
@@ -200,11 +199,10 @@ public abstract class FieldWrapper implements IFieldWrapper
Enum enu = (Enum) field.get(instance);
return enu.name();
}
catch (Exception e)
catch (IllegalAccessException e)
{
Throwables.propagate(e);
throw new RuntimeException(e);
}
return null;
}
@Override
@@ -218,9 +216,9 @@ public abstract class FieldWrapper implements IFieldWrapper
{
field.set(instance, enu);
}
catch (Exception e)
catch (IllegalAccessException e)
{
Throwables.propagate(e);
throw new RuntimeException(e);
}
}
@@ -271,11 +269,10 @@ public abstract class FieldWrapper implements IFieldWrapper
{
return field.get(instance);
}
catch (Exception e)
catch (IllegalAccessException e)
{
Throwables.propagate(e);
throw new RuntimeException(e);
}
return null;
}
@Override
@@ -287,9 +284,9 @@ public abstract class FieldWrapper implements IFieldWrapper
{
field.set(instance, value);
}
catch (Exception e)
catch (IllegalAccessException e)
{
Throwables.propagate(e);
throw new RuntimeException(e);
}
}
@@ -19,15 +19,13 @@
package net.minecraftforge.common.network;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;
import org.apache.logging.log4j.Level;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import com.google.common.base.Charsets;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Sets;
@@ -54,7 +52,7 @@ public abstract class ForgeMessage {
void toBytes(ByteBuf bytes)
{
bytes.writeInt(this.dimensionId);
byte[] data = this.providerId.getBytes(Charsets.UTF_8);
byte[] data = this.providerId.getBytes(StandardCharsets.UTF_8);
bytes.writeShort(data.length);
bytes.writeBytes(data);
}
@@ -65,7 +63,7 @@ public abstract class ForgeMessage {
dimensionId = bytes.readInt();
byte[] data = new byte[bytes.readShort()];
bytes.readBytes(data);
providerId = new String(data, Charsets.UTF_8);
providerId = new String(data, StandardCharsets.UTF_8);
}
}