Skip to content
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

Native hints for package private methods on custom @Repository class #29764

Closed
maciejwalkowiak opened this issue Jan 4, 2023 · 2 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: data Issues in data modules (jdbc, orm, oxm, tx) theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@maciejwalkowiak
Copy link
Contributor

When a custom class is annotated with @Repository annotation and Spring Data JPA is on the classpath (I believe it will happen with other spring data modules present too), package private methods from the annotated class (that get turned into proxy) are not visible in AdvisedSupport:

Sample class:

@Repository
public class CreditCardRepository {
    private final JdbcTemplate jdbcTemplate;

    public CreditCardRepository(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    Optional<CreditCard> findByCardNumber(String cardNumber) {
        ...
    }

Calling findByCardNumber results in:

java.lang.NullPointerException: null
	at org.springframework.aop.framework.AdvisedSupport$MethodCacheKey.<init>(AdvisedSupport.java:578) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:6.0.3]
	at org.springframework.aop.framework.AdvisedSupport.getInterceptorsAndDynamicInterceptionAdvice(AdvisedSupport.java:470) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:6.0.3]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) ~[na:na]
	at com.sivalabs.bookstore.payments.domain.CreditCardRepository$$SpringCGLIB$$0.findByCardNumber(<generated>) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:na]
	at com.sivalabs.bookstore.payments.domain.PaymentService.validate(PaymentService.java:21) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:na]
	at [email protected]/java.lang.reflect.Method.invoke(Method.java:568) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:na]
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[na:na]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:6.0.3]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:6.0.3]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:752) ~[na:na]
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[na:na]
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:6.0.3]
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:6.0.3]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:6.0.3]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:752) ~[na:na]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:703) ~[na:na]
	at com.sivalabs.bookstore.payments.domain.PaymentService$$SpringCGLIB$$0.validate(<generated>) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:na]
	at com.sivalabs.bookstore.payments.api.PaymentController.validate(PaymentController.java:23) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:na]
	at [email protected]/java.lang.reflect.Method.invoke(Method.java:568) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:na]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:207) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:6.0.3]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:152) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:6.0.3]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[com.sivalabs.bookstore.payments.PaymentServiceApplication:6.0.3]

Repo reproducing this issue made by @sivaprasadreddy https://github.com/siva-throwaway-work/spring-boot-native-issue

Current workaround:

  • change method visibility to public
  • instead of @Repository use @Component annotation on the custom repository class

I think it could be related to #29309 but after 2h of try & error with registering custom hints i give up

@mdeinum
Copy link
Contributor

mdeinum commented Jan 4, 2023

Did a little test, the same happens without spring-data-jpa and only the @Repository annotation. It appears as if the proxy created for the exception translation is the culprit.

@rstoyanchev rstoyanchev added the theme: aot An issue related to Ahead-of-time processing label Jan 25, 2023
@sbrannen sbrannen added in: data Issues in data modules (jdbc, orm, oxm, tx) in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 31, 2023
@sdeleuze sdeleuze self-assigned this Feb 9, 2023
@sdeleuze sdeleuze added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 9, 2023
@sdeleuze sdeleuze added this to the 6.0.6 milestone Feb 9, 2023
@sdeleuze
Copy link
Contributor

sdeleuze commented Feb 9, 2023

The exception looks similar to #29582.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: data Issues in data modules (jdbc, orm, oxm, tx) theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

6 participants