Re: Issue with PSQL JDBC Driver Null Pointer

From: Bhavesh Mistry <bhavesh(dot)mistry13(at)gmail(dot)com>
To: davecramer(at)postgres(dot)rocks
Cc: Discuss List Postgres <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Issue with PSQL JDBC Driver Null Pointer
Date: 2021-07-29 19:44:30
Message-ID: CAD1effjzEBH5hQYyo9rsjmqHQQcUCveTYpbZuMKu+6VFCN87oA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Dave,

It still does not address the NPE issue. If an alias is NULL. What should
be the behavior?

public String getTypeForAlias(String alias) {
String type = TYPE_ALIASES.get(alias);
if (type != null) {
return type;
}
type = TYPE_ALIASES.get(alias.toLowerCase()) *// NPE STILL HERE*;
if (type == null) {
type = alias;
}
//populate for future use
TYPE_ALIASES.put(alias, type);
return type;
}
Thanks,

Bhavesh

On Thu, Jul 29, 2021 at 8:44 AM Dave Cramer <davecramer(at)postgres(dot)rocks>
wrote:

>
>
> On Thu, 29 Jul 2021 at 11:04, Bhavesh Mistry <bhavesh(dot)mistry13(at)gmail(dot)com>
> wrote:
>
>> Hello,
>>
>> I am getting an NPE exception in the JDBC driver 42.2.23.
>>
>> When the alias is null, NPE results. Is it possible to handle null
>> value ? I have filled a bug against RCA
>> https://github.com/vladmihalcea/hibernate-types/issues/335. But, I
>> thought that PSQL Driver can handle it more gracefully.
>>
>> Caused by: java.lang.NullPointerException: null
>> at org.postgresql.jdbc.TypeInfoCache.getTypeForAlias(TypeInfoCache.java:675)
>> at org.postgresql.jdbc.TypeInfoCache.getPGArrayType(TypeInfoCache.java:519)
>> at org.postgresql.jdbc.PgConnection.createArrayOf(PgConnection.java:1375)
>> at org.postgresql.jdbc.PgConnection.createArrayOf(PgConnection.java:1399)
>> at org.apache.commons.dbcp2.DelegatingConnection.createArrayOf(DelegatingConnection.java:827)
>> at org.apache.commons.dbcp2.DelegatingConnection.createArrayOf(DelegatingConnection.java:827)
>> at org.apache.commons.dbcp2.DelegatingConnection.createArrayOf(DelegatingConnection.java:827)
>> at com.vladmihalcea.hibernate.type.array.internal.ArraySqlTypeDescriptor$1.doBind(ArraySqlTypeDescriptor.java:36)
>> at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:73)
>> at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:276)
>> at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:271)
>> at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:39)
>> at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2995)
>> at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3292)
>> at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3828)
>> at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:107)
>> at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
>> at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478)
>> at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
>> at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
>> at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:348)
>> at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40)
>> at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:102)
>> at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1362)
>> at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:453)
>> at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3212)
>> at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2380)
>> at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:447)
>> at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183)
>> at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:40)
>> at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281)
>> at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101)
>> ... 123 common frames omitted
>>
>> public String getTypeForAlias(String alias) {
>> String type = typeAliases.get(alias);
>> if (type != null) {
>> return type;
>> }
>> if (alias.indexOf('"') == -1) { *// THIS LINE THROWS NPE SINCE alias is null ** *
>> type = typeAliases.get(alias.toLowerCase());
>> if (type != null) {
>> return type;
>> }
>> }
>> return alias;
>> }
>>
>>
>> It would appear that improv: type alias handling in TypeInfoCache by
> bokken · Pull Request #1986 · pgjdbc/pgjdbc (github.com)
> <https://github.com/pgjdbc/pgjdbc/pull/1986>
> should be backpatched into 42.2.24 which should solve this problem
>
>
> Thanks,
> Dave
>
>>
>> --
>> Thanks,
>>
>> Bhavesh
>>
>>

--
Thanks,

Bhavesh

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dave Cramer 2021-07-29 19:48:44 Re: Issue with PSQL JDBC Driver Null Pointer
Previous Message Rory Campbell-Lange 2021-07-29 19:12:49 Re: PostgreSQL reference coffee mug