question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.InstantiationError after upgrading to Spring Boot 2.4.4 (spring data commons 2.4.6)

See original GitHub issue

In a Spring Boot application we use Spring Data Mongo to map some documents. Some of them have embedded documents with a hierarchy, e.g.:

@Document("projects")
@TypeAlias("project")
data class Project(
       ...
       val budget: ProjectBudget)
abstract class ProjectBudget {

    abstract fun getCurrentBudget(): MonetaryAmount?

}
@TypeAlias("projectProjectBudget")
class ClosedProjectBudget(... ) : ProjectBudget() {}

Up to Spring Boot 2.4.3 when retrieving a Project instance the corresponding ProjectBudget subclass what built correctly. However after the upgrade to Boot 2.4.4 we get this exception:

Caused by: java.lang.InstantiationError: xxx.ProjectBudget
	at xxx.ProjectBudget_Instantiator_srp3na.newInstance(Unknown Source)
	at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator$EntityInstantiatorAdapter.createInstance(ClassGeneratingEntityInstantiator.java:238)
	at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:87)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:344)

There seems to be a regression when instantiating subclasses.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
mp911decommented, Mar 23, 2021

This looks actually as if the subclass isn’t registered with MappingContext. To properly resolve the target class using TypeAlias, it must be already present in the context.

Can you isolate the issue and provide a minimal reproducer?

1reaction
mp911decommented, Mar 25, 2021

I entirely missed the fact of the custom Mongo configuration MongoDbClientConfiguration hence I relied on Spring Boot to perform the entity scan.

I moved the ticket into Spring Data MongoDB. The difference comes from #3592 where we removed @Persistent as marker annotation from the entity scan in Spring Data MongoDB. Previously, this arrangement worked because @TypeAlias is meta-annotated with @Persistent and so entities annotated with @TypeAlias are picked up as entities during the scan.

ServiceProjectBudget and ProjectProjectBudget aren’t subtypes of Project hence the @Document annotation doesn’t apply these types. So annotating both types with @Document is the way to go and it worked previously rather by accident and not by intent.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot 2.4.4 failed to start after upgrading - Stack Overflow
I am upgrading Spring boot application, which is currently working on 2.1.13 to 2.4.4. After upgrade, spring boot application is not ...
Read more >
Spring Data Commons - Reference Documentation
Dependency Management with Spring Boot. Spring Boot selects a recent version of Spring Data modules for you. If you still want to upgrade...
Read more >
org.springframework.data:spring-data-commons vulnerabilities
version published direct vulnerabilities 3.0.0 18 Nov, 2022 0. C. 0. H. 0. M. 0. L 2.7.6 18 Nov, 2022 0. C. 0. H. 0....
Read more >
org.springframework.data » spring-data-commons » 2.4.6
Compile Dependencies (32) ; Func. Programming Apache 2.0, logo, io.vavr » vavr (optional) ; Java Spec CDDLGPL 2.0, logo, javax.annotation » javax.
Read more >
Spring Data Core 3.0.0 API - Javadoc.io
Core annotations being used by Spring Data. ... Support for registering the need for reflection, resources, java serialization and proxies at runtime for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found