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 183df801558..8838253d0df 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
@@ -105,11 +105,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
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-image-multi-module/app/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-image-multi-module/app/src/main/java/org/test/SampleApplication.java
index a2ad26ea716..a09b075b1c2 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-image-multi-module/app/src/main/java/org/test/SampleApplication.java
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-image-multi-module/app/src/main/java/org/test/SampleApplication.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors.
+ * Copyright 2012-2021 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.
diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/java/com/example/JettyServerCustomizerConfig.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/java/com/example/JettyServerCustomizerConfig.java
index f927f9b410c..2c934be6b48 100644
--- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/java/com/example/JettyServerCustomizerConfig.java
+++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/java/com/example/JettyServerCustomizerConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 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.