- Notifications
You must be signed in to change notification settings - Fork 2.1k
Switch to JSpecify annotations for the model module #5129
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Eric Bottard <eric.bottard@broadcom.com>
sdeleuze left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly good, just a few things to refine from my POV.
See https://jspecify.dev/docs/user-guide/#declaring-generics for my comments about generic types.
| public ChatResponse(List<Generation> generations, ChatResponseMetadata chatResponseMetadata) { | ||
| this.chatResponseMetadata = chatResponseMetadata; | ||
| Assert.notNull(generations, "'generations' must not be null"); | ||
| this.chatResponseMetadata = Objects.requireNonNullElse(chatResponseMetadata, new ChatResponseMetadata()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a defensive check because we want to be lenient if chatResponseMetadata is forced to null?
| return List.of(); | ||
| } | ||
| | ||
| if (!StringUtils.hasText(context.getResponse().getResult().getOutput().getText())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please share more details about why this check can be safely removed?
| | ||
| targetMap.putAll(sourceMap.entrySet() | ||
| .stream() | ||
| .filter(e -> e.getValue() != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we kept a similar defensive filtering in a previous PR, is this one fine to remove?
| } | ||
| | ||
| var nullableAnnotation = parameter.getAnnotation(Nullable.class); | ||
| var nullableAnnotation = parameter.getAnnotation(org.springframework.lang.Nullable.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you should probably use org.springframework.core.Nullness that I have introduced for this kind of use case.
| | ||
| @Override | ||
| public String apply(String template, Map<String, Object> variables) { | ||
| public String apply(String template, Map<String, @Nullable Object> variables) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be Map<String, ? extends @Nullable Object> to allow both Map<String, @Nullable Object> and Map<String, Object> (flexible nullability).
| | ||
| @Override | ||
| public String apply(String template, Map<String, Object> variables) { | ||
| public String apply(String template, Map<String, @Nullable Object> variables) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be Map<String, ? extends @Nullable Object> to allow both Map<String, @Nullable Object> and Map<String, Object> (flexible nullability).
| * @since 1.0.0 | ||
| */ | ||
| public interface TemplateRenderer extends BiFunction<String, Map<String, Object>, String> { | ||
| public interface TemplateRenderer extends BiFunction<String, Map<String, @Nullable Object>, String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be Map<String, ? extends @Nullable Object> to allow both Map<String, @Nullable Object> and Map<String, Object> (flexible nullability).
Same below.
| @SuppressWarnings("unchecked") | ||
| public static BiFunction<?, ToolContext, ?> wrapKotlinBiFunction(Object bean) { | ||
| return (t, u) -> ((Function2<Object, ToolContext, Object>) bean).invoke(t, u); | ||
| public static BiFunction<?, @Nullable ToolContext, ?> wrapKotlinBiFunction(Object bean) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be ? extends @Nullable ToolContext (flexible nullability).
Same below and above.
| private final Type toolInputType; | ||
| | ||
| private final BiFunction<I, ToolContext, O> toolFunction; | ||
| private final BiFunction<I, @Nullable ToolContext, O> toolFunction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be ? extends @Nullable ToolContext (flexible nullability).
Same below.
| private @Nullable ToolMetadata toolMetadata; | ||
| | ||
| private BiFunction<I, ToolContext, O> toolFunction; | ||
| private final BiFunction<I, @Nullable ToolContext, O> toolFunction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be ? extends @Nullable ToolContext (flexible nullability).
Same below.
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!