While trying to prepare the reproducible case for https://github.com/spring-projects/spring-framework/issues/30525 I noticed there is a problem with aspect in native image. I'll provide a repro.
Comment From: phejl
https://github.com/phejl/spring-boot-30529
Comment From: sdeleuze
Looks like a duplicate of #28711.
Comment From: sdeleuze
After more testing, seems to be a distinct issue.
Comment From: sdeleuze
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.
Comment From: sdeleuze
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?
Comment From: sbrannen
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.
Comment From: sdeleuze
@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 https://github.com/oracle/graal/issues/6079, so I will close this issue and add a commend on GraalVM side.