8202719: Use Collections.emptyEnumeration where possible
authorredestad
Tue, 08 May 2018 09:57:45 +0200
changeset 50048 1c4fb292447c
parent 50047 edbb27451b4b
child 50049 9d17c375dc30
8202719: Use Collections.emptyEnumeration where possible Reviewed-by: martin, psandoz Contributed-by: christoph.dreis@freenet.de
src/java.base/share/classes/java/util/jar/JarFile.java
src/java.base/share/classes/java/util/jar/JarVerifier.java
--- a/src/java.base/share/classes/java/util/jar/JarFile.java	Tue May 08 09:52:18 2018 +0200
+++ b/src/java.base/share/classes/java/util/jar/JarFile.java	Tue May 08 09:57:45 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();
         }
     }
 
--- a/src/java.base/share/classes/java/util/jar/JarVerifier.java	Tue May 08 09:52:18 2018 +0200
+++ b/src/java.base/share/classes/java/util/jar/JarVerifier.java	Tue May 08 09:57:45 2018 +0200
@@ -684,7 +684,7 @@
         }
 
         final List<CodeSigner[]> signersReq = req;
-        final Enumeration<String> enum2 = (matchUnsigned) ? unsignedEntryNames(jar) : emptyEnumeration;
+        final Enumeration<String> enum2 = matchUnsigned ? unsignedEntryNames(jar) : Collections.emptyEnumeration();
 
         return new Enumeration<>() {
 
@@ -769,16 +769,6 @@
             }
         };
     }
-    private Enumeration<String> emptyEnumeration = new Enumeration<String>() {
-
-        public boolean hasMoreElements() {
-            return false;
-        }
-
-        public String nextElement() {
-            throw new NoSuchElementException();
-        }
-    };
 
     // true if file is part of the signature mechanism itself
     static boolean isSigningRelated(String name) {