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/java/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<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();
-        }
-    };


Reply via email to