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

Null Pointer Exception if there is null in hstore #13

Open
smsufyian opened this issue May 14, 2019 · 5 comments
Open

Null Pointer Exception if there is null in hstore #13

smsufyian opened this issue May 14, 2019 · 5 comments

Comments

@smsufyian
Copy link
Contributor

smsufyian commented May 14, 2019

If the 'hstore' column has null value (having a null is different then having no value) throws NullPointerException.
Stack trace :

Caused by: java.lang.NullPointerException: null
	at org.postgresql.util.HStoreConverter.fromString(HStoreConverter.java:116) ~[postgresql-42.2.5.jar:42.2.5]
	at com.github.thealchemist.pg_hibernate.HstoreType.nullSafeGet(HstoreType.java:63) ~[hibernate-postgresql-1.0.19.jar:na]
	at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:119) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.type.AbstractType.hydrate(AbstractType.java:91) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:3007) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1746) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1672) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.Loader.getRow(Loader.java:1561) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:731) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.Loader.processResultSet(Loader.java:990) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.Loader.doQuery(Loader.java:948) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.Loader.doList(Loader.java:2689) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.Loader.doList(Loader.java:2672) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2506) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.Loader.list(Loader.java:2501) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:395) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:220) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1508) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.query.Query.getResultList(Query.java:135) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:74) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
	at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:402) ~[spring-orm-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at com.sun.proxy.$Proxy126.getResultList(Unknown Source) ~[na:na]
	at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:129) ~[spring-data-jpa-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:91) ~[spring-data-jpa-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:136) ~[spring-data-jpa-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:125) ~[spring-data-jpa-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605) ~[spring-data-commons-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) ~[spring-tx-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135) ~[spring-data-jpa-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at com.sun.proxy.$Proxy112.findByHotelIdAndIsOnlineAndIsRemovedByUser(Unknown Source) ~[na:na]

Entity class :

@Data
@Entity
@Table (schema = "datafeeds", name = "\"PartnerHotel\"")
@TypeDefs({
       @TypeDef(name = "hstore", typeClass = HstoreType.class)
})
public class PartnerHotel implements Serializable{
   
   // few more attributes

   @Column(name = "descriptions")
    @Type(type = "hstore")
    private Map<String,String> descriptions = new ConcurrentHashMap<>();
}

On getting hstore where there is no value using Repository gives NullPointerException.

@The-Alchemist
Copy link
Owner

Thank you for finding this bug! Do you think you can write a unit test to reproduce this?

You can probably just add a new method to https://github.com/The-Alchemist/hibernate-postgresql/blob/master/src/test/java/com/github/thealchemist/pg_hibernate/HstoreTypeTest.java

@smsufyian
Copy link
Contributor Author

Thank you for finding this bug! Do you think you can write a unit test to reproduce this?

You can probably just add a new method to https://github.com/The-Alchemist/hibernate-postgresql/blob/master/src/test/java/com/github/thealchemist/pg_hibernate/HstoreTypeTest.java

Sure , I will write a unit test to reproduce the issue

@smsufyian
Copy link
Contributor Author

smsufyian commented May 15, 2019

CREATE TABLE HstoreTypeEntity (
id serial not null,
map hstore,
primary key (id)
);

INSERT INTO datafeeds.test(test) VALUES(null); => To put further details , when you try to get the values of the insertion made using the above statement , gets NullPointerException.

@smsufyian smsufyian changed the title Null Pointer Exception if there is no value in hstore Null Pointer Exception if there is null in hstore May 15, 2019
@smsufyian
Copy link
Contributor Author

@The-Alchemist Can you please take a look at the travis run for the pull request , looks like something is rong with the Travis pipeline ?

travis_setup_postgresql 9.3
Starting PostgreSQL v9.3
Assertion failed on job for [email protected].
sudo systemctl start [email protected]
git.checkout
NaNs$ git clone --depth=50 https://github.com/The-Alchemist/hibernate-postgresql.git The-Alchemist/hibernate-postgresql
Cloning into 'The-Alchemist/hibernate-postgresql'...
remote: Enumerating objects: 417, done.
remote: Counting objects: 100% (417/417), done.
remote: Compressing objects: 100% (166/166), done.
remote: Total 417 (delta 182), reused 401 (delta 169), pack-reused 0
Receiving objects:  89% (372/417)Receiving objects: 100% (417/417), 61.16 KiB | 1.65 MiB/s, done.
Resolving deltas: 100% (182/182), done.
$ cd The-Alchemist/hibernate-postgresql
0.71s$ git fetch origin +refs/pull/14/merge:
remote: Enumerating objects: 206, done.
remote: Counting objects: 100% (122/122), done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 66 (delta 23), reused 59 (delta 19), pack-reused 0
Unpacking objects: 100% (66/66), done.
From https://github.com/The-Alchemist/hibernate-postgresql
 * branch            refs/pull/14/merge -> FETCH_HEAD
$ git checkout -qf FETCH_HEAD
$ java -Xmx32m -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
$ javac -J-Xmx32m -version
javac 11.0.2
0.06s$ psql -c 'create database pg_hibernate;' -U postgres
psql: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
The command "psql -c 'create database pg_hibernate;' -U postgres" failed and exited with 2 during .
Your build has been stopped.

@smsufyian
Copy link
Contributor Author

#15 , please review and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants