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

AOT processing for bean validation causes StackOverflowError #33936

Closed
mingchiuli opened this issue Nov 22, 2024 · 10 comments
Closed

AOT processing for bean validation causes StackOverflowError #33936

mingchiuli opened this issue Nov 22, 2024 · 10 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another theme: aot An issue related to Ahead-of-time processing type: regression A bug that is also a regression

Comments

@mingchiuli
Copy link

Problem generate in spring boot Version: 3.4.0. It's normal in spring boot 3.3.6.

error log:

> Task :micro-blog:processAot

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.0)

2024-11-22T08:58:56.607+08:00  INFO 55656 --- [           main] w.chiu.micro.blog.MicroBlogApplication   : Starting MicroBlogApplication using Java 23.0.1 with PID 55656 (/Users/mingchiuli/Desktop/megalith-micro/micro-blog/build/classes/java/main started by mingchiuli in /Users/mingchiuli/Desktop/megalith-micro/micro-blog)
2024-11-22T08:58:56.609+08:00  INFO 55656 --- [           main] w.chiu.micro.blog.MicroBlogApplication   : The following 1 profile is active: "dev"
2024-11-22T08:58:57.159+08:00  INFO 55656 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2024-11-22T08:58:57.159+08:00  INFO 55656 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-11-22T08:58:57.240+08:00  INFO 55656 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 76 ms. Found 2 JPA repository interfaces.
2024-11-22T08:58:57.250+08:00  INFO 55656 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2024-11-22T08:58:57.251+08:00  INFO 55656 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2024-11-22T08:58:57.261+08:00  INFO 55656 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface wiki.chiu.micro.blog.repository.BlogRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository
2024-11-22T08:58:57.261+08:00  INFO 55656 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface wiki.chiu.micro.blog.repository.BlogSensitiveContentRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository
2024-11-22T08:58:57.261+08:00  INFO 55656 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 5 ms. Found 0 Redis repository interfaces.
Exception in thread "main" java.lang.StackOverflowError
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.checkReceiver(DirectMethodHandleAccessor.java:196)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:99)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:281)
	at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:265)
	at org.springframework.core.SerializableTypeWrapper$MethodInvokeTypeProvider.getType(SerializableTypeWrapper.java:357)
	at org.springframework.core.SerializableTypeWrapper.forTypeProvider(SerializableTypeWrapper.java:106)
	at org.springframework.core.SerializableTypeWrapper$TypeProxyInvocationHandler.invoke(SerializableTypeWrapper.java:215)
	at org.springframework.core.$Proxy6.getActualTypeArguments(Unknown Source)
	at org.springframework.core.ResolvableType.getGenerics(ResolvableType.java:809)
	at org.springframework.core.ResolvableType.getGeneric(ResolvableType.java:762)
	at org.springframework.validation.beanvalidation.BeanValidationBeanRegistrationAotProcessor$BeanValidationDelegate.lambda$processAheadOfTime$0(BeanValidationBeanRegistrationAotProcessor.java:162)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:728)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:707)
	at org.springframework.validation.beanvalidation.BeanValidationBeanRegistrationAotProcessor$BeanValidationDelegate.processAheadOfTime(BeanValidationBeanRegistrationAotProcessor.java:150)
	at org.springframework.validation.beanvalidation.BeanValidationBeanRegistrationAotProcessor$BeanValidationDelegate.lambda$processAheadOfTime$0(BeanValidationBeanRegistrationAotProcessor.java:170)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:728)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:707)
	at org.springframework.validation.beanvalidation.BeanValidationBeanRegistrationAotProcessor$BeanValidationDelegate.processAheadOfTime(BeanValidationBeanRegistrationAotProcessor.java:150)
	at org.springframework.validation.beanvalidation.BeanValidationBeanRegistrationAotProcessor$BeanValidationDelegate.lambda$processAheadOfTime$0(BeanValidationBeanRegistrationAotProcessor.java:170)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:728)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:707)
	at org.springframework.validation.beanvalidation.BeanValidationBeanRegistrationAotProcessor$BeanValidationDelegate.processAheadOfTime(BeanValidationBeanRegistrationAotProcessor.java:150)
	at org.springframework.validation.beanvalidation.BeanValidationBeanRegistrationAotProcessor$BeanValidationDelegate.lambda$processAheadOfTime$0(BeanValidationBeanRegistrationAotProcessor.java:170)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:728)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:707)
	at org.springframework.validation.beanvalidation.BeanValidationBeanRegistrationAotProcessor$BeanValidationDelegate.processAheadOfTime(BeanValidationBeanRegistrationAotProcessor.java:150)
	at org.springframework.validation.beanvalidat
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 22, 2024
@bclozel bclozel transferred this issue from spring-projects/spring-boot Nov 22, 2024
@bclozel
Copy link
Member

bclozel commented Nov 22, 2024

Can you provide a minimal sample application that reproduces the problem please?

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Nov 22, 2024
@waileong
Copy link

I'm encountering the same issue, which seems to be caused by 33842

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 22, 2024
@bclozel
Copy link
Member

bclozel commented Nov 22, 2024

@waileong can you provide a minimal sample application? This would help us speed us the resolution process.

@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Nov 22, 2024
@itineric
Copy link

itineric commented Nov 22, 2024

Having the same error.

The usecase to reproduce is not ideal, but cannot find a better one for now.

I have an empty spring Application

@SpringBootApplication
public class MyApplication
{
  public static void main(final String[] args)
  {
    SpringApplication.run(MyApplication.class, args);
  }
}

But these dependencies in my pom.xml

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-amqp</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

I get the StackOverflowError during AOT.
If I remove one or the other dependency, it works.
I'm stuck here since it seems to have nothing to do with my apps.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 22, 2024
@bsgrd
Copy link
Contributor

bsgrd commented Nov 22, 2024

Having the same error.

The usecase to reproduce is not ideal, but cannot find a better one for now.

I have an empty spring Application

@SpringBootApplication
public class MyApplication
{
  public static void main(final String[] args)
  {
    SpringApplication.run(MyApplication.class, args);
  }
}

But these dependencies in my pom.xml

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-amqp</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

I get the StackOverflowError during AOT. If I remove one or the other dependency, it works. I'm stuck here since it seems to have nothing to do with my apps.

I can confirm that removing "spring-boot-starter-validation" and "spring-cloud-stream-binder-kafka" "fixed" the issue for me.

@bsgrd
Copy link
Contributor

bsgrd commented Nov 22, 2024

For me the issue was the combination of "spring-boot-starter-validation" and "org.springdoc:springdoc-openapi-starter-webmvc-api:2.6.0".
I have created a minimum application here: https://github.com/bsgrd/spring-framework-issues-33936

@javapapo
Copy link

+1 on the above aot + spring-starter-validation

@mingchiuli
Copy link
Author

For me the issue was the combination of "spring-boot-starter-validation" and "org.springdoc:springdoc-openapi-starter-webmvc-api:2.6.0". I have created a minimum application here: https://github.com/bsgrd/spring-framework-issues-33936

@bclozel This instance can show my problem

@waileong
Copy link

@bclozel

Minimal sample application https://github.com/waileong/spring-aot-infinite-recursive

Cause of the StackOverflowError

The issue is caused by the commit 357dbc0, which introduced a recursive processAheadOfTime method without a condition to break the recursion. This leads to an infinite recursive loop and eventually a StackOverflowError.

Suggested Fix

To resolve the issue, add a condition to break the infinite recursive loop by keeping track of the classes that have already been validated.

if (validatedClasses.contains(clazz)) {
  // Break the infinite recursive loop
  logger.debug("Class {} has already been validated.", clazz.getName());
  return;
}

@sbrannen sbrannen added type: regression A bug that is also a regression in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Nov 23, 2024
@sbrannen sbrannen added this to the 6.2.1 milestone Nov 23, 2024
@sbrannen sbrannen changed the title processAot cause StackOverflowError AOT processing for bean validation causes StackOverflowError Nov 23, 2024
@sbrannen sbrannen self-assigned this Nov 23, 2024
@sbrannen
Copy link
Member

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2024
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) status: superseded An issue that has been superseded by another theme: aot An issue related to Ahead-of-time processing type: regression A bug that is also a regression
Projects
None yet
8 participants