However, the official Javadoc of HashMap and HashSet, which is internally used by the HashMap, mentions that the order or elements will not be maintained over time.
This causes issue where the URI String with params are expected to be in a specific order. Specifically, the following tests expects the order of params in the generated URI to be in their order of insertion.
However, this expected order might be changed based on the order of elements returned by param.entrySet(), which could result in the following error. To be concise, I have mentioned only one of the error logs.
**Expected behavior/code**
- For any amount of runs, the test should have passes successfully (with `NonDex` too).
- The expected order of params should be maintained over time.
**Environment**
- Core Components version: `2.23.5-SNAPSHOT`
- Java version: `Java(TM) SE Runtime Environment (build 1.8.0_381-b09)`
**Possible Solution**
- Since the order of elements is expected to be maintained, replacing the implementation of `params` from `HashMap` to `LinkedHashMap` will enforce the expected order.
Bug Report
Current Behavior
NextGenDMImageURIBuilder
builds the NextGen Dynamic Media Image URI with different parameters usingHashMap
at https://github.com/adobe/aem-core-wcm-components/blob/0efca91f4b7b5f56a02fefabbdec273c8b77ffd8/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v3/NextGenDMImageURIBuilder.java#L106 https://github.com/adobe/aem-core-wcm-components/blob/0efca91f4b7b5f56a02fefabbdec273c8b77ffd8/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v3/NextGenDMImageURIBuilder.java#L123-L131HashMap
, mentions that the order or elements will not be maintained over time.com.adobe.cq.wcm.core.components.internal.models.v3.NextgenDMImageURIBuilderTest#testUriWithDefaultValues
com.adobe.cq.wcm.core.components.internal.models.v3.NextgenDMImageURIBuilderTest#testUriWithInvalidSmartCrop
com.adobe.cq.wcm.core.components.internal.models.v3.ImageImplTest#testNgdmImage
com.adobe.cq.wcm.core.components.internal.models.v3.ImageImplTest#testNgdmImageWithResizeWidth
com.adobe.cq.wcm.core.components.internal.models.v2.TeaserImplTest#testTeaserWithNgdmImage
param.entrySet()
, which could result in the following error. To be concise, I have mentioned only one of the error logs.Steps to reproduce
params.entrySet()
Compile the module byte-buddy-dep
mvn clean install -pl bundles/core -am -DskipTests
(Optional) Run the unit test
mvn -pl bundles/core test -Dtest=
Run the unit test using NonDex
mvn -pl bundles/core edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=
+/- com.adobe.cq.wcm.core.components.internal.models.v3.NextGenDMImageURIBuilder.java: 106
Additional context / Screenshots
One of the order returned by
params.entrySet()
, which is the expected behaviorThe string built based on the above order
Another order returned by
params.entrySet()
, which is not expectedThe string built based on the above order