Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SafeVarargs annotations #4335

Merged
merged 1 commit into from
Mar 29, 2023
Merged

Add SafeVarargs annotations #4335

merged 1 commit into from
Mar 29, 2023

Conversation

hpoettker
Copy link
Contributor

@hpoettker hpoettker commented Mar 25, 2023

This PR adds @SafeVarargs to methods in Chunk and CompositeItemWriter that take a generic varargs parameter but don't perform unsafe operations on them. This prevents false positive warnings in the users' code when they use these methods.

In the constructor of Chunk with the generic varargs parameter, I've replaced Arrays.stream(items).toList() with Arrays.asList(items). Both work fine regarding varargs safety in practice but the latter is explicitly annotated with @SafeVarargs itself, while Arrays.stream does not explicitly say that it works fine with an array of type Object[] in every case. Using Array.asList also saves one copy of the array, which is not needed as the array will be copied later anyway.

@fmbenhassine fmbenhassine added this to the 5.0.2 milestone Mar 29, 2023
@fmbenhassine fmbenhassine merged commit 2b53657 into spring-projects:main Mar 29, 2023
@hpoettker hpoettker deleted the safe-varargs branch March 29, 2023 13:24
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.

2 participants