Re: Issue with PSQL JDBC Driver Null Pointer - Mailing list pgsql-general

From Edson Carlos Ericksson Richter
Subject Re: Issue with PSQL JDBC Driver Null Pointer
Date
Msg-id d999c7dc-f47a-6d4e-e44f-a9e4a0bb6072@simkorp.com.br
Whole thread Raw
In response to Re: Issue with PSQL JDBC Driver Null Pointer  (Bhavesh Mistry <bhavesh.mistry13@gmail.com>)
List pgsql-general
I would do


public String getTypeForAlias(String alias) {

    if (alias==null) return null; // this shall solve NPE on
alias.toLowerCase()

    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;

    }




Em 29/07/2021 16:44, Bhavesh Mistry escreveu:
> 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@postgres.rocks> wrote:
>
>
>
>     On Thu, 29 Jul 2021 at 11:04, Bhavesh Mistry
>     <bhavesh.mistry13@gmail.com <mailto:bhavesh.mistry13@gmail.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
>         <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
>



pgsql-general by date:

Previous
From: Dave Cramer
Date:
Subject: Re: Issue with PSQL JDBC Driver Null Pointer
Next
From: Bhavesh Mistry
Date:
Subject: Re: Issue with PSQL JDBC Driver Null Pointer