chore: prevent NPE in solution annotation processing#1684
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
Refactors solution annotation processing to centralize null-checks and improve error reporting, helping to prevent NullPointerExceptions.
- Extracted inline annotation lookup logic into a dedicated
extractPlanningSolutionAnnotationmethod. - Added
@NonNullannotation and detailed error messages for missing@PlanningSolution. - Simplified cloner retrieval by calling
annotation.solutionCloner()directly.
Comments suppressed due to low confidence (3)
core/src/main/java/ai/timefold/solver/core/impl/domain/solution/descriptor/SolutionDescriptor.java:411
- [nitpick] Consider adding a JavaDoc comment to
extractPlanningSolutionAnnotationto explain its purpose, return guarantee, and the conditions under which it throws an exception.
private @NonNull PlanningSolution extractPlanningSolutionAnnotation() {
core/src/main/java/ai/timefold/solver/core/impl/domain/solution/descriptor/SolutionDescriptor.java:411
- There are no tests covering the new
extractPlanningSolutionAnnotationmethod, especially for cases where the annotation is on the superclass or missing entirely. Consider adding unit tests for these scenarios to ensure correct behavior.
private @NonNull PlanningSolution extractPlanningSolutionAnnotation() {
core/src/main/java/ai/timefold/solver/core/impl/domain/solution/descriptor/SolutionDescriptor.java:402
- The original logic used
PlanningSolution.NullSolutionClonerwhen only a superclass annotation was present. This change now applies the superclass'ssolutionCloner, which alters behavior. Confirm whether this is intentional or adjust to preserve the previous fallback behavior.
var solutionClonerClass = annotation.solutionCloner();
zepfred
reviewed
Jul 7, 2025
|
zepfred
approved these changes
Jul 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Was bringing our Sonar rating down to C.