diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java index f604f493c73..0ebb8b0fe26 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java @@ -106,11 +106,15 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter { } catch (Exception ex) { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); - record(timingContext, request, response, (ex instanceof NestedServletException) ? ex.getCause() : ex); + record(timingContext, request, response, unwrapNestedServletException(ex)); throw ex; } } + private Throwable unwrapNestedServletException(Throwable ex) { + return (ex instanceof NestedServletException) ? ex.getCause() : ex; + } + private TimingContext startAndAttachTimingContext(HttpServletRequest request) { Timer.Sample timerSample = Timer.start(this.registry); TimingContext timingContext = new TimingContext(timerSample); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileEntries.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileEntries.java index edc79133077..ac272101246 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileEntries.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileEntries.java @@ -34,9 +34,9 @@ import org.springframework.boot.loader.data.RandomAccessData; /** * Provides access to entries from a {@link JarFile}. In order to reduce memory - * consumption entry details are stored using int arrays. The {@code hashCodes} array - * stores the hash code of the entry name, the {@code centralDirectoryOffsets} provides - * the offset to the central directory record and {@code positions} provides the original + * consumption entry details are stored using arrays. The {@code hashCodes} array stores + * the hash code of the entry name, the {@code centralDirectoryOffsets} provides the + * offset to the central directory record and {@code positions} provides the original * order position of the entry. The arrays are stored in hashCode order so that a binary * search can be used to find a name. *

@@ -120,7 +120,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable { int maxSize = endRecord.getNumberOfRecords(); this.centralDirectoryData = centralDirectoryData; this.hashCodes = new int[maxSize]; - this.centralDirectoryOffsets = Offsets.of(endRecord); + this.centralDirectoryOffsets = Offsets.get(endRecord); this.positions = new int[maxSize]; } @@ -187,12 +187,6 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable { swap(this.positions, i, j); } - private static void swap(int[] array, int i, int j) { - int temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } - @Override public Iterator iterator() { return new EntryIterator(NO_VALIDATION); @@ -388,6 +382,18 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable { return -1; } + private static void swap(int[] array, int i, int j) { + int temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + + private static void swap(long[] array, int i, int j) { + long temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + /** * Iterator for contained entries. */ @@ -421,6 +427,11 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable { } + /** + * Interface to manage offsets to central directory records. Regular zip files are + * backed by an {@code int[]} based implementation, Zip64 files are backed by a + * {@code long[]} and will consume more memory. + */ private interface Offsets { void set(int index, long value); @@ -429,13 +440,16 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable { void swap(int i, int j); - static Offsets of(CentralDirectoryEndRecord endRecord) { - return endRecord.isZip64() ? new Zip64Offsets(endRecord.getNumberOfRecords()) - : new ZipOffsets(endRecord.getNumberOfRecords()); + static Offsets get(CentralDirectoryEndRecord endRecord) { + int size = endRecord.getNumberOfRecords(); + return endRecord.isZip64() ? new Zip64Offsets(size) : new ZipOffsets(size); } } + /** + * {@link Offsets} implementation for regular zip files. + */ private static final class ZipOffsets implements Offsets { private final int[] offsets; @@ -461,6 +475,9 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable { } + /** + * {@link Offsets} implementation for zip64 files. + */ private static final class Zip64Offsets implements Offsets { private final long[] offsets; @@ -471,9 +488,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable { @Override public void swap(int i, int j) { - long temp = this.offsets[i]; - this.offsets[i] = this.offsets[j]; - this.offsets[j] = temp; + JarFileEntries.swap(this.offsets, i, j); } @Override