You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "carteruu (via GitHub)" <gi...@apache.org> on 2026/10/14 16:46:00 UTC

[PR] Fix NPE in PostgreSQL plugin when executing statements prepared with generated keys [skywalking-java]

carteruu opened a new pull request, #840:
URL: https://github.com/apache/skywalking-java/pull/840

   ### Fix the `NullPointerException` in the PostgreSQL plugin for statements prepared with generated keys (apache/skywalking#14138)
   - [x] Add a unit test to verify that the fix works.
   - [x] Explain briefly why the bug exists and how to fix it.
   
   `PgConnection#prepareStatement(String, String[])` is intercepted by `JDBCPrepareStatementWithStringArrayInterceptor`, which wraps the result in `SWPreparedStatement` but does not set the dynamic field of the real `PgPreparedStatement`. pgjdbc 42.x constructs that statement directly instead of going through the intercepted 4-argument `prepareStatement`, so its dynamic field stays null. `prepareStatement(String, int)` with `Statement.RETURN_GENERATED_KEYS` delegates to this method, and Hibernate and MyBatis use it for generated keys.
   
   `PgPreparedStatement` is still enhanced, so when `SWPreparedStatement` calls the real `executeUpdate` (and the nested `executeWithFlags`), `PreparedStatementExecuteMethodsInterceptor` dereferences the null dynamic field. The agent logs 4 NPEs for every such insert, while the SQL span is still recorded by `SWPreparedStatement`.
   
   This PR skips the interceptor when the dynamic field or its `ConnectionInfo` is null, which is the same guard the MySQL plugin's `PreparedStatementExecuteMethodsInterceptor` already has. Tracing of this path is unchanged. The new unit test fails with the NPE from the issue before this change.
   
   - [x] If this pull request closes/resolves/fixes an existing issue, replace the issue number. Closes https://github.com/apache/skywalking/issues/14138.
   - [x] Update the [`CHANGES` log](https://github.com/apache/skywalking-java/blob/main/CHANGES.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix NPE in PostgreSQL plugin when executing statements prepared with generated keys [skywalking-java]

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng merged PR #840:
URL: https://github.com/apache/skywalking-java/pull/840


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org