Add comprehensive test case and analysis for FELIX-6724 circular dependency detection #5
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.
Overview
This PR adds a comprehensive test case to investigate and document the circular dependency detection behavior reported in FELIX-6724 and FELIX-6069, which describe scenarios where circular dependencies may be incorrectly reported.
Test Implementation
Created four test scenarios covering different circular dependency patterns:
Scenario 1: True Circular Dependency (Control)
Tests the baseline case where all dependencies are mandatory (A → B → C → A, all 1..1 cardinality). This verifies that genuine circular dependencies are correctly detected and prevented.
Scenario 2: Optional Dependency Chain (Immediate)
Tests the case where the circular chain includes an optional dependency (A → B → C → A, where C → A is 0..n). Components use immediate activation. This scenario demonstrates whether the system can resolve circular patterns when optional dependencies are involved.
Scenario 3: Optional Dependency Chain (Delayed)
Same as Scenario 2 but with delayed component activation, testing whether activation timing affects circular dependency resolution.
Scenario 4: Static Binding Policy
Tests whether the binding policy (static vs dynamic) affects circular dependency detection when optional dependencies are present.
Test Results
All 4 test scenarios pass, demonstrating that the current Felix SCR implementation:
✅ Correctly detects true circular dependencies (Scenario 1)
✅ Correctly resolves circular patterns with optional dependencies (Scenarios 2-4)
✅ Handles both immediate and delayed activation correctly
✅ Works with both static and dynamic binding policies
How It Works
The circular dependency detection uses a
ThreadLocal<List<ServiceReference<?>>>stack inComponentRegistry.javato track service creation. When the sameServiceReferenceappears twice in the call stack, a circular dependency is detected.Why optional dependencies work:
Documentation
Added comprehensive documentation:
Files Changed
Test Code:
Felix6724Test.java- Integration test class with 4 scenariosServiceA.java,ServiceB.java,ServiceC.java- Test componentsintegration_test_FELIX_6724.xml- Component descriptorsComponentTestBase.java- Added felix6724 package exportDocumentation:
Next Steps
While these tests demonstrate that basic circular dependency scenarios work correctly, the reported JIRA issues may involve more complex edge cases such as:
To fully address FELIX-6724 and FELIX-6069, the actual JIRA issue descriptions and attached reproducers should be reviewed to identify any specific scenarios not covered by these tests.
Testing
mvn clean verify -Dit.test=Felix6724Test # Result: Tests run: 4, Failures: 0, Errors: 0, Skipped: 0All license checks pass:
mvn apache-rat:check # Result: Unapproved: 0, approved: 340 licensesOriginal prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.