ChatResponse `getResult` method implementation is not consist with interface `ModelResponse` which the package is annotated with `@NonNullApi`

Open
#4,413 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
38/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
java

Research direction

Start with ChatResponse#getResult and the ModelResponse contract, then inspect the org.springframework.ai.model package nullability annotations. Determine the intended handling of an empty generations collection; done means the implementation and declared nullability agree and the reported IntelliJ IDEA and Kotlin checks no longer conflict.

Written by the indexing model from the issue text.

Description

status: waiting-for-triage

The package org.springframework.ai.model is annotated with @NonNullApi

@NonNullApi
@NonNullFields
package org.springframework.ai.model;

import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

So all methods of interface org.springframework.ai.model.ModelResponse are annotated with @NonNull implicitly.

But in ChatResponse implementation, the getResult method could return null:

public Generation getResult() {
	if (CollectionUtils.isEmpty(this.generations)) {
		return null;
	}
	return this.generations.get(0);
}

It breaks IntelliJ IDEA and Kotlin nullability check.

Image
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 10h
Merged PRs (30d)
5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spring-projects/spring-ai

All issues in spring-projects/spring-ai

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.