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

NullPointerException from Hibernate ORM when there is a problem establishing a connection #44645

Open
shawkins opened this issue Nov 22, 2024 · 3 comments
Labels
area/hibernate-orm Hibernate ORM kind/bug Something isn't working

Comments

@shawkins
Copy link
Contributor

Describe the bug

In some circumstances hibernate fails to report a meaningful error message and instead shows a nullpointerexception:

2024-11-21 19:00:18,827 WARN  [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (JPA Startup Thread) HHH000342: Could not obtain connecti                    on to query metadata: java.lang.NullPointerException: Cannot throw exception because the return value of "java.util.function.BiFunction.apply(Object, Obj                    ect)" is null
        at org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.doTheWork(JtaIsolationDelegate.java:202)
        at org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.lambda$delegateWork$3(JtaIsolationDelegate.java:91)
        at org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.doInSuspendedTransaction(JtaIsolationDelegate.java:123)
        at org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.delegateWork(JtaIsolationDelegate.java:88)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.getJdbcEnvironmentUsingJdbcMetadata(JdbcEnvironmentInitiator.java:276)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:107)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:130)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:238)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:215)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:52)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:136)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:247)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:215)
        at org.hibernate.boot.internal.SessionFactoryOptionsBuilder.<init>(SessionFactoryOptionsBuilder.java:276)
        at io.quarkus.hibernate.orm.runtime.recording.PrevalidatedQuarkusMetadata.buildSessionFactoryOptionsBuilder(PrevalidatedQuarkusMetadata.java:70)
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:84)
        at io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.createEntityManagerFactory(FastBootHibernatePersistenceProvider.java:72)
        at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
        at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
        at io.quarkus.hibernate.orm.runtime.JPAConfig$LazyPersistenceUnit.get(JPAConfig.java:157)
        at io.quarkus.hibernate.orm.runtime.JPAConfig$1.run(JPAConfig.java:64)
        at java.base/java.lang.Thread.run(Thread.java:1583)

See keycloak/keycloak#35181 - this error also appears in other Keycloak and Quarkus issues, such as #31842

Expected behavior

A meaningful exception.

Actual behavior

A nullpointerexception.

How to Reproduce?

Keycloak is using a persistence.xml, I'm not sure if that's a requirement to reproduce this. If you then misconfigure the datasource, such as an invalid password, you should see the null pointer exception.

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

3.8.5

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

No response

Additional information

No response

@shawkins shawkins added the kind/bug Something isn't working label Nov 22, 2024
@quarkus-bot quarkus-bot bot added the area/hibernate-orm Hibernate ORM label Nov 22, 2024
Copy link

quarkus-bot bot commented Nov 22, 2024

/cc @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

@yrodiere
Copy link
Member

I think the most likely cause would be either the sqlExceptionConverter being passed a null exception (in which case the bug is in whatever called the sqlExceptionConverter), or the sqlExceptionConverter returning null as the "converted" exception (in which case the bug is in the sqlExceptionConverter)

Quoting keycloak/keycloak#35014 (comment) :

it seems caused by the exception converter returning null, which certainly looks like a bug, possibly caused by this line.

We probably need, at least, to check in Hibernate ORM that sqlExceptionConverter implementations never return null, because I think that would be a bug.

@yrodiere
Copy link
Member

Also, thanks for creating the bug report @shawkins :)

@yrodiere yrodiere changed the title NullPointerException from hibernated when there is a problem establishing a connection NullPointerException from Hibernate ORM when there is a problem establishing a connection Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants