Skip to content

Conversation

@KoreaNirsa
Copy link
Contributor

Description

This pull request removes the redundant Assert.notNull(...) check from the OpenAiApi.Builder#apiKey(String) method.

Motivation

The SimpleApiKey constructor already performs a null check and throws an IllegalArgumentException if the value is null:

java
public SimpleApiKey(String value) {
    Assert.notNull(value, "API key value must not be null or empty");
    this.value = value;
}

Thus, the additional null check inside the builder is unnecessary and violates the DRY principle (Don't Repeat Yourself).
By relying on the constructor's validation, the code becomes cleaner and easier to maintain.

Impact
No behavioral change; exception will still be thrown with the same message if the input is null.

Improves code clarity and separation of responsibility.

@ilayaperumalg
Copy link
Member

@KoreaNirsa Thanks for the PR!

@ilayaperumalg ilayaperumalg merged commit a1c341a into spring-projects:main Jun 25, 2025
2 checks passed
spring-builds pushed a commit that referenced this pull request Jun 25, 2025
scionaltera pushed a commit to scionaltera/spring-ai that referenced this pull request Sep 3, 2025
chedim pushed a commit to couchbaselabs/spring-ai that referenced this pull request Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants