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

Datei anzeigen

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