Force load more util classes to prevent further LinkageErrors.

This commit is contained in:
ulumulu1510 2017-02-17 13:10:41 +01:00
parent 6aee300cbe
commit db59c7b2a1
2 changed files with 48 additions and 2 deletions

View File

@ -104,9 +104,19 @@ import com.massivecraft.massivecore.store.ModificationPollerLocal;
import com.massivecraft.massivecore.store.ModificationPollerRemote; import com.massivecraft.massivecore.store.ModificationPollerRemote;
import com.massivecraft.massivecore.test.TestTypeEnchantment; import com.massivecraft.massivecore.test.TestTypeEnchantment;
import com.massivecraft.massivecore.util.BoardUtil; import com.massivecraft.massivecore.util.BoardUtil;
import com.massivecraft.massivecore.util.ContainerUtil;
import com.massivecraft.massivecore.util.EventUtil;
import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.IntervalUtil;
import com.massivecraft.massivecore.util.InventoryUtil;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.PeriodUtil;
import com.massivecraft.massivecore.util.PlayerUtil; import com.massivecraft.massivecore.util.PlayerUtil;
import com.massivecraft.massivecore.util.RecipeUtil;
import com.massivecraft.massivecore.util.ReflectionUtil;
import com.massivecraft.massivecore.util.SignUtil;
import com.massivecraft.massivecore.util.SmokeUtil;
import com.massivecraft.massivecore.util.TimeDiffUtil;
import com.massivecraft.massivecore.util.TimeUnit; import com.massivecraft.massivecore.util.TimeUnit;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import com.massivecraft.massivecore.xlib.gson.Gson; import com.massivecraft.massivecore.xlib.gson.Gson;
@ -229,8 +239,21 @@ public class MassiveCore extends MassivePlugin
@Override @Override
public void onLoadInner() public void onLoadInner()
{ {
// Attempting to fix a race condition within the class asynchronous class loader. // These util classes are not automatically loaded/resolved when MassiveCore is being loaded.
System.out.println(TimeUnit.DAY); // However they need to be loaded to ensure async safety.
// This fixes a race condition within the asynchronous class loader (LinkageError).
ReflectionUtil.forceLoadClasses(
ContainerUtil.class,
EventUtil.class,
IntervalUtil.class,
InventoryUtil.class,
PeriodUtil.class,
RecipeUtil.class,
SignUtil.class,
SmokeUtil.class,
TimeUnit.class,
TimeDiffUtil.class
);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -465,4 +465,27 @@ public class ReflectionUtil
private static int versionRelease = Integer.valueOf(getVersionRawPart(2).substring(1)); private static int versionRelease = Integer.valueOf(getVersionRawPart(2).substring(1));
public static int getVersionRelease() { return versionRelease; } public static int getVersionRelease() { return versionRelease; }
// -------------------------------------------- //
// FORCE LOAD CLASSES
// -------------------------------------------- //
public static void forceLoadClasses(Class<?>... classes)
{
for (Class<?> clazz : classes)
{
forceLoadClass(clazz);
}
}
// We chose this "weird" string in startsWith to avoid getting optimized away by the JIT compiler.
// It will never start with this string, but the JIT can't be sure of that.
public static void forceLoadClass(Class<?> clazz)
{
String className = clazz.getSimpleName();
if (className.startsWith("Spaces are not allowed in class names."))
{
System.out.println(className);
}
}
} }