Make AnthropicChatModel internal methods private - #6718
Conversation
Align AnthropicChatModel with the upgrade notes and other chat model implementations by restricting internalCall and internalStream to private access. Callers should use call() and stream() instead. Fixes spring-projects#6700 Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
kuntal1461
left a comment
There was a problem hiding this comment.
Code Review — Issue #6700: AnthropicChatModel exposes internalStream and internalCall publicly
Verdict: Approve — no blocking findings.
Context
AnthropicChatModel was rewritten in March 2026 to use the official Anthropic Java SDK (b0ce25aed). That rewrite reintroduced public access on internalCall and internalStream, undoing the earlier privacy fix (da3bec4a8, Feb 2026). Every other chat model in the project (OpenAiChatModel, OllamaChatModel, MistralAiChatModel, DeepSeekChatModel, GoogleGenAiChatModel, BedrockProxyChatModel) already declares these methods private, and the upgrade notes explicitly state:
All
internalCallandinternalStreammethods in model classes have been changed toprivate.
This PR is the minimal, correct fix to restore that contract for AnthropicChatModel.
Call-site analysis
A full-codebase grep confirms:
internalCallis called only fromcall()(line 262, same class).internalStreamis called only fromstream()(line 283, same class).- No external callers, no test callers, no reflection usage.
- The class is
final, so no subclass extension concerns. - Neither method appears in
ChatModelorStreamingChatModel, so there is no interface override.
Testing
Ran locally:
./mvnw -pl models/spring-ai-anthropic test
Tests run: 124, Failures: 0, Errors: 0, Skipped: 0 — BUILD SUCCESS
Minor observation (pre-existing, does not block)
The Javadoc on both methods still says "This method is called recursively to support multi-turn tool calling." That description became stale when a48dc60af ("Remove internal tool execution from AnthropicChatModel") delegated recursive tool-call handling to ToolCallingManager. The PR does not need to fix this, but a follow-up Javadoc polish would improve accuracy.
Commit message
Follows the project convention correctly: uppercase verb, no fix: prefix, no PR number in the title, wrapped description, Fixes #6700, and Signed-off-by for DCO.
No blocking code-review findings. Ready to merge after maintainer triage.
| */ | ||
| public Flux<ChatResponse> internalStream(Prompt prompt, @Nullable ChatResponse previousChatResponse) { | ||
| private Flux<ChatResponse> internalStream(Prompt prompt, @Nullable ChatResponse previousChatResponse) { | ||
|
|
There was a problem hiding this comment.
Looks right. The only caller is stream() on line 283, and since the class is final there's no subclass path either — matches what Ollama, Mistral, DeepSeek, and the rest all do.
Nit (pre-existing, not a blocker): the Javadoc still says "called recursively to support multi-turn tool calling" — that's been stale since a48dc60af moved the recursive loop into ToolCallingManager. Worth a follow-up cleanup but doesn't need to hold up this PR.
| */ | ||
| public ChatResponse internalCall(Prompt prompt, @Nullable ChatResponse previousChatResponse) { | ||
| private ChatResponse internalCall(Prompt prompt, @Nullable ChatResponse previousChatResponse) { | ||
|
|
There was a problem hiding this comment.
Same story — only call() on line 262 uses this. Good to have both locked down.
Nit: same stale "called recursively" Javadoc as above.
|
Looks good to me. When the Anthropic module was rewritten to use the official Java SDK ( Checked both call sites — nothing outside this class calls either method, no reflection usage, no interface override. Class is Ran One pre-existing nit on the Javadoc: both methods still mention "called recursively" which stopped being true after |
Thank you for taking time to contribute this pull request!
You might have already read the contributor guide, but as a reminder, please make sure to:
git commit -s) per the DCOmainbranch and squash your commitsFor more details, please check the contributor guide.
Thank you upfront!
Description
AnthropicChatModel.internalStream(andinternalCall) were leftpublicafter the model internal methods were supposed to beprivate(see upgrade notes). Other chat model implementations already useprivate.This change restricts both methods to
private, matching:internalCallandinternalStreammethods in model classes have been changed toprivate"Maintainer @guanxuc confirmed on #6700 that these should be private.
No external callers needed adjustment; both methods are only used within
AnthropicChatModel(call/streamand recursive tool-call loops).Fixes #6700
Testing
Results: 124 tests, 0 failures, 0 errors (JDK 17.0.19)
AI assistance
Created with AI assistance and reviewed by a human.