fix(rdb): null-guard view/function/procedure list endpoints - #2404
Conversation
…d#2403) DbFunctionController/DbProcedureController/DbViewController list endpoints called .size() directly on the service/converter result, NPEing when it returned null (some JDBC drivers return null for empty result sets). DbTriggerController already guarded with CollectionUtils.isNotEmpty. Align the three with a null-safe size computation. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: liuhy <liuhongyu@apache.org>
There was a problem hiding this comment.
Pull request overview
This PR fixes a null-handling bug in the RDB metadata “list” endpoints for views, functions, and procedures. Previously, these controllers called .size() on potentially null lists (some JDBC drivers can return null instead of an empty list), causing NPEs; the change aligns their behavior with the already-null-safe trigger endpoint pattern.
Changes:
- Add null-safe
sizecomputation inDbViewController.list,DbFunctionController.list, andDbProcedureController.list. - Preserve existing “fake pagination” behavior while ensuring
WebPageResult.of(...)is constructed without dereferencing a null list.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| chat2db-community-server/chat2db-community-web/src/main/java/ai/chat2db/community/web/api/controller/DbViewController.java | Null-guards the converted view list before computing size/total for WebPageResult. |
| chat2db-community-server/chat2db-community-web/src/main/java/ai/chat2db/community/web/api/controller/DbProcedureController.java | Null-guards procedure list before computing size/total for WebPageResult. |
| chat2db-community-server/chat2db-community-web/src/main/java/ai/chat2db/community/web/api/controller/DbFunctionController.java | Null-guards function list before computing size/total for WebPageResult. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
openai0229
left a comment
There was a problem hiding this comment.
Reviewed the null normalization across the three metadata list endpoints after syncing with the latest main. The Web module packages successfully. This PR only addresses the null-result NPE; the description now uses Refs #2403 so the still-open result-cap/pagination work is not closed incorrectly.
What
DbFunctionController,DbProcedureController, andDbViewControllerlistendpoints called.size()directly on the service/converter result, NPEing when it returnednull(some JDBC drivers returnnullfor empty result sets).DbTriggerControlleralready guards withCollectionUtils.isNotEmpty.Location
DbViewController.java:53-57DbFunctionController.java:38-42DbProcedureController.java:38-42DbTriggerController.java:39-43(reference, already guarded)Fix
Align the three unguarded controllers with a null-safe size computation (compute
sizeonly when non-null). MirrorsDbTriggerController's intent without adding an import. Real DB-level pagination is a separate feature.Verification
Long.valueOf(size)wheresizeis an int;1/sizeautobox to Integer forof(List, Long, Integer, Integer).Refs #2403
🤖 Generated with Claude Code