From 33af98b6d601057ddc54493ee9301285f61c57f2 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 30 Nov 2023 17:51:46 +0100 Subject: [PATCH] Document need for -parameters flag in cache key generation exception messages Closes gh-31675 --- .../cache/interceptor/CacheAspectSupport.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java index eb742122d0..4616abcc08 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java @@ -670,8 +670,10 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker private Object generateKey(CacheOperationContext context, @Nullable Object result) { Object key = context.generateKey(result); if (key == null) { - throw new IllegalArgumentException("Null key returned for cache operation (maybe you are " + - "using named params on classes without debug info?) " + context.metadata.operation); + throw new IllegalArgumentException(""" + Null key returned for cache operation [%s]. If you are using named parameters, \ + ensure that the compiler uses the '-parameters' flag.""" + .formatted(context.metadata.operation)); } if (logger.isTraceEnabled()) { logger.trace("Computed cache key '" + key + "' for operation " + context.metadata.operation);