diff --git a/projects/core/src/main/java/dan200/computercraft/core/asm/MethodSupplierImpl.java b/projects/core/src/main/java/dan200/computercraft/core/asm/MethodSupplierImpl.java index 16141485d..f115f2647 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/asm/MethodSupplierImpl.java +++ b/projects/core/src/main/java/dan200/computercraft/core/asm/MethodSupplierImpl.java @@ -4,9 +4,6 @@ package dan200.computercraft.core.asm; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.peripheral.PeripheralType; @@ -23,7 +20,6 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.concurrent.ExecutionException; import java.util.function.Function; import static dan200.computercraft.core.asm.Generator.catching; @@ -36,9 +32,14 @@ final class MethodSupplierImpl implements MethodSupplier { private final IntCache dynamic; private final Function dynamicMethods; - private final LoadingCache, List>> classCache = CacheBuilder - .newBuilder() - .build(CacheLoader.from(catching(this::getMethodsImpl, List.of()))); + private final ClassValue>> classCache = new ClassValue<>() { + private final Function, List>> getter = catching(MethodSupplierImpl.this::getMethodsImpl, List.of()); + + @Override + protected List> computeValue(Class type) { + return getter.apply(type); + } + }; MethodSupplierImpl( List genericMethods, @@ -93,12 +94,7 @@ final class MethodSupplierImpl implements MethodSupplier { @VisibleForTesting List> getMethods(Class klass) { - try { - return classCache.get(klass); - } catch (ExecutionException e) { - LOG.error("Error getting methods for {}.", klass.getName(), e.getCause()); - return List.of(); - } + return classCache.get(klass); } private List> getMethodsImpl(Class klass) { @@ -148,5 +144,4 @@ final class MethodSupplierImpl implements MethodSupplier { } } } - }