java.lang.NullPointerException at NamedParamBinder.java:34

Description

Hi,
I've just noticed a NullPointer with the version of hibernate-core-5.3.10,jar:

This is the snippet that generated the NullPointer:

StringBuilder dynamicQuery = new StringBuilder();
int value = 1;
dynamicQuery.append("UPDATE xxxx SET yyyy=:value WHERE CODE IN:zzzz");

Query query = entityManager.createNativeQuery(dynamicQuery.toString());

query.setParameter("yyyy", value);
query.setParameter("zzzz", codeList);
result.setUpdatedRows(query.executeUpdate());

The line query.executeUpdate() generates this error stacktrace:

java.lang.NullPointerException
at org.hibernate.loader.custom.sql.NamedParamBinder.bind(NamedParamBinder.java:34)
at org.hibernate.engine.query.spi.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:102)
at org.hibernate.internal.SessionImpl.executeNativeUpdate(SessionImpl.java:1593)
at org.hibernate.query.internal.NativeQueryImpl.doExecuteUpdate(NativeQueryImpl.java:292)
at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1584)

Looking into the code we've noticed that the class NativeSQLQueryPlan is performing the for cycle:

ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement( sql, false );

try {
int col = 1;
for ( ParameterBinder binder : this.customQuery.getParameterValueBinders() ) {
col += binder.bind( ps, queryParameters, session, col );
}
if ( selection != null && selection.getTimeout() != null ) {
ps.setQueryTimeout( selection.getTimeout() );
}
result = session.getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
}
finally {
if ( ps != null ) {
session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( ps );
session.getJdbcCoordinator().afterStatementExecution();
}
}

executing the for cycle two times (correct) but without binding the second parameter (IN CLAUSE) because it was not recognized.

In the NamedParamBinder, in the second execution of the main for cycle:

PreparedStatement statement,
QueryParameters qp,
SharedSessionContractImplementor session,
int position) throws SQLException {
final TypedValue typedValue = qp.getNamedParameters().get( name );
typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );
return typedValue.getType().getColumnSpan( session.getFactory() );
}

the TypedValue was null, generating the Null pointer in the subsequent line.

Considering that the query was really malformed as it was missing in a space char:

UPDATE xxxx SET yyyy=:value WHERE CODE IN :zzzz

I was wondering if it was possible return a SyntaxValidation Error instead of a Nullpointer.

Environment

hibernate-core-5.3.10,jar

Activity

Show:
viral
September 4, 2020, 1:24 PM

Is this is resolved ? any body looking into this ? i am getting after upgrading

Assignee

Unassigned

Reporter

pietro nardone

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Priority

Major
Configure