2626import org .springframework .core .env .Environment ;
2727import org .springframework .core .type .AnnotatedTypeMetadata ;
2828import org .springframework .core .type .AnnotationMetadata ;
29- import org .springframework .core . type . ClassMetadata ;
29+ import org .springframework .util . Assert ;
3030
3131/**
3232 * General cache condition used with all cache configuration classes.
@@ -39,18 +39,20 @@ class CacheCondition extends SpringBootCondition {
3939
4040 @ Override
4141 public ConditionOutcome getMatchOutcome (ConditionContext context , AnnotatedTypeMetadata metadata ) {
42- String sourceClass = "" ;
43- if (metadata instanceof ClassMetadata classMetadata ) {
44- sourceClass = classMetadata .getClassName ();
45- }
42+ Assert .isInstanceOf (AnnotationMetadata .class , metadata );
43+ return extracted (context , (AnnotationMetadata ) metadata );
44+ }
45+
46+ private ConditionOutcome extracted (ConditionContext context , AnnotationMetadata metadata ) {
47+ String sourceClass = metadata .getClassName ();
4648 ConditionMessage .Builder message = ConditionMessage .forCondition ("Cache" , sourceClass );
4749 Environment environment = context .getEnvironment ();
4850 try {
4951 BindResult <CacheType > specified = Binder .get (environment ).bind ("spring.cache.type" , CacheType .class );
5052 if (!specified .isBound ()) {
5153 return ConditionOutcome .match (message .because ("automatic cache type" ));
5254 }
53- CacheType required = CacheConfigurations .getType ((( AnnotationMetadata ) metadata ) .getClassName ());
55+ CacheType required = CacheConfigurations .getType (metadata .getClassName ());
5456 if (specified .get () == required ) {
5557 return ConditionOutcome .match (message .because (specified .get () + " cache type" ));
5658 }
0 commit comments