Skip to content

Commit

Permalink
Merge branch '2.4.x' into 2.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Sep 21, 2021
2 parents 4ee249c + dfd3667 commit 5ba6963
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,15 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
}
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

/**
* 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.
* <p>
Expand Down Expand Up @@ -120,7 +120,7 @@ public void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData cen
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];
}

Expand Down Expand Up @@ -187,12 +187,6 @@ private void swap(int i, int j) {
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<JarEntry> iterator() {
return new EntryIterator(NO_VALIDATION);
Expand Down Expand Up @@ -388,6 +382,18 @@ private int getEntryIndex(CharSequence name) {
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.
*/
Expand Down Expand Up @@ -421,6 +427,11 @@ public JarEntry next() {

}

/**
* 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);
Expand All @@ -429,13 +440,16 @@ private interface Offsets {

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;
Expand All @@ -461,6 +475,9 @@ public long get(int index) {

}

/**
* {@link Offsets} implementation for zip64 files.
*/
private static final class Zip64Offsets implements Offsets {

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

@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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 5ba6963

Please sign in to comment.