Aspect not invoked in native image
phejl opened this issue · 7 comments
While trying to prepare the reproducible case for #30525 I noticed there is a problem with aspect in native image. I'll provide a repro.
After more testing, seems to be a distinct issue.
The repro for that issue is interesting because it is still broken after fixing #28711 in 6.0.11-SNAPSHOT
. Based on my tests, it works on the JVM with AOT enabled, but fails on native even with the native configuration generated by the tracing agent which is surprising.
Comparing DEBUG/TRACE logs between JVM/native may allow to identify what causes the aspect to be ignored.
On native, fails with
@Pointcut("execution(* com.example.demo.data.DataRepository.*(..))")
Works with
@Pointcut("execution(* com.example.demo.data.DataRepositoryCustom.*(..))")
or
@Pointcut("execution(* com.example.demo.data.DataRepositoryImpl.*(..))")
.
With
public interface DataRepository extends MongoRepository<Data, ObjectId>, DataRepositoryCustom { ... }
public class DataRepositoryImpl implements DataRepositoryCustom { ... }
On the JVM, it works with all 3 pointcut expressions.
More reflection hints do not seem to fix this. Maybe there's a difference of behavior between the JVM and native?
On native, fails with
@Pointcut("execution(* com.example.demo.data.DataRepository.*(..))")
Out of curiosity, what happens if you try this (note the extra +
)?
@Pointcut("execution(* com.example.demo.data.DataRepository+.*(..))")
It probably does not make any difference, but I'm interested in knowing.
Maybe a difference of behavior between the JVM and native?
Could well be the case.
@sbrannen Same result
I managed to identify that the difference between JVM and native is the invocation of ClassUtils#getMostSpecificMethod
in AspectJExpressionPointcut#getTargetShadowMatch
which returns jdk.proxy2.$Proxy64.findByUidAndUpdateAccess(java.lang.String)
on the JVM and com.example.demo.data.DataRepository.findByUid(java.lang.String)
because a NoSuchMethodException
is thrown. The impact is that on the JVM, a pointcut on execution(* com.example.demo.data.DataRepository.*(..))
with a Spring Data repository interface ends up to a ShadowMatch#alwaysMatches
while on native ShadowMatch#neverMatches
.
Looks like related to oracle/graal#6079, so I will close this issue and add a commend on GraalVM side.