Skip to content

Conversation

Copy link

Copilot AI commented Oct 20, 2025

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 in ComponentRegistry.java to track service creation. When the same ServiceReference appears twice in the call stack, a circular dependency is detected.

Why optional dependencies work:

  1. Components with only optional dependencies can activate without all dependencies satisfied
  2. This allows activation in the correct order: C (optional) → B → A
  3. After all components are active, optional bindings occur asynchronously
  4. No circular dependency is detected because services are never requested while already being created

Documentation

Added comprehensive documentation:

  • FELIX-6724-SUMMARY.md - Test results and key findings
  • FELIX-6724-ANALYSIS.md - Detailed analysis of the detection algorithm
  • FELIX-6724-MITIGATIONS.md - Potential improvement strategies for edge cases
  • components/felix6724/README.md - Test component documentation

Files Changed

Test Code:

  • Felix6724Test.java - Integration test class with 4 scenarios
  • ServiceA.java, ServiceB.java, ServiceC.java - Test components
  • integration_test_FELIX_6724.xml - Component descriptors
  • ComponentTestBase.java - Added felix6724 package export

Documentation:

  • 3 analysis documents and 1 README for the test components

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:

  • Factory components with circular dependencies
  • Multiple component instances with different configurations
  • Concurrent bundle activation scenarios
  • Complex service ranking and target filter scenarios

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: 0

All license checks pass:

mvn apache-rat:check
# Result: Unapproved: 0, approved: 340 licenses
Original prompt

Create a testcase an analyze the issue for FELIX-6724

https://issues.apache.org/jira/browse/FELIX-6724 describes a problem where incorectly a circular dependency problem is reported. A similar thing is reported as well in https://issues.apache.org/jira/browse/FELIX-6069 both have attached already some reproducer examples.

We need to create a testcase inside the felix-scr component that shows this behaviour in a unit test and explore possible mitigations for the problem


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI self-assigned this Oct 20, 2025
Copilot AI changed the title [WIP] Add testcase for circular dependency issue FELIX-6724 Add comprehensive test case and analysis for FELIX-6724 circular dependency detection Oct 20, 2025
Copilot AI requested a review from laeubi October 20, 2025 08:19
Copilot finished work on behalf of laeubi October 20, 2025 08:19
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.

2 participants