[PATCH] 8245694 : java.util.Properties.entrySet() does not override java.lang.Object methods

Julia Boes julia.boes at oracle.com
Mon Jul 20 12:17:59 UTC 2020


Hi Lisa,

I added a newline at the end of the test and ran the relevant test set, 
which came back all clear.

The change is pushed now.

Thanks,

Julia

On 19/07/2020 11:48, Lisa Li wrote:
> Hi Julia,
>
> Apologies for the delay. Please review the updated fix for JDK-8245694 
> <https://bugs.openjdk.java.net/browse/JDK-8245694>.  Also, my name is 
> on the contributor list as: Yu Li - OpenJDK - yuli.
>
>
> *BUG DESCRIPTION*:
>
> JDK-8245694 <https://bugs.openjdk.java.net/browse/JDK-8245694> : 
> java.util.Properties.entrySet() does not override java.lang.Object 
> methods since java 9.
>
>
> *PATCH*:
>
> # HG changeset patch
> # User yuli
> # Date 1595152648 -28800
> #      Sun Jul 19 17:57:28 2020 +0800
> # Node ID 4f359fdb3df3407cf8b31cb9ad153a99c52165c8
> # Parent  72bf0aca309e326f35cdc85cbdeb3076e4d4e74d
> 8245694: java.util.Properties.entrySet() does not override Object methods
> Summary: Add missing override methods
> Contributed-by: Yu Li <liyu.italy at gmail.com <mailto:liyu.italy at gmail.com>>
>
> diff -r 72bf0aca309e -r 4f359fdb3df3 
> src/java.base/share/classes/java/util/Properties.java
> --- a/src/java.base/share/classes/java/util/Properties.java Fri Jul 17 
> 17:27:31 2020 -0700
> +++ b/src/java.base/share/classes/java/util/Properties.java Sun Jul 19 
> 17:57:28 2020 +0800
> @@ -1405,6 +1405,21 @@
>          }
>
>          @Override
> +        public boolean equals(Object o) {
> +            return o == this || entrySet.equals(o);
> +        }
> +
> +        @Override
> +        public int hashCode() {
> +            return entrySet.hashCode();
> +        }
> +
> +        @Override
> +        public String toString() {
> +            return entrySet.toString();
> +        }
> +
> +        @Override
>          public boolean removeAll(Collection<?> c) {
>              return entrySet.removeAll(c);
>          }
> diff -r 72bf0aca309e -r 4f359fdb3df3 
> test/jdk/java/util/Properties/PropertiesEntrySetTest.java
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/test/jdk/java/util/Properties/PropertiesEntrySetTest.java Sun 
> Jul 19 17:57:28 2020 +0800
> @@ -0,0 +1,201 @@
> +/*
> + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
> + *
> + * This code is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License version 2 only, as
> + * published by the Free Software Foundation.
> + *
> + * This code is distributed in the hope that it will be useful, but 
> WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
> + * version 2 for more details (a copy is included in the LICENSE file 
> that
> + * accompanied this code).
> + *
> + * You should have received a copy of the GNU General Public License 
> version
> + * 2 along with this work; if not, write to the Free Software Foundation,
> + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
> + *
> + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 
> 94065 USA
> + * or visit www.oracle.com <http://www.oracle.com> if you need 
> additional information or have any
> + * questions.
> + */
> +
> +/*
> + * @test
> + * @bug        8245694
> + * @summary    tests the entrySet() method of Properties class
> + * @author     Yu Li
> + * @run testng PropertiesEntrySetTest
> + */
> +
> +import org.testng.annotations.Test;
> +
> +import java.util.Properties;
> +
> +import static org.testng.Assert.assertEquals;
> +import static org.testng.Assert.assertFalse;
> +import static org.testng.Assert.assertThrows;
> +import static org.testng.Assert.assertTrue;
> +
> +public class PropertiesEntrySetTest {
> +
> +    @Test
> +    public void testEquals() {
> +        Properties a = new Properties();
> +        var aEntrySet = a.entrySet();
> +        assertFalse(aEntrySet.equals(null));
> +        assertTrue(aEntrySet.equals(aEntrySet));
> +
> +        Properties b = new Properties();
> +        var bEntrySet = b.entrySet();
> +        assertTrue(bEntrySet.equals(aEntrySet));
> +        assertTrue(bEntrySet.hashCode() == aEntrySet.hashCode());
> +
> +        a.setProperty("p1", "1");
> +        assertFalse(bEntrySet.equals(aEntrySet));
> +        assertFalse(bEntrySet.hashCode() == aEntrySet.hashCode());
> +
> +        b.setProperty("p1", "1");
> +        assertTrue(aEntrySet.equals(bEntrySet));
> +        assertTrue(bEntrySet.hashCode() == aEntrySet.hashCode());
> +
> +        Properties c = new Properties();
> +        c.setProperty("p1", "2");
> +        var cEntrySet = c.entrySet();
> +        assertFalse(cEntrySet.equals(bEntrySet));
> +        assertFalse(bEntrySet.hashCode() == cEntrySet.hashCode());
> +        assertFalse(cEntrySet.equals(aEntrySet));
> +        assertFalse(aEntrySet.hashCode() == cEntrySet.hashCode());
> +
> +        a.setProperty("p2", "2");
> +        Properties d = new Properties();
> +        d.setProperty("p2", "2");
> +        d.setProperty("p1", "1");
> +        var dEntrySet = d.entrySet();
> +        assertTrue(dEntrySet.equals(aEntrySet));
> +        assertTrue(aEntrySet.hashCode() == dEntrySet.hashCode());
> +
> +        a.remove("p1");
> +        assertFalse(aEntrySet.equals(dEntrySet));
> +        assertFalse(aEntrySet.hashCode() == dEntrySet.hashCode());
> +
> +        d.remove("p1", "1");
> +        assertTrue(dEntrySet.equals(aEntrySet));
> +        assertTrue(aEntrySet.hashCode() == dEntrySet.hashCode());
> +
> +        a.clear();
> +        assertFalse(aEntrySet.equals(dEntrySet));
> +        assertFalse(aEntrySet.hashCode() == dEntrySet.hashCode());
> +        assertTrue(aEntrySet.isEmpty());
> +
> +        d.clear();
> +        assertTrue(dEntrySet.equals(aEntrySet));
> +        assertTrue(aEntrySet.hashCode() == dEntrySet.hashCode());
> +        assertTrue(dEntrySet.isEmpty());
> +    }
> +
> +    @Test
> +    public void testToString() {
> +        Properties a = new Properties();
> +        var aEntrySet = a.entrySet();
> +        assertEquals(aEntrySet.toString(), "[]");
> +
> +        a.setProperty("p1", "1");
> +        assertEquals(aEntrySet.toString(), "[p1=1]");
> +
> +        a.setProperty("p2", "2");
> +        assertEquals(aEntrySet.size(), 2);
> +  assertTrue(aEntrySet.toString().trim().startsWith("["));
> +        assertTrue(aEntrySet.toString().contains("p1=1"));
> +        assertTrue(aEntrySet.toString().contains("p2=2"));
> +  assertTrue(aEntrySet.toString().trim().endsWith("]"));
> +
> +        Properties b = new Properties();
> +        b.setProperty("p2", "2");
> +        b.setProperty("p1", "1");
> +        var bEntrySet = b.entrySet();
> +        assertEquals(bEntrySet.size(), 2);
> +  assertTrue(bEntrySet.toString().trim().startsWith("["));
> +        assertTrue(bEntrySet.toString().contains("p1=1"));
> +        assertTrue(bEntrySet.toString().contains("p2=2"));
> +  assertTrue(bEntrySet.toString().trim().endsWith("]"));
> +
> +        b.setProperty("p0", "0");
> +        assertEquals(bEntrySet.size(), 3);
> +        assertTrue(bEntrySet.toString().contains("p0=0"));
> +
> +        b.remove("p1");
> +        assertEquals(bEntrySet.size(), 2);
> +        assertFalse(bEntrySet.toString().contains("p1=1"));
> +  assertTrue(bEntrySet.toString().trim().startsWith("["));
> +        assertTrue(bEntrySet.toString().contains("p0=0"));
> +        assertTrue(bEntrySet.toString().contains("p2=2"));
> +  assertTrue(bEntrySet.toString().trim().endsWith("]"));
> +
> +        b.remove("p0", "0");
> +        assertEquals(bEntrySet.size(), 1);
> +        assertFalse(bEntrySet.toString().contains("p0=0"));
> +  assertTrue(bEntrySet.toString().trim().startsWith("["));
> +        assertTrue(bEntrySet.toString().contains("p2=2"));
> +  assertTrue(bEntrySet.toString().trim().endsWith("]"));
> +
> +        b.clear();
> +        assertTrue(bEntrySet.isEmpty());
> +        assertTrue(bEntrySet.toString().equals("[]"));
> +    }
> +
> +    @Test
> +    public void testEntrySetWithoutException() {
> +        Properties a = new Properties();
> +        a.setProperty("p1", "1");
> +        a.setProperty("p2", "2");
> +        var aEntrySet = a.entrySet();
> +        assertEquals(aEntrySet.size(), 2);
> +
> +        var i = aEntrySet.iterator();
> +        var e1 = i.next();
> +        i.remove();
> +        assertFalse(aEntrySet.contains(e1));
> +        assertEquals(aEntrySet.size(), 1);
> +
> +        var e2 = i.next();
> +        aEntrySet.remove(e2);
> +        assertFalse(aEntrySet.contains(e2));
> +        assertTrue(aEntrySet.isEmpty());
> +
> +        a.setProperty("p1", "1");
> +        a.setProperty("p3", "3");
> +        Properties b = new Properties();
> +        b.setProperty("p2", "2");
> +        b.setProperty("p1", "1");
> +        var bEntrySet = b.entrySet();
> +
> +        assertFalse(bEntrySet.containsAll(aEntrySet));
> +        assertEquals(bEntrySet.size(), 2);
> +
> +        assertTrue(bEntrySet.removeAll(aEntrySet));
> +        assertEquals(bEntrySet.size(), 1);
> +
> +        assertTrue(bEntrySet.retainAll(aEntrySet));
> +        assertTrue(bEntrySet.isEmpty());
> +        assertEquals(aEntrySet.size(), 2);
> +
> +        aEntrySet.clear();
> +        assertTrue(aEntrySet.isEmpty());
> +    }
> +
> +    @Test
> +    public void testEntrySetExceptionWhenAdd() {
> +        Properties a = new Properties();
> +        a.setProperty("p1", "1");
> +        var aEntrySet = a.entrySet();
> +
> +        Properties b = new Properties();
> +        b.setProperty("p2", "2");
> +        var bEntrySet = b.entrySet();
> +
> +        assertThrows(UnsupportedOperationException.class, () -> 
> aEntrySet.addAll(bEntrySet));
> +        assertThrows(UnsupportedOperationException.class, () -> 
> aEntrySet.add(bEntrySet.iterator().next()));
> +    }
> +}
> \ No newline at end of file
>
> Best regards,
> Yu L.
>
>
> On Tue, Jun 23, 2020 at 12:32 AM Lisa Li <liyu.italy at gmail.com 
> <mailto:liyu.italy at gmail.com>> wrote:
>
>     Great, thanks Julia!
>
>     Best regards,
>      Yu L.
>
>     On Mon, Jun 22, 2020 at 9:56 PM Julia Boes <julia.boes at oracle.com
>     <mailto:julia.boes at oracle.com>> wrote:
>
>         Hi Yu,
>
>>         Just to confirm, for
>>         src/java.base/share/classes/java/util/Properties.java the
>>         copyright should be updated as :
>>
>>         + * Copyright (c) 1995, 2020, Oracle and/or its affiliates.
>>         All rights
>>
>>         Because 1995 was the year when the file was added, while 2020
>>         when this change is made. Correct me if I'm wrong.
>
>         That's right!
>
>         Cheers,
>
>         Julia
>
>


More information about the core-libs-dev mailing list