Skip to content

chore: prevent NPE in solution annotation processing#1684

Merged
triceo merged 3 commits into
TimefoldAI:mainfrom
triceo:sonar
Jul 7, 2025
Merged

chore: prevent NPE in solution annotation processing#1684
triceo merged 3 commits into
TimefoldAI:mainfrom
triceo:sonar

Conversation

@triceo

@triceo triceo commented Jul 7, 2025

Copy link
Copy Markdown
Collaborator

Was bringing our Sonar rating down to C.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 extractPlanningSolutionAnnotation method.
  • Added @NonNull annotation 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 extractPlanningSolutionAnnotation to 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 extractPlanningSolutionAnnotation method, 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.NullSolutionCloner when only a superclass annotation was present. This change now applies the superclass's solutionCloner, which alters behavior. Confirm whether this is intentional or adjust to preserve the previous fallback behavior.
        var solutionClonerClass = annotation.solutionCloner();

@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2025

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
69.6% Coverage on New Code (required ≥ 70%)

See analysis details on SonarQube Cloud

@triceo triceo merged commit d2b2406 into TimefoldAI:main Jul 7, 2025
42 of 43 checks passed
@triceo triceo deleted the sonar branch July 7, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants