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