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

java.lang.StackOverflowError during build when using hibernate-orm with CompositeAttribute within hbm.xml #22685

Closed
digsb opened this issue Jan 6, 2022 · 3 comments · Fixed by #22701
Assignees
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Milestone

Comments

@digsb
Copy link
Contributor

digsb commented Jan 6, 2022

Describe the bug

As part of migration our legacy Java Hibernate project to Quarkus, we faced this issue.

During compilation we got this error:

[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:2.6.1.Final:build (default) on project code-with-quarkus: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] 	[error]: Build step io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor#defineJpaEntities threw an exception: java.lang.StackOverflowError
[ERROR] 	at java.base/java.util.HashMap.hash(HashMap.java:340)
[ERROR] 	at java.base/java.util.HashMap.get(HashMap.java:553)
[ERROR] 	at java.base/java.util.Collections$UnmodifiableMap.get(Collections.java:1454)
[ERROR] 	at org.jboss.jandex.Index.getClassByName(Index.java:301)
[ERROR] 	at org.jboss.jandex.CompositeIndex.getClassByName(CompositeIndex.java:201)
[ERROR] 	at org.jboss.jandex.CompositeIndex.getClassByName(CompositeIndex.java:201)
[ERROR] 	at io.quarkus.deployment.index.IndexWrapper.getClassByName(IndexWrapper.java:62)
[ERROR] 	at org.jboss.jandex.CompositeIndex.getClassByName(CompositeIndex.java:201)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.addClassHierarchyToReflectiveList(JpaJandexScavenger.java:429)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.enlistExplicitClass(JpaJandexScavenger.java:312)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:300)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.JpaJandexScavenger.collectHbmXmlEmbeddedTypes(JpaJandexScavenger.java:304)

I tried to check in the source as pointed in stack trace and found this method. Last line of the method call caught my eye, as we are passing the same attributes again in recursive call.

private void collectHbmXmlEmbeddedTypes(Collector collector, String packagePrefix, List<?> attributes) {
        for (Object attribute : attributes) {
            if (attribute instanceof JaxbHbmCompositeAttributeType) {
                JaxbHbmCompositeAttributeType compositeAttribute = (JaxbHbmCompositeAttributeType) attribute;
                String name = packagePrefix + compositeAttribute.getClazz();
                enlistExplicitClass(collector, name);
                // The call to 'enlistExplicitClass' above may not
                // detect that this class is an entity if it is not annotated
                collector.entityTypes.add(name);
                collectHbmXmlEmbeddedTypes(collector, packagePrefix, attributes);
            }
        }
    }

I made some modification to the code and this solved my StackOverflowError issue. But not sure if this is the correct way to fix it.

private void collectHbmXmlEmbeddedTypes(Collector collector, String packagePrefix, List<?> attributes) {
        for (Object attribute : attributes) {
            if (attribute instanceof JaxbHbmCompositeAttributeType) {
                JaxbHbmCompositeAttributeType compositeAttribute = (JaxbHbmCompositeAttributeType) attribute;
                String name = packagePrefix + compositeAttribute.getClazz();
                enlistExplicitClass(collector, name);
                // The call to 'enlistExplicitClass' above may not
                // detect that this class is an entity if it is not annotated
                collector.entityTypes.add(name);
                collectHbmXmlEmbeddedTypes(collector, packagePrefix,
                        ((JaxbHbmCompositeAttributeType) attribute).getAttributes());
            }
        }
    }

Expected behavior

Build should complete successfully.

Actual behavior

Getting java.lang.StackOverflowError

How to Reproduce?

No response

Output of uname -a or ver

Linux ubuntu 4.15.0-159-generic #167-Ubuntu SMP Tue Sep 21 08:55:05 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.18.04) OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.18.04, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.6.1.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)

Additional information

No response

@digsb digsb added the kind/bug Something isn't working label Jan 6, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 6, 2022

/cc @Sanne, @gsmet, @yrodiere

@quarkus-bot quarkus-bot bot added area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE labels Jan 6, 2022
@yrodiere
Copy link
Member

yrodiere commented Jan 6, 2022

Thanks. Your patch looks right, though you could simplify the line to:

                collectHbmXmlEmbeddedTypes(collector, packagePrefix, compositeAttribute.getAttributes());

Do you think you could submit a pull request?

@digsb
Copy link
Contributor Author

digsb commented Jan 6, 2022

@yrodiere, sure I can do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants