From a4876c2a6f7743b9d3d069e9a37ef896601082f2 Mon Sep 17 00:00:00 2001
From: Joshua Barr
+ * {@code
* int[] ints = new int[] {1, 2, 3, 4};
* IonList list = SYSTEM.newList(ints);
* IonSexp sexp = SYSTEM.newSexp(ints)
@@ -444,7 +444,7 @@ public void add(int index, IonValue child)
* List dgrmSubList = sexp.subList(0, ints.size())
* List arrayList = new ArrayList();
* for(int i : ints) { arrayList.add(SYSTEM.newInt(i)); }
- *
+ * }
*
* {@link IonSequence#equals(Object)} always returns false when presented
* with a non {@link IonSequence} instance of {@link List
+ * {@code
* list.equals(listSubList) // false
* list.equals(sexpSubList) // false
* list.equals(dgrm) // false
@@ -472,7 +472,7 @@ public void add(int index, IonValue child)
* dgrm.equals(sexpSubList) // false
* dgrm.equals(dgrmSubList) // false
* dgrm.equals(arrayList) // false
- *
+ * }
*
* However, {@link IonSequence#subList(int, int)} was implemented much
* later and faithfully implements {@link List#equals(Object)} meaning
@@ -483,7 +483,7 @@ public void add(int index, IonValue child)
* no notion of an {@link IonType}, annotations or nullability which
* allows for compliance with the {@link List} specification.
*
- *
+ * {@code
* listSubList.equals(listSubList); // true
* listSubList.equals(sexpSubList); // true
* listSubList.equals(dgrmSubList); // true
@@ -504,7 +504,7 @@ public void add(int index, IonValue child)
* dgrmSubList.equals(list); // true
* dgrmSubList.equals(sexp); // true
* dgrmSubList.equals(arrayList); // true
- *
+ * }
*
* @see List#subList(int, int)
*/
@@ -566,4 +566,60 @@ public void add(int index, IonValue child)
public IonSequence clone()
throws UnknownSymbolException;
+
+ /**
+ * The existing implementation of {@link IonSequence} does not
+ * provide a specification-compliant {@link List#equals} and
+ * {@link List#hashCode()}. If you want a symmetric {@code equals} then
+ * use a {@link IonSequence#subList(int, int)} view of the sequence.
+ * + * The non-compliant {@code equals} implementation of {@link IonSequence} + * results to the following caveats: + *
+ * Given: + * + *
{@code
+ * int[] ints = new int[] {1, 2, 3, 4};
+ * IonList list = SYSTEM.newList(ints);
+ * IonSexp sexp = SYSTEM.newSexp(ints)
+ * IonSexp dgrm = SYSTEM.newDatagram(ints)
+ * List listSubList = list.subList(0, ints.size())
+ * List sexpSubList = sexp.subList(0, ints.size())
+ * List dgrmSubList = sexp.subList(0, ints.size())
+ * List arrayList = new ArrayList();
+ * for(int i : ints) { arrayList.add(SYSTEM.newInt(i)); }
+ * }
+ *
+ * {@link IonSequence#equals(Object)} always returns false when presented
+ * with a non {@link IonSequence} instance of {@link List {@code
+ * list.equals(listSubList) // false
+ * list.equals(sexpSubList) // false
+ * list.equals(dgrm) // false
+ * list.equals(arrayList) // false
+ *
+ * sexp.equals(listSubList) // false
+ * sexp.equals(sexpSubList) // false
+ * sexp.equals(dgrm) // false
+ * sexp.equals(arrayList) // false
+ *
+ * dgrm.equals(listSubList) // false
+ * dgrm.equals(sexpSubList) // false
+ * dgrm.equals(dgrmSubList) // false
+ * dgrm.equals(arrayList) // false
+ * }
+ *
+ * @param other the object to be compared for equality with this list
+ * @return {@code true} if the specified object is equal to this list
+ */
+ boolean equals(Object other);
}
From c6f123501dc47ff44179a17f55d1d42fc0abac14 Mon Sep 17 00:00:00 2001
From: Joshua Barr <70981087+jobarr-amzn@users.noreply.github.com>
Date: Thu, 16 Oct 2025 09:16:41 -0700
Subject: [PATCH 2/4] Update src/main/java/com/amazon/ion/IonSequence.java
Co-authored-by: Austin Williams {@code
* list.equals(listSubList) // false
* list.equals(sexpSubList) // false
- * list.equals(dgrm) // false
+ * list.equals(dgrmSubList) // false
* list.equals(arrayList) // false
*
* sexp.equals(listSubList) // false
* sexp.equals(sexpSubList) // false
- * sexp.equals(dgrm) // false
+ * sexp.equals(dgrmSubList) // false
* sexp.equals(arrayList) // false
*
* dgrm.equals(listSubList) // false
From 0026d0aee76fca80d7180e5b68722dc89d59dbec Mon Sep 17 00:00:00 2001
From: Joshua Barr <70981087+jobarr-amzn@users.noreply.github.com>
Date: Thu, 16 Oct 2025 09:59:55 -0700
Subject: [PATCH 4/4] Update src/main/java/com/amazon/ion/IonSequence.java
Co-authored-by: Austin Williams
---
src/main/java/com/amazon/ion/IonSequence.java | 39 ++++++++++---------
1 file changed, 20 insertions(+), 19 deletions(-)
diff --git a/src/main/java/com/amazon/ion/IonSequence.java b/src/main/java/com/amazon/ion/IonSequence.java
index e322566eed..a2fc70d400 100644
--- a/src/main/java/com/amazon/ion/IonSequence.java
+++ b/src/main/java/com/amazon/ion/IonSequence.java
@@ -581,11 +581,12 @@ public IonSequence clone()
* {@code
* int[] ints = new int[] {1, 2, 3, 4};
* IonList list = SYSTEM.newList(ints);
- * IonSexp sexp = SYSTEM.newSexp(ints)
- * IonDatagram dgrm = SYSTEM.newDatagram(ints)
- * List listSubList = list.subList(0, ints.size())
- * List sexpSubList = sexp.subList(0, ints.size())
- * List dgrmSubList = dgrm.subList(0, ints.size())
+ * IonSexp sexp = SYSTEM.newSexp(ints);
+ * IonDatagram dgrm = SYSTEM.newDatagram();
+ * for(int i : ints) { dgrm.add(SYSTEM.newInt(i)); };
+ * List listSubList = list.subList(0, ints.length);
+ * List sexpSubList = sexp.subList(0, ints.length);
+ * List dgrmSubList = dgrm.subList(0, ints.length);
* List arrayList = new ArrayList();
* for(int i : ints) { arrayList.add(SYSTEM.newInt(i)); }
* }
@@ -602,20 +603,20 @@ public IonSequence clone()
* as-is.
*
* {@code
- * list.equals(listSubList) // false
- * list.equals(sexpSubList) // false
- * list.equals(dgrmSubList) // false
- * list.equals(arrayList) // false
- *
- * sexp.equals(listSubList) // false
- * sexp.equals(sexpSubList) // false
- * sexp.equals(dgrmSubList) // false
- * sexp.equals(arrayList) // false
- *
- * dgrm.equals(listSubList) // false
- * dgrm.equals(sexpSubList) // false
- * dgrm.equals(dgrmSubList) // false
- * dgrm.equals(arrayList) // false
+ * list.equals(listSubList); // false
+ * list.equals(sexpSubList); // false
+ * list.equals(dgrmSubList); // false
+ * list.equals(arrayList); // false
+ *
+ * sexp.equals(listSubList); // false
+ * sexp.equals(sexpSubList); // false
+ * sexp.equals(dgrmSubList); // false
+ * sexp.equals(arrayList); // false
+ *
+ * dgrm.equals(listSubList); // false
+ * dgrm.equals(sexpSubList); // false
+ * dgrm.equals(dgrmSubList); // false
+ * dgrm.equals(arrayList); // false
* }
*
* @param other the object to be compared for equality with this list