Skip to content

[#8166] fix: treat PostgreSQL SQLSTATE as string#8260

Merged
justinmclean merged 2 commits intoapache:mainfrom
iinow:main
Aug 25, 2025
Merged

[#8166] fix: treat PostgreSQL SQLSTATE as string#8260
justinmclean merged 2 commits intoapache:mainfrom
iinow:main

Conversation

@iinow
Copy link
Contributor

@iinow iinow commented Aug 22, 2025

What changes were proposed in this pull request?

Fix bug in PostgreSQLExceptionConverter where SQLSTATE codes were parsed as numbers.
Now SQLSTATE is treated as a string to avoid NumberFormatException (e.g., "28P01").

Why are the changes needed?

PostgreSQL SQLSTATE codes can include letters. Parsing them as integers causes runtime errors.

Fix: #8166

Does this PR introduce any user-facing change?

No

How was this patch tested?

  1. Added unit tests for numeric code ("23505") and non-numeric code ("28P01").
  2. Verified tests pass successfully.

@iinow iinow force-pushed the main branch 5 times, most recently from 54fab80 to f871989 Compare August 23, 2025 02:55
@shaofengshi
Copy link
Contributor

LGTM; @yuqi1129 Yuqi, what do you think?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the PostgreSQL exception converter where SQLSTATE codes were incorrectly parsed as integers, causing NumberFormatException when encountering alphanumeric codes like "28P01".

  • Changed SQLSTATE handling from integer parsing to string comparison
  • Added comprehensive unit tests for both numeric and alphanumeric SQLSTATE codes

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
PostgreSQLExceptionConverter.java Changed SQLSTATE handling from integer to string to support alphanumeric codes
TestPostgreSQLExceptionConverter.java Added unit tests covering numeric and non-numeric SQLSTATE scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member

@justinmclean justinmclean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this, much appreciated

@justinmclean justinmclean merged commit 5c2047d into apache:main Aug 25, 2025
28 checks passed
diqiu50 pushed a commit to diqiu50/gravitino that referenced this pull request Sep 15, 2025
### What changes were proposed in this pull request?

Fix bug in `PostgreSQLExceptionConverter` where SQLSTATE codes were
parsed as numbers.
Now SQLSTATE is treated as a string to avoid `NumberFormatException`
(e.g., "28P01").

### Why are the changes needed?

PostgreSQL SQLSTATE codes can include letters. Parsing them as integers
causes runtime errors.

Fix: apache#8166

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

1. Added unit tests for numeric code ("23505") and non-numeric code
("28P01").
2. Verified tests pass successfully.

Co-authored-by: 이준하 <joonha.lee@kia.com>
Co-authored-by: Justin Mclean <justin@classsoftware.com>
bharos pushed a commit to bharos/gravitino that referenced this pull request Oct 3, 2025
### What changes were proposed in this pull request?

Fix bug in `PostgreSQLExceptionConverter` where SQLSTATE codes were
parsed as numbers.
Now SQLSTATE is treated as a string to avoid `NumberFormatException`
(e.g., "28P01").

### Why are the changes needed?

PostgreSQL SQLSTATE codes can include letters. Parsing them as integers
causes runtime errors.

Fix: apache#8166

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

1. Added unit tests for numeric code ("23505") and non-numeric code
("28P01").
2. Verified tests pass successfully.

Co-authored-by: 이준하 <joonha.lee@kia.com>
Co-authored-by: Justin Mclean <justin@classsoftware.com>
bharos pushed a commit to bharos/gravitino that referenced this pull request Oct 7, 2025
### What changes were proposed in this pull request?

Fix bug in `PostgreSQLExceptionConverter` where SQLSTATE codes were
parsed as numbers.
Now SQLSTATE is treated as a string to avoid `NumberFormatException`
(e.g., "28P01").

### Why are the changes needed?

PostgreSQL SQLSTATE codes can include letters. Parsing them as integers
causes runtime errors.

Fix: apache#8166

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

1. Added unit tests for numeric code ("23505") and non-numeric code
("28P01").
2. Verified tests pass successfully.

Co-authored-by: 이준하 <joonha.lee@kia.com>
Co-authored-by: Justin Mclean <justin@classsoftware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] Fix handling of SQL exception error codes in PostgreSQLExceptionConverter.java

5 participants