Archiviert
13
0

Fix backwards compat with nullable classes

Fixes #499
Dieser Commit ist enthalten in:
Dan Mulloy 2018-08-03 22:07:25 -04:00
Ursprung d112e9b1dc
Commit 9df0dd48e4
3 geänderte Dateien mit 2171 neuen und 2172 gelöschten Zeilen

Datei anzeigen

@ -63,21 +63,16 @@ class CachedPackage {
* @return Class object.
* @throws RuntimeException If we are unable to find the given class.
*/
public Optional<Class<?>> getPackageClass(String className) {
public Optional<Class<?>> getPackageClass(final String className) {
Preconditions.checkNotNull(className, "className cannot be null!");
Optional<Class<?>> result = cache.get(className);
if (result == null) {
return cache.computeIfAbsent(className, x -> {
try {
Class<?> clazz = source.loadClass(combine(packageName, className));
result = Optional.ofNullable(clazz);
cache.put(className, result);
return Optional.ofNullable(source.loadClass(combine(packageName, className)));
} catch (ClassNotFoundException ex) {
cache.put(className, Optional.empty());
return Optional.empty();
}
}
return result;
});
}
/**

Datei anzeigen

@ -2021,7 +2021,7 @@ public class MinecraftReflection {
.orElseThrow(() -> new RuntimeException("Failed to find NMS class: " + className));
}
private static Class<?> getNullableNMS(String className) {
static Class<?> getNullableNMS(String className) {
if (minecraftPackage == null)
minecraftPackage = new CachedPackage(getMinecraftPackage(), getClassSource());
return minecraftPackage.getPackageClass(className).orElse(null);

Datei anzeigen

@ -1,8 +1,7 @@
package com.comphenix.protocol.utility;
import static com.comphenix.protocol.utility.TestUtils.assertItemsEqual;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@ -75,6 +74,11 @@ public class MinecraftReflectionTest {
MinecraftReflection.getBukkitEntity("Hello");
}
@Test
public void testNullable() {
assertNull(MinecraftReflection.getNullableNMS("ProtocolLib"));
}
@Test
public void testAttributeSnapshot() {
assertEquals(AttributeSnapshot.class, MinecraftReflection.getAttributeSnapshotClass());