RFR: 8202719: Use Collections.emptyEnumeration() where possible (original) (raw)
Martin Buchholz martinrb at google.com
Mon May 7 16:27:02 UTC 2018
- Previous message: RFR: 8202719: Use Collections.emptyEnumeration() where possible
- Next message: RFR: 8202719: Use Collections.emptyEnumeration() where possible
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
+1
On Mon, May 7, 2018 at 5:43 AM, Claes Redestad <claes.redestad at oracle.com> wrote:
Hi,
I'll sponsor this trivial contribution. Bug: https://bugs.openjdk.java.net/browse/JDK-8202719 Webrev: http://cr.openjdk.java.net/~redestad/8202719/open.00/ Thanks! /Claes On 2018-05-07 14:35, Claes Redestad wrote:
Hi, looks like a reasonable cleanup.
I would expect very few applications actually use these, but at the very least we'd save a few bytes of compiled bytecode. /Claes On 2018-05-06 17:19, Christoph Dreis wrote:
Hi,
I just noticed two places - namely in JarFile and JarVerifier - that could make use of Collections.emptyEnumeration(). Let me know what you think. I'd be happy if this is sponsored in case it's considered worthwile. Cheers, Christoph ============= PATCH ============== diff -r 7238cb613dc5 src/java.base/share/classes/ja va/util/jar/JarFile.java --- a/src/java.base/share/classes/java/util/jar/JarFile.java Sun May 06 00:42:59 2018 +0200 +++ b/src/java.base/share/classes/java/util/jar/JarFile.java Sun May 06 17:10:42 2018 +0200 @@ -42,6 +42,7 @@ import java.security.CodeSource; import java.security.cert.Certificate; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.List; import java.util.Locale; @@ -1095,16 +1096,7 @@ if (includeUnsigned) { return unsignedEntryNames(); } else { - return new Enumeration<>() { - - public boolean hasMoreElements() { - return false; - } - - public String nextElement() { - throw new NoSuchElementException(); - } - }; + return Collections.emptyEnumeration(); } } diff -r 7238cb613dc5 src/java.base/share/classes/java/util/jar/JarVerifier.java --- a/src/java.base/share/classes/java/util/jar/JarVerifier.java Sun May 06 00:42:59 2018 +0200 +++ b/src/java.base/share/classes/java/util/jar/JarVerifier.java Sun May 06 17:10:42 2018 +0200 @@ -684,7 +684,7 @@ } final List<CodeSigner[]> signersReq = req; - final Enumeration enum2 = (matchUnsigned) ? unsignedEntryNames(jar) : emptyEnumeration; + final Enumeration enum2 = matchUnsigned ? unsignedEntryNames(jar) : Collections.emptyEnumeration(); return new Enumeration<>() { @@ -769,16 +769,6 @@ } }; } - private Enumeration emptyEnumeration = new Enumeration() { - - public boolean hasMoreElements() { - return false; - } - - public String nextElement() { - throw new NoSuchElementException(); - } - };
- Previous message: RFR: 8202719: Use Collections.emptyEnumeration() where possible
- Next message: RFR: 8202719: Use Collections.emptyEnumeration() where possible
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]