Skip to content

Commit cfeafee

Browse files
committed
Polish
1 parent 0a4d58f commit cfeafee

File tree

2 files changed

+36
-17
lines changed
  • spring-boot-project
    • spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet
    • spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar

2 files changed

+36
-17
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,15 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
106106
}
107107
catch (Exception ex) {
108108
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
109-
record(timingContext, request, response, (ex instanceof NestedServletException) ? ex.getCause() : ex);
109+
record(timingContext, request, response, unwrapNestedServletException(ex));
110110
throw ex;
111111
}
112112
}
113113

114+
private Throwable unwrapNestedServletException(Throwable ex) {
115+
return (ex instanceof NestedServletException) ? ex.getCause() : ex;
116+
}
117+
114118
private TimingContext startAndAttachTimingContext(HttpServletRequest request) {
115119
Timer.Sample timerSample = Timer.start(this.registry);
116120
TimingContext timingContext = new TimingContext(timerSample);

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileEntries.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434

3535
/**
3636
* Provides access to entries from a {@link JarFile}. In order to reduce memory
37-
* consumption entry details are stored using int arrays. The {@code hashCodes} array
38-
* stores the hash code of the entry name, the {@code centralDirectoryOffsets} provides
39-
* the offset to the central directory record and {@code positions} provides the original
37+
* consumption entry details are stored using arrays. The {@code hashCodes} array stores
38+
* the hash code of the entry name, the {@code centralDirectoryOffsets} provides the
39+
* offset to the central directory record and {@code positions} provides the original
4040
* order position of the entry. The arrays are stored in hashCode order so that a binary
4141
* search can be used to find a name.
4242
* <p>
@@ -120,7 +120,7 @@ public void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData cen
120120
int maxSize = endRecord.getNumberOfRecords();
121121
this.centralDirectoryData = centralDirectoryData;
122122
this.hashCodes = new int[maxSize];
123-
this.centralDirectoryOffsets = Offsets.of(endRecord);
123+
this.centralDirectoryOffsets = Offsets.get(endRecord);
124124
this.positions = new int[maxSize];
125125
}
126126

@@ -187,12 +187,6 @@ private void swap(int i, int j) {
187187
swap(this.positions, i, j);
188188
}
189189

190-
private static void swap(int[] array, int i, int j) {
191-
int temp = array[i];
192-
array[i] = array[j];
193-
array[j] = temp;
194-
}
195-
196190
@Override
197191
public Iterator<JarEntry> iterator() {
198192
return new EntryIterator(NO_VALIDATION);
@@ -388,6 +382,18 @@ private int getEntryIndex(CharSequence name) {
388382
return -1;
389383
}
390384

385+
private static void swap(int[] array, int i, int j) {
386+
int temp = array[i];
387+
array[i] = array[j];
388+
array[j] = temp;
389+
}
390+
391+
private static void swap(long[] array, int i, int j) {
392+
long temp = array[i];
393+
array[i] = array[j];
394+
array[j] = temp;
395+
}
396+
391397
/**
392398
* Iterator for contained entries.
393399
*/
@@ -421,6 +427,11 @@ public JarEntry next() {
421427

422428
}
423429

430+
/**
431+
* Interface to manage offsets to central directory records. Regular zip files are
432+
* backed by an {@code int[]} based implementation, Zip64 files are backed by a
433+
* {@code long[]} and will consume more memory.
434+
*/
424435
private interface Offsets {
425436

426437
void set(int index, long value);
@@ -429,13 +440,16 @@ private interface Offsets {
429440

430441
void swap(int i, int j);
431442

432-
static Offsets of(CentralDirectoryEndRecord endRecord) {
433-
return endRecord.isZip64() ? new Zip64Offsets(endRecord.getNumberOfRecords())
434-
: new ZipOffsets(endRecord.getNumberOfRecords());
443+
static Offsets get(CentralDirectoryEndRecord endRecord) {
444+
int size = endRecord.getNumberOfRecords();
445+
return endRecord.isZip64() ? new Zip64Offsets(size) : new ZipOffsets(size);
435446
}
436447

437448
}
438449

450+
/**
451+
* {@link Offsets} implementation for regular zip files.
452+
*/
439453
private static final class ZipOffsets implements Offsets {
440454

441455
private final int[] offsets;
@@ -461,6 +475,9 @@ public long get(int index) {
461475

462476
}
463477

478+
/**
479+
* {@link Offsets} implementation for zip64 files.
480+
*/
464481
private static final class Zip64Offsets implements Offsets {
465482

466483
private final long[] offsets;
@@ -471,9 +488,7 @@ private Zip64Offsets(int size) {
471488

472489
@Override
473490
public void swap(int i, int j) {
474-
long temp = this.offsets[i];
475-
this.offsets[i] = this.offsets[j];
476-
this.offsets[j] = temp;
491+
JarFileEntries.swap(this.offsets, i, j);
477492
}
478493

479494
@Override

0 commit comments

Comments
 (0)