Merge pull request #127 from raboof/fix-deterministic-extra-dependency-attributes

fix: make module attribute string encoding deterministic
This commit is contained in:
Stefan Bodewig 2026-07-10 05:52:44 +00:00 committed by GitHub
commit 9bba2ae9ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -20,6 +20,7 @@ package org.apache.ivy.core.module.id;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.WeakHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -259,7 +260,7 @@ public class ModuleRevisionId extends UnmodifiableExtendableItem {
public String encodeToString() {
StringBuilder buf = new StringBuilder();
Map<String, String> attributes = new HashMap<>(getAttributes());
Map<String, String> attributes = new TreeMap<>(getAttributes());
attributes.keySet().removeAll(getExtraAttributes().keySet());
attributes.putAll(getQualifiedExtraAttributes());

View File

@ -85,6 +85,12 @@ public class ModuleRevisionIdTest {
extraAttributes.put("nullatt", null);
testEncodeDecodeToString(
ModuleRevisionId.newInstance("org/apache", "pre/name", "1.0-dev8/2", extraAttributes));
String encoded = ModuleRevisionId.newInstance("org/apache", "pre/name", "1.0-dev8/2", extraAttributes).encodeToString();
// We expect the encoding/ordering to be stable for reproducibility.
// If necessary this may vary across Ivy versions,
// but ideally only intentionally.
assertEquals("+att.name:#@#:+att.value:#@#:+att/name:#@#:+att/value:#@#:+att<name:#@#:+att<value:#@#:+branch:#@#:+@#:NULL:#@:#@#:+extra:#@#:+extravalue:#@#:+module:#@#:+pre/name:#@#:+nullatt:#@#:+@#:NULL:#@:#@#:+organisation:#@#:+org/apache:#@#:+revision:#@#:+1.0-dev8/2:#@#:", encoded);
}
private void testEncodeDecodeToString(ModuleRevisionId mrid) {