From 00ead74204229d20e4d214c4b8baf979cb4cb249 Mon Sep 17 00:00:00 2001 From: redkale Date: Wed, 20 Dec 2023 20:29:16 +0800 Subject: [PATCH] =?UTF-8?q?CacheAsmMethodBoost=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/redkale/cache/spi/CacheAsmMethodBoost.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/redkale/cache/spi/CacheAsmMethodBoost.java b/src/main/java/org/redkale/cache/spi/CacheAsmMethodBoost.java index 6c27b0577..8cf6af7d4 100644 --- a/src/main/java/org/redkale/cache/spi/CacheAsmMethodBoost.java +++ b/src/main/java/org/redkale/cache/spi/CacheAsmMethodBoost.java @@ -7,6 +7,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.List; +import java.util.concurrent.CompletableFuture; import org.redkale.asm.AnnotationVisitor; import org.redkale.asm.AsmMethodBean; import org.redkale.asm.AsmMethodBoost; @@ -19,6 +20,7 @@ import static org.redkale.asm.Opcodes.*; import org.redkale.asm.Type; import org.redkale.cache.Cached; import org.redkale.util.RedkaleException; +import org.redkale.util.TypeToken; /** * @@ -26,6 +28,9 @@ import org.redkale.util.RedkaleException; */ public class CacheAsmMethodBoost extends AsmMethodBoost { + private static final java.lang.reflect.Type FUTURE_VOID = new TypeToken>() { + }.getType(); + private static final List> FILTER_ANN = List.of(Cached.class, DynForCache.class); public CacheAsmMethodBoost(Class serviceType) { @@ -47,11 +52,14 @@ public class CacheAsmMethodBoost extends AsmMethodBoost { return newMethodName; } if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) { - throw new RedkaleException("@" + Cached.class.getSimpleName() + " can not on final or static method, but on " + method); + throw new RedkaleException("@" + Cached.class.getSimpleName() + " cannot on final or static method, but on " + method); } if (!Modifier.isProtected(method.getModifiers()) && !Modifier.isPublic(method.getModifiers())) { throw new RedkaleException("@" + Cached.class.getSimpleName() + " must on protected or public method, but on " + method); } + if (method.getReturnType() == void.class || FUTURE_VOID.equals(method.getGenericReturnType())) { + throw new RedkaleException("@" + Cached.class.getSimpleName() + " cannot on void method, but on " + method); + } final String rsMethodName = method.getName() + "_afterCache"; final String dynFieldName = fieldPrefix + "_" + method.getName() + "CacheAction" + fieldIndex.incrementAndGet();