Skip to content

Move circular reference handling from ResolverChain to NullableResolver #61

Description

@MessiasLima

Description

ResolverChain currently contains both circular-reference detection and circular-reference handling. The handleCircularReference method decides whether to return null or throw SomeCircularReferenceException based on NullableStrategy. This couples the core resolution chain with nullable-specific strategy behavior.

The goal is to simplify ResolverChain so it only detects circular references and always throws SomeCircularReferenceException. NullableResolver will then catch the exception when resolving non-null instances and decide whether to return null based on the active NullableStrategy.

  • Scope and constraints

    • ResolverChain must retain detectCircularReference and the resolution stack
    • ResolverChain must no longer receive NullableStrategy via its constructor
    • NullableResolver must handle SomeCircularReferenceException when resolving non-null values
    • Non-nullable circular references must still throw SomeCircularReferenceException
    • All existing tests must continue to pass
  • References

    • src/main/kotlin/dev/appoutlet/some/core/ResolverChain.kt
    • src/main/kotlin/dev/appoutlet/some/resolver/NullableResolver.kt
    • src/main/kotlin/dev/appoutlet/some/Some.kt

Scope

In scope:

  • Removing handleCircularReference and nullableStrategy from ResolverChain
  • Updating ResolverChain to always throw SomeCircularReferenceException on circular references
  • Updating NullableResolver to catch SomeCircularReferenceException and decide whether to return null or re-throw based on the active NullableStrategy
  • Updating Some.kt and TestHelpers.kt to stop passing NullableStrategy to ResolverChain

Out of scope:

  • Changing the behavior of NullableStrategy variants
  • Changing the circular-reference detection algorithm in ResolverChain

Acceptance criteria

  • ResolverChain no longer contains handleCircularReference method
  • ResolverChain no longer accepts nullableStrategy as a constructor parameter
  • ResolverChain throws SomeCircularReferenceException for all detected circular references
  • NullableResolver catches SomeCircularReferenceException when calling chain.resolve(nonNullType) and decides whether to return null or re-throw based on the active NullableStrategy
  • Some.kt and TestHelpers.kt no longer pass NullableStrategy to ResolverChain
  • All existing tests pass, including CircularReferenceIntegrationTest

Additional information

The current implementation short-circuits in ResolverChain.resolve() before resolvers are invoked when a circular reference is detected. After this refactor, ResolverChain should detect and throw for all circular references, while NullableResolver handles the exception when resolving non-null values for nullable types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status
    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions