Skip to content

NullPointerException during AOT processing when MongoDB domain model #4958

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

Open
ckdgus08 opened this issue Apr 30, 2025 · 2 comments
Open

NullPointerException during AOT processing when MongoDB domain model #4958

ckdgus08 opened this issue Apr 30, 2025 · 2 comments
Labels
status: feedback-provided Feedback has been provided

Comments

@ckdgus08
Copy link

ckdgus08 commented Apr 30, 2025

Hello,

First of all, thank you for your continued work on the Spring ecosystem.
I encountered a NullPointerException while using Spring Boot 3.4.5 with AOT processing enabled, and I'd like to report a potential bug.

Based on my debugging, it seems that a NullPointerException occurs when using Jackson with Mongo data models annotated with @ Document.

If this issue is not already being worked on, I would like to submit a pull request with a fix.

Environment

  • Spring Boot: 3.4.5
  • Spring Data MongoDB
  • GraalVM / Native AOT enabled

Stack Trace

Exception in thread "main" org.springframework.beans.factory.aot.AotBeanProcessingException: Error processing bean with name 'mongoManagedTypes' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataConfiguration.class]: failed to generate code for bean definition
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.lambda$generateRegisterBeanDefinitionMethods$2(BeanRegistrationsAotContribution.java:217)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.generateRegisterBeanDefinitionMethods(BeanRegistrationsAotContribution.java:207)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.lambda$generateSliceMethod$1(BeanRegistrationsAotContribution.java:198)
	at org.springframework.aot.generate.GeneratedMethod.<init>(GeneratedMethod.java:54)
	at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:112)
	at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:89)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.generateSliceMethod(BeanRegistrationsAotContribution.java:194)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.lambda$generateRegisterBeanDefinitionsMethod$0(BeanRegistrationsAotContribution.java:181)
	at org.springframework.aot.generate.GeneratedMethod.<init>(GeneratedMethod.java:54)
	at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:112)
	at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:89)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.generateRegisterBeanDefinitionsMethod(BeanRegistrationsAotContribution.java:166)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.applyTo(BeanRegistrationsAotContribution.java:77)
	at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:96)
	at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:58)
	at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67)
	at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53)
	at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:106)
	at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84)
	at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49)
	at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:83)
	at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:80)
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Package.getName()" because the return value of "java.lang.Class.getPackage()" is null
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Package.getName()" because the return value of "java.lang.Class.getPackage()" is null

	at org.springframework.data.util.QTypeContributor.getQueryClassName(QTypeContributor.java:83)
	at org.springframework.data.util.QTypeContributor.contributeEntityPath(QTypeContributor.java:44)
	at org.springframework.data.aot.ManagedTypesBeanRegistrationAotProcessor.contributeType(ManagedTypesBeanRegistrationAotProcessor.java:140)
	at org.springframework.data.mongodb.aot.MongoManagedTypesBeanRegistrationAotProcessor.contributeType(MongoManagedTypesBeanRegistrationAotProcessor.java:53)
	at org.springframework.data.aot.ManagedTypesRegistrationAotContribution.lambda$applyTo$0(ManagedTypesRegistrationAotContribution.java:96)
	at org.springframework.data.util.TypeCollector.processType(TypeCollector.java:103)
	at org.springframework.data.util.TypeCollector.processType(TypeCollector.java:117)
	at org.springframework.data.util.TypeCollector.processType(TypeCollector.java:117)
	at org.springframework.data.util.TypeCollector.processType(TypeCollector.java:117)
	at org.springframework.data.util.TypeCollector.processType(TypeCollector.java:117)
	at org.springframework.data.util.TypeCollector.processType(TypeCollector.java:117)
	at org.springframework.data.util.TypeCollector.processType(TypeCollector.java:117)
	at org.springframework.data.util.TypeCollector.processType(TypeCollector.java:117)
	at org.springframework.data.util.TypeCollector.processType(TypeCollector.java:117)
	at org.springframework.data.util.TypeCollector.processType(TypeCollector.java:117)
	at org.springframework.data.util.TypeCollector.processType(TypeCollector.java:117)
	at org.springframework.data.util.TypeCollector.process(TypeCollector.java:90)
	at org.springframework.data.util.TypeCollector$ReachableTypes.lambda$forEach$0(TypeCollector.java:229)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at org.springframework.data.util.TypeCollector$ReachableTypes.forEach(TypeCollector.java:229)
	at org.springframework.data.aot.ManagedTypesRegistrationAotContribution.applyTo(ManagedTypesRegistrationAotContribution.java:96)
	at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.lambda$generateBeanDefinitionMethod$2(BeanDefinitionMethodGenerator.java:165)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.generateBeanDefinitionMethod(BeanDefinitionMethodGenerator.java:165)
	at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.generateBeanDefinitionMethod(BeanDefinitionMethodGenerator.java:89)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.generateBeanRegistration(BeanRegistrationsAotContribution.java:226)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.lambda$generateRegisterBeanDefinitionMethods$2(BeanRegistrationsAotContribution.java:209)
	... 22 more
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 30, 2025
@christophstrobl
Copy link
Member

Thank you for reporting! Please help us diagnose the issue by providing a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem. Right now I do not see the Jackson & MongoDB connection but some Q class resolution failure for Querydsl generated types.

@christophstrobl christophstrobl added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels May 2, 2025
@ckdgus08
Copy link
Author

ckdgus08 commented May 4, 2025

I’ve created a minimal project that reproduces the issue. You can find it here:

🔗 https://github.com/ckdgus08/demo-aot-npe

It uses Spring Boot with AOT enabled and includes Querydsl and MongoDB dependencies.

The issue occurs during the AOT processing phase while generating metadata for the Querydsl-generated Q classes. Specifically, it seems to be triggered when Jackson-related code is being processed—possibly during introspection or serialization configuration. This causes the AOT engine to fail when trying to handle the generated Querydsl types.

Please let me know if there’s anything I can improve or clarify further. Thanks again for taking a look!

Image

@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 May 4, 2025
ckdgus08 added a commit to ckdgus08/spring-data-commons that referenced this issue May 4, 2025
…types.

Related tickets: spring-projects/spring-data-mongodb#4958

Signed-off-by: ckdgus08 <ckdgus0808@naver.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided
Projects
None yet
Development

No branches or pull requests

3 participants