Skip to content

fix(openai): handle null statusCode in HttpTransportException to prevent NPE#928

Merged
LearningGp merged 3 commits intoagentscope-ai:mainfrom
shlokmestry:fix/openai-client-npe-status-code
Mar 20, 2026
Merged

fix(openai): handle null statusCode in HttpTransportException to prevent NPE#928
LearningGp merged 3 commits intoagentscope-ai:mainfrom
shlokmestry:fix/openai-client-npe-status-code

Conversation

@shlokmestry
Copy link
Copy Markdown
Contributor

1.0.10-SNAPSHOT

Fixes a NullPointerException in OpenAIClient.stream() caused by auto-unboxing
a nullable Integer when HttpTransportException has no HTTP status code
(e.g. connection failure, DNS error, timeout).

The existing code passed getStatusCode() (return type Integer, nullable)
directly to OpenAIException.create(int, ...), which throws an NPE when
statusCode is null.

Fix: Added a null check before accessing getStatusCode(). If null, falls back
to new OpenAIException(msg, ex) instead of crashing.

Fixes #891

@shlokmestry shlokmestry requested a review from a team March 11, 2026 21:48
@shlokmestry
Copy link
Copy Markdown
Contributor Author

Ran OpenAIClientExceptionTest locally : 17/17 tests pass (Failures: 0, Errors: 0). The only failing test in the full suite (ShellCommandToolTest$BufferDeadlockTests) is unrelated to this change. CI failures are due to Codecov token not being configured for fork PRs and a Windows build timeout, not the code change itself.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...in/java/io/agentscope/core/model/OpenAIClient.java 50.00% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@LearningGp LearningGp merged commit dcec8fc into agentscope-ai:main Mar 20, 2026
5 of 6 checks passed
@shlokmestry shlokmestry deleted the fix/openai-client-npe-status-code branch March 22, 2026 14:21
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.

NPE in OpenAIClient: HttpTransportException.getStatusCode() null auto-unboxing

2 participants