Catch NullPointerException thrown by some server class loaders

Affects issues:
- Fixed #2074
This commit is contained in:
Risto Lahtela 2021-09-18 21:30:29 +03:00
parent b3674dfbda
commit 5dc3b39741
3 changed files with 19 additions and 3 deletions

View File

@ -38,7 +38,7 @@ public class ReflectiveLevelEntityPlayerLatencyFieldMethod implements PingMethod
private static void setMethods() throws IllegalAccessException, NoSuchFieldException, NoSuchMethodException, ClassNotFoundException {
MethodHandle[] methodHandles = PingMethodReflection.getMethods(
Reflection.getCraftBukkitClass("entity.CraftPlayer"),
Class.forName("net.minecraft.server.level.EntityPlayer"),
getEntityPlayer(),
"getHandle",
"latency"
);
@ -46,6 +46,14 @@ public class ReflectiveLevelEntityPlayerLatencyFieldMethod implements PingMethod
pingField = methodHandles[1];
}
private static Class<?> getEntityPlayer() throws ClassNotFoundException {
try {
return Class.forName("net.minecraft.server.level.EntityPlayer");
} catch (NullPointerException classLoaderError) {
throw new ClassNotFoundException("net.minecraft.server.level.EntityPlayer");
}
}
@Override
public boolean isAvailable() {
try {

View File

@ -38,7 +38,7 @@ public class ReflectiveUnmappedLatencyFieldMethod implements PingMethod {
private static void setMethods() throws IllegalAccessException, NoSuchFieldException, NoSuchMethodException, ClassNotFoundException {
MethodHandle[] methodHandles = PingMethodReflection.getMethods(
Reflection.getCraftBukkitClass("entity.CraftPlayer"),
Class.forName("net.minecraft.server.level.EntityPlayer"),
getEntityPlayer(),
"getHandle",
"e"
);
@ -46,6 +46,14 @@ public class ReflectiveUnmappedLatencyFieldMethod implements PingMethod {
pingField = methodHandles[1];
}
private static Class<?> getEntityPlayer() throws ClassNotFoundException {
try {
return Class.forName("net.minecraft.server.level.EntityPlayer");
} catch (NullPointerException classLoaderError) {
throw new ClassNotFoundException("net.minecraft.server.level.EntityPlayer");
}
}
@Override
public boolean isAvailable() {
try {

View File

@ -140,7 +140,7 @@ public final class Reflection {
private static Class<?> getCanonicalClass(String canonicalName) {
try {
return Class.forName(canonicalName);
} catch (ClassNotFoundException e) {
} catch (ClassNotFoundException | NullPointerException e) {
throw new IllegalArgumentException("Cannot find " + canonicalName, e);
}
}