-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix cache compatibility with rest-client #13991
Fix cache compatibility with rest-client #13991
Conversation
List<Short> positions = new ArrayList<>(); | ||
for (short i = 0; i < parameters.length; i++) { | ||
if (parameters[i].isAnnotationPresent(CacheKey.class)) { | ||
positions.add(i); | ||
} | ||
} | ||
short[] positionsArray = new short[positions.size()]; | ||
for (int i = 0; i < positions.size(); i++) { | ||
positionsArray[i] = positions.get(i); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is not pretty, but there's a reason behind that: avoid lambdas in runtime code.
public class SpringCacheAnnotationsTransformer implements AnnotationsTransformer { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(SpringCacheAnnotationsTransformer.class); | ||
|
||
private static final DotName CACHE_RESULT_INTERCEPTOR_BINDING = DotName | ||
.createSimple(CacheResultInterceptorBinding.class.getName()); | ||
.createSimple(CacheResult.class.getName()); | ||
private static final DotName CACHE_INVALIDATE_INTERCEPTOR_BINDING = DotName | ||
.createSimple(CacheInvalidateInterceptorBinding.class.getName()); | ||
.createSimple(CacheInvalidate.class.getName()); | ||
private static final DotName CACHE_INVALIDATE_ALL_INTERCEPTOR_BINDING = DotName | ||
.createSimple(CacheInvalidateAllInterceptorBinding.class.getName()); | ||
.createSimple(CacheInvalidateAll.class.getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @geoand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
c176af2
to
de9cf89
Compare
assertUnknownCacheNameException(t, UNKNOWN_CACHE_1); | ||
assertUnknownCacheNameException(t, UNKNOWN_CACHE_2); | ||
assertUnknownCacheNameException(t, UNKNOWN_CACHE_3); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a preview of what would be logged if the exceptions were not "caught" by the test:
[...]
Caused by: javax.enterprise.inject.spi.DeploymentException: Found 10 deployment problems:
[1] @CacheResult is not allowed on a method returning void [class=io.quarkus.cache.test.deployment.DeploymentExceptionsTest$TestResource, method=showThrowVoidReturnTypeTargetException]
[2] Caching annotations are not allowed on a class [class=io.quarkus.cache.test.deployment.DeploymentExceptionsTest$TestResource, annotation=io.quarkus.cache.CacheInvalidate]
[3] Caching annotations are not allowed on a private method [class=io.quarkus.cache.test.deployment.DeploymentExceptionsTest$TestResource, method=shouldThrowPrivateMethodTargetException, annotation=io.quarkus.cache.CacheInvalidateAll]
[4] Caching annotations are not allowed on a private method [class=io.quarkus.cache.test.deployment.DeploymentExceptionsTest$TestResource, method=shouldAlsoThrowPrivateMethodTargetException, annotation=io.quarkus.cache.CacheInvalidate]
[5] Caching annotations are not allowed on a private method [class=io.quarkus.cache.test.deployment.DeploymentExceptionsTest$TestResource, method=shouldAlsoThrowPrivateMethodTargetException, annotation=io.quarkus.cache.CacheInvalidate]
[6] Caching annotations are not allowed on a class [class=io.quarkus.cache.test.deployment.DeploymentExceptionsTest$TestBean, annotation=io.quarkus.cache.CacheInvalidateAll]
[7] Caching annotations are not allowed on a class [class=io.quarkus.cache.test.deployment.DeploymentExceptionsTest$TestBean, annotation=io.quarkus.cache.CacheInvalidateAll]
[8] A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=io.quarkus.cache.test.deployment.DeploymentExceptionsTest$TestBean, cacheName=unknown-cache-1]
[9] A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=io.quarkus.cache.test.deployment.DeploymentExceptionsTest$TestBean, cacheName=unknown-cache-2]
[10] A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=io.quarkus.cache.test.deployment.DeploymentExceptionsTest$TestBean, cacheName=unknown-cache-3]
cbd22e3
to
abab11a
Compare
abab11a
to
17cf713
Compare
Conflicts solved. |
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CacheInterceptionContext<T extends Annotation> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if this class was immutable... WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, thanks for the suggestion. It took care of it in #14111.
I added one minor comment, otherwise looks good to me. |
17cf713
to
981e7b9
Compare
981e7b9
to
1da99b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually planning on applying @mkouba's suggestion about immutability and ask for another review tonight 😃 I'll do it in a separate PR. |
Ah I saw you pushed another commit, I thought you fixed it. Sorry :/ |
Fixes #8221.
This PR:
AnnotationsTransformer
because that's what prevented the extension from being compatible with MP REST Client. The former API annotations (@CacheResult
,@CacheInvalidate
and@CacheInvalidateAll
) are now the new interceptor bindings.Quarkus (Arc) currently supports repeated caching interceptor bindings (like
@CacheInvalidateAll
) but this PR does not allow repeated interceptor bindings on a method from a MP REST Client bean. The interceptors implementation from MP REST Client simply ignores repeated interceptor bindings. That's why there's a dedicated check at build time to forbid that combination.