StackOverflowError with AttributeConverter hierarchy with generic parameter

Hi,

I use Spring Boot 4.1.0 with Hibernate 7.4.1.Final and just using a hierarchy of two attribute converters that both have a generic parameter T results in a StackOverflowError when creating the EntityManager:

[ERROR] com.example.hibernatestackoverflowerror.HibernateStackOverflowErrorApplicationTests.contextLoads -- Time elapsed: 0.009 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext for [MergedContextConfiguration@16949dfa testClass = com.example.hibernatestackoverflowerror.HibernateStackOverflowErrorApplicationTests, locations = [], classes = [com.example.hibernatestackoverflowerror.HibernateStackOverflowErrorApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.context.PropertyMappingContextCustomizer@0, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@37b70343, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@354fc8f0, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@5b43fbf6, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@c573e310], contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.lambda$loadContext$0(DefaultCacheAwareContextLoaderDelegate.java:195)
	at org.springframework.test.context.cache.DefaultContextCache.put(DefaultContextCache.java:214)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:160)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:128)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:156)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:111)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:260)
	at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:242)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:186)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1724)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:153)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:176)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:632)
	at java.base/java.util.Optional.orElseGet(Optional.java:368)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1612)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1612)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/hibernate/autoconfigure/HibernateJpaConfiguration.class]: null
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1815)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:603)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:525)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:371)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:331)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:201)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:977)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:621)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:756)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:445)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
	at org.springframework.boot.test.context.SpringBootContextLoader.lambda$loadContext$2(SpringBootContextLoader.java:155)
	at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58)
	at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46)
	at org.springframework.boot.SpringApplication.withHook(SpringApplication.java:1465)
	at org.springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook.run(SpringBootContextLoader.java:600)
	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:155)
	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:114)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:247)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.lambda$loadContext$0(DefaultCacheAwareContextLoaderDelegate.java:167)
	... 21 more
Caused by: java.lang.StackOverflowError
	at org.hibernate.internal.util.GenericsHelper.substituteTypeArguments(GenericsHelper.java:267)
	at org.hibernate.internal.util.GenericsHelper.replaceTypeVariableWithArgument(GenericsHelper.java:254)
	at org.hibernate.internal.util.GenericsHelper.substituteTypeArguments(GenericsHelper.java:267)
	at org.hibernate.internal.util.GenericsHelper.replaceTypeVariableWithArgument(GenericsHelper.java:254)
	at org.hibernate.internal.util.GenericsHelper.substituteTypeArguments(GenericsHelper.java:267)
	at org.hibernate.internal.util.GenericsHelper.replaceTypeVariableWithArgument(GenericsHelper.java:254)
	at org.hibernate.internal.util.GenericsHelper.substituteTypeArguments(GenericsHelper.java:267)
	at org.hibernate.internal.util.GenericsHelper.replaceTypeVariableWithArgument(GenericsHelper.java:254)
	at org.hibernate.internal.util.GenericsHelper.substituteTypeArguments(GenericsHelper.java:267)
...

The error does not occur if I change the generic parameter on one of the attribute converters to A.

I have created a minimal producer here: GitHub - trettstadt/hibernate-stackoverflowerror · GitHub

I tried to create an issue, but Jira always says that I do not have the necessary permissions. Perhaps someone can have a look and create a bug report?

Thanks and best regards,
Tobias

We have a long thread in our Zulip chat where people come by every now and then and it’s always the same

You are probably logged into another Jira organization’s account. Can you please click on your profile picture in the top-right and show us what’s there?

This topic also mentioned the problem: Trying to report a bug in Hibernate - #15 by luiscla27

Alright, clicking account icon → Login does help. Another annoying thing is that the banner is displayed only after you do that :slight_smile: . While you are authenticated, but before clicking that another Login thing, the banner is not displayed :slight_smile: .

After clicking Login I was added to the Hibernate space and could create the issue. Thanks for your help!

FWIW, it was reported that this is still an issue after fixing HHH-20265, but we don’t have an isolated Hibernate ORM only reproducer for this yet. Would you mind creating a new Jira ticket and attach a reproducer?

I created the new issue HHH-20624 with a Spring Boot reproducer. I will try to provide a Hibernate ORM only reproducer today.

I updated the issue with a Hibernate ORM only reproducer. Basically I just copied the two abstract attribute converters from my Spring Boot reproducer to the hibernate-orm-7 test case template.

Actually someone already created an issue with a Hibernate ORM only reproducer for exactly this case: HHH-20467 Development of a workaround is currently ongoing: HHH-20467 Exclude abstract converters from global registrations by quaff · Pull Request #12716 · hibernate/hibernate-orm · GitHub