shashank created CAMEL-26704:
--------------------------------

             Summary: camel-sql - DefaultJdbcOptimisticLockingExceptionMapper 
throws NullPointerException for an SQLException without SQLState
                 Key: CAMEL-26704
                 URL: https://issues.apache.org/jira/browse/CAMEL-26704
             Project: Camel
          Issue Type: Bug
          Components: camel-sql
            Reporter: shashank
            Assignee: shashank


{{DefaultJdbcOptimisticLockingExceptionMapper.isConstraintViolation}} calls 
{{e.getSQLState().startsWith("23")}}. The SQLState is optional in JDBC, and 
connection pools can report a pool timeout without one (Agroal, and HikariCP's 
{{SQLTransientConnectionException}} when the pool is exhausted).

The mapper walks the cause chain from the root cause up, so the first 
{{SQLException}} without SQLState throws a {{NullPointerException}} out of 
{{isOptimisticLocking}}, before the {{DataIntegrityViolationException}} and 
class-name checks run. The only caller is the {{catch}} in 
{{JdbcAggregationRepository.add(camelContext, key, oldExchange, newExchange)}} 
(aggregate EIP with {{optimisticLocking}}). There the NPE replaces the real 
exception: it has no cause, so the SQL error is lost and 
{{onException(SQLException.class)}} (for example with redeliveries for 
transient database errors) no longer matches.

{code:java}
SQLException e = new SQLTransientConnectionException("Connection is not 
available, request timed out");
new DefaultJdbcOptimisticLockingExceptionMapper().isOptimisticLocking(new 
CannotCreateTransactionException("Could not open connection", e));
// NullPointerException: Cannot invoke "String.startsWith(String)" because the 
return value of "java.sql.SQLException.getSQLState()" is null
{code}

Expected: an {{SQLException}} without SQLState is not a constraint violation, 
and the other checks still run.

Suggested fix: a null check in {{isConstraintViolation}}; no other change.

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to