sharanggupta opened a new pull request, #660:
URL: https://github.com/apache/commons-configuration/pull/660

   Fixes 
[CONFIGURATION-859](https://issues.apache.org/jira/browse/CONFIGURATION-859).
   
   **What**
   
   Since the cycle detection of #634, a map or list referenced several times 
through YAML aliases is only loaded the first time. `constructHierarchy()` 
records every map and collection in one visited set for the whole document, so 
each later reference to the same object is skipped as if it were a cycle:
   
   ```yaml
   connections:
     primary: &writer
       - host: writer.example.com
     direct: *writer      # connections.direct.host is null
   ```
   
   **How**
   
   - The set now holds the maps and collections on the path from the root to 
the current element: an element is added before its children are processed and 
removed afterwards. Only an element that contains itself, such as `root: &cycle 
[*cycle]` from `cycle.yaml`, is skipped, and a shared but acyclic alias is 
loaded at every reference, as in 2.12.0.
   - Elements are compared by identity through `Collections.newSetFromMap(new 
IdentityHashMap<>())` instead of by `System.identityHashCode()`, which is not 
unique and could make two distinct elements look like the same one.
   
   #637 also switches to an identity-based set and adds a warning for a 
detected cycle. With the set as it is today, that warning would also be logged 
for every repeated alias. This change keeps the warning-free behaviour, and I'm 
happy to rebase on #637, or the other way round, whichever you prefer.
   
   **Tests**
   
   `TestYAMLConfiguration.testSharedListAlias` and `testSharedMapAlias` 
reproduce the report with a list alias and a map alias; both fail on master 
(`expected: <writer.example.com> but was: <null>` and `Key 
'service1.settings.timeout' does not map to an existing object`) and pass with 
this change. `testCycle` still passes.
   
   The default Maven goal (`clean verify apache-rat:check japicmp:cmp 
checkstyle:check spotbugs:check pmd:check pmd:cpd-check javadoc:javadoc`) 
passes locally on Java 17.
   
   Before you push a pull request, review this list:
   
   - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
   - [x] Read the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use 
Artificial Intelligence (AI).
   - [x] I used AI to create any part of, or all of, this pull request. Which 
AI tool was used to create this pull request, and to what extent did it 
contribute? Claude (Anthropic) helped analyse the regression and draft the 
change and tests; I reviewed them against the code and ran the build.
   - [x] Run a successful build using the default 
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command 
line by itself.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied. This may not always be possible, 
but it is a best practice.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body. Note that a maintainer may squash commits during the merge process.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to