This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git


The following commit(s) were added to refs/heads/master by this push:
     new f59447dd4 Must override toString() for Java 17
f59447dd4 is described below

commit f59447dd4ff348b0d232934aef88dfb86951ca83
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Jul 13 09:46:50 2023 -0400

    Must override toString() for Java 17
---
 .../collections4/properties/OrderedProperties.java | 25 ++++++++++++++++++++++
 .../properties/OrderedPropertiesTest.java          |  1 -
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/apache/commons/collections4/properties/OrderedProperties.java
 
b/src/main/java/org/apache/commons/collections4/properties/OrderedProperties.java
index 4cf0b9c6c..ffa9570bd 100644
--- 
a/src/main/java/org/apache/commons/collections4/properties/OrderedProperties.java
+++ 
b/src/main/java/org/apache/commons/collections4/properties/OrderedProperties.java
@@ -19,6 +19,7 @@ package org.apache.commons.collections4.properties;
 import java.util.AbstractMap.SimpleEntry;
 import java.util.Collections;
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Objects;
@@ -145,4 +146,28 @@ public class OrderedProperties extends Properties {
         }
         return remove;
     }
+
+    @Override
+    public synchronized String toString() {
+        // Must override for Java 17 to maintain order since the 
implementation is based on a map
+        final int max = size() - 1;
+        if (max == -1) {
+            return "{}";
+        }
+        final StringBuilder sb = new StringBuilder();
+        final Iterator<Map.Entry<Object, Object>> it = entrySet().iterator();
+        sb.append('{');
+        for (int i = 0;; i++) {
+            final Map.Entry<Object, Object> e = it.next();
+            final Object key = e.getKey();
+            final Object value = e.getValue();
+            sb.append(key == this ? "(this Map)" : key.toString());
+            sb.append('=');
+            sb.append(value == this ? "(this Map)" : value.toString());
+            if (i == max) {
+                return sb.append('}').toString();
+            }
+            sb.append(", ");
+        }
+    }
 }
diff --git 
a/src/test/java/org/apache/commons/collections4/properties/OrderedPropertiesTest.java
 
b/src/test/java/org/apache/commons/collections4/properties/OrderedPropertiesTest.java
index f0bb17875..127b3caaa 100644
--- 
a/src/test/java/org/apache/commons/collections4/properties/OrderedPropertiesTest.java
+++ 
b/src/test/java/org/apache/commons/collections4/properties/OrderedPropertiesTest.java
@@ -288,7 +288,6 @@ public class OrderedPropertiesTest {
         assertFalse(Collections.list(props.propertyNames()).contains(k));
     }
 
-    @Disabled("Fails on GHA?")
     @Test
     public void testToString() {
         final OrderedProperties orderedProperties = new OrderedProperties();

Reply via email to