From e0d1cf0e3898f5a3e918c3be2dd7efab27b11e79 Mon Sep 17 00:00:00 2001 From: Konrado85 <63104554+Konrado85@users.noreply.github.com> Date: Wed, 8 Apr 2020 17:44:23 +0200 Subject: [PATCH 1/2] Polish JarFile to extra anonymous inner class See gh-20882 --- .../boot/loader/jar/JarFile.java | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java index 26d62978eb4..2bd4816c69d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java @@ -192,19 +192,7 @@ public class JarFile extends java.util.jar.JarFile { @Override public Enumeration entries() { final Iterator iterator = this.entries.iterator(); - return new Enumeration() { - - @Override - public boolean hasMoreElements() { - return iterator.hasNext(); - } - - @Override - public java.util.jar.JarEntry nextElement() { - return iterator.next(); - } - - }; + return new EnumerationJarEntry(iterator); } public JarEntry getJarEntry(CharSequence name) { @@ -421,4 +409,33 @@ public class JarFile extends java.util.jar.JarFile { } + /** + * The type Enumeration jar entry. + */ + static class EnumerationJarEntry implements Enumeration { + + /** + * The Iterator. + */ + Iterator iterator; + + /** + * Instantiates a new Enumeration jar entry. + * + * @param iterator the iterator + */ + EnumerationJarEntry(Iterator iterator) { + this.iterator = iterator; + } + + @Override + public boolean hasMoreElements() { + return this.iterator.hasNext(); + } + + @Override + public java.util.jar.JarEntry nextElement() { + return this.iterator.next(); + } + } } From 1dd8dcc6c9e72f64cb66662c5fa43ba749ec0bfd Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 15 Apr 2020 09:39:00 +0200 Subject: [PATCH 2/2] Polish "Polish JarFile to extra anonymous inner class" See gh-20882 --- .../boot/loader/jar/JarFile.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java index 2bd4816c69d..ecdb31ef6fc 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -191,8 +191,7 @@ public class JarFile extends java.util.jar.JarFile { @Override public Enumeration entries() { - final Iterator iterator = this.entries.iterator(); - return new EnumerationJarEntry(iterator); + return new JarEntryEnumeration(this.entries.iterator()); } public JarEntry getJarEntry(CharSequence name) { @@ -410,21 +409,13 @@ public class JarFile extends java.util.jar.JarFile { } /** - * The type Enumeration jar entry. + * An {@link Enumeration} on {@linkplain java.util.jar.JarEntry jar entries}. */ - static class EnumerationJarEntry implements Enumeration { - - /** - * The Iterator. - */ - Iterator iterator; - - /** - * Instantiates a new Enumeration jar entry. - * - * @param iterator the iterator - */ - EnumerationJarEntry(Iterator iterator) { + private static class JarEntryEnumeration implements Enumeration { + + private final Iterator iterator; + + JarEntryEnumeration(Iterator iterator) { this.iterator = iterator; } @@ -437,5 +428,7 @@ public class JarFile extends java.util.jar.JarFile { public java.util.jar.JarEntry nextElement() { return this.iterator.next(); } + } + }