Merge branch '2.7.x' into 3.0.x

This commit is contained in:
Phillip Webb
2023-02-21 23:15:40 -08:00
1890 changed files with 27173 additions and 21952 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 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.
@@ -44,8 +44,8 @@ class ClassPathIndexFileTests {
@Test
void loadIfPossibleWhenRootIsNotFileReturnsNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ClassPathIndexFile.loadIfPossible(new URL("https://example.com/file"), "test.idx"))
.withMessage("URL does not reference a file");
.isThrownBy(() -> ClassPathIndexFile.loadIfPossible(new URL("https://example.com/file"), "test.idx"))
.withMessage("URL does not reference a file");
}
@Test

View File

@@ -99,7 +99,7 @@ class PropertiesLauncherTests {
@SuppressWarnings("unchecked")
private void clearHandlerCache() throws Exception {
Map<File, JarFile> rootFileCache = ((SoftReference<Map<File, JarFile>>) ReflectionTestUtils
.getField(Handler.class, "rootFileCache")).get();
.getField(Handler.class, "rootFileCache")).get();
if (rootFileCache != null) {
for (JarFile rootJarFile : rootFileCache.values()) {
rootJarFile.close();
@@ -127,7 +127,8 @@ class PropertiesLauncherTests {
void testNonExistentHome() {
System.setProperty("loader.home", "src/test/resources/nonexistent");
assertThatIllegalStateException().isThrownBy(PropertiesLauncher::new)
.withMessageContaining("Invalid source directory").withCauseInstanceOf(IllegalArgumentException.class);
.withMessageContaining("Invalid source directory")
.withCauseInstanceOf(IllegalArgumentException.class);
}
@Test
@@ -194,7 +195,7 @@ class PropertiesLauncherTests {
System.setProperty("loader.path", "jar:file:./src/test/resources/nested-jars/app.jar!/");
this.launcher = new PropertiesLauncher();
assertThat(ReflectionTestUtils.getField(this.launcher, "paths"))
.hasToString("[jar:file:./src/test/resources/nested-jars/app.jar!/]");
.hasToString("[jar:file:./src/test/resources/nested-jars/app.jar!/]");
List<Archive> archives = new ArrayList<>();
this.launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
assertThat(archives).areExactly(1, endingWith("foo.jar!/"));
@@ -237,7 +238,7 @@ class PropertiesLauncherTests {
System.setProperty("loader.main", "demo.Application");
this.launcher = new PropertiesLauncher();
assertThat(ReflectionTestUtils.getField(this.launcher, "paths"))
.hasToString("[nested-jars/nested-jar-app.jar!/BOOT-INF/classes/]");
.hasToString("[nested-jars/nested-jar-app.jar!/BOOT-INF/classes/]");
this.launcher.launch(new String[0]);
waitFor("Hello World");
}
@@ -277,7 +278,7 @@ class PropertiesLauncherTests {
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
this.launcher = new PropertiesLauncher();
assertThat(ReflectionTestUtils.getField(this.launcher, "paths"))
.hasToString("[more-jars/app.jar, jars/app.jar]");
.hasToString("[more-jars/app.jar, jars/app.jar]");
this.launcher.launch(new String[0]);
waitFor("Hello Other World");
}
@@ -393,7 +394,7 @@ class PropertiesLauncherTests {
catch (Exception ex) {
// Expected ClassNotFoundException
LaunchedURLClassLoader classLoader = (LaunchedURLClassLoader) Thread.currentThread()
.getContextClassLoader();
.getContextClassLoader();
classLoader.close();
}
URL resource = new URL("jar:" + jarFile.toURI() + "!/nested.jar!/3.dat");

View File

@@ -136,7 +136,7 @@ class JarFileArchiveTests {
setup(true);
try (Archive nestedArchive = this.archive.getNestedArchive(getEntriesMap(this.archive).get("nested.jar"));
Archive anotherNestedArchive = this.archive
.getNestedArchive(getEntriesMap(this.archive).get("another-nested.jar"))) {
.getNestedArchive(getEntriesMap(this.archive).get("another-nested.jar"))) {
File nested = new File(nestedArchive.getUrl().toURI());
File anotherNested = new File(anotherNestedArchive.getUrl().toURI());
assertThat(nested).hasParent(anotherNested.getParent());

View File

@@ -79,14 +79,14 @@ class RandomAccessDataFileTests {
@Test
void fileNotNull() {
assertThatIllegalArgumentException().isThrownBy(() -> new RandomAccessDataFile(null))
.withMessageContaining("File must not be null");
.withMessageContaining("File must not be null");
}
@Test
void fileExists() {
File file = new File("/does/not/exist");
assertThatIllegalArgumentException().isThrownBy(() -> new RandomAccessDataFile(file))
.withMessageContaining(String.format("File %s must exist", file.getAbsolutePath()));
.withMessageContaining(String.format("File %s must exist", file.getAbsolutePath()));
}
@Test
@@ -127,13 +127,13 @@ class RandomAccessDataFileTests {
@Test
void inputStreamReadNullBytes() {
assertThatNullPointerException().isThrownBy(() -> this.inputStream.read(null))
.withMessage("Bytes must not be null");
.withMessage("Bytes must not be null");
}
@Test
void inputStreamReadNullBytesWithOffset() {
assertThatNullPointerException().isThrownBy(() -> this.inputStream.read(null, 0, 1))
.withMessage("Bytes must not be null");
.withMessage("Bytes must not be null");
}
@Test
@@ -286,7 +286,7 @@ class RandomAccessDataFileTests {
for (int i = 0; i < 100; i++) {
results.add(executorService.submit(() -> {
InputStream subsectionInputStream = RandomAccessDataFileTests.this.file.getSubsection(0, 256)
.getInputStream();
.getInputStream();
byte[] b = new byte[256];
subsectionInputStream.read(b);
return Arrays.equals(b, BYTES);

View File

@@ -96,32 +96,36 @@ class HandlerTests {
@Test
void sameFileReturnsFalseForDifferentFileInSameJar() throws MalformedURLException {
assertThat(this.handler.sameFile(new URL("jar:file:foo.jar!/the/path/to/the/first/content.txt"),
new URL("jar:file:/foo.jar!/content.txt"))).isFalse();
new URL("jar:file:/foo.jar!/content.txt")))
.isFalse();
}
@Test
void sameFileReturnsFalseForSameFileInDifferentJars() throws MalformedURLException {
assertThat(this.handler.sameFile(new URL("jar:file:/the/path/to/the/first.jar!/content.txt"),
new URL("jar:file:/second.jar!/content.txt"))).isFalse();
new URL("jar:file:/second.jar!/content.txt")))
.isFalse();
}
@Test
void sameFileReturnsTrueForSameFileInSameJar() throws MalformedURLException {
assertThat(this.handler.sameFile(new URL("jar:file:/the/path/to/the/first.jar!/content.txt"),
new URL("jar:file:/the/path/to/the/first.jar!/content.txt"))).isTrue();
new URL("jar:file:/the/path/to/the/first.jar!/content.txt")))
.isTrue();
}
@Test
void sameFileReturnsTrueForUrlsThatReferenceSameFileViaNestedArchiveAndFromRootOfJar()
throws MalformedURLException {
assertThat(this.handler.sameFile(new URL("jar:file:/test.jar!/BOOT-INF/classes!/foo.txt"),
new URL("jar:file:/test.jar!/BOOT-INF/classes/foo.txt"))).isTrue();
new URL("jar:file:/test.jar!/BOOT-INF/classes/foo.txt")))
.isTrue();
}
@Test
void hashCodesAreEqualForUrlsThatReferenceSameFileViaNestedArchiveAndFromRootOfJar() throws MalformedURLException {
assertThat(this.handler.hashCode(new URL("jar:file:/test.jar!/BOOT-INF/classes!/foo.txt")))
.isEqualTo(this.handler.hashCode(new URL("jar:file:/test.jar!/BOOT-INF/classes/foo.txt")));
.isEqualTo(this.handler.hashCode(new URL("jar:file:/test.jar!/BOOT-INF/classes/foo.txt")));
}
@Test
@@ -157,11 +161,12 @@ class HandlerTests {
File testJar = new File(tempDir, "test.jar");
TestJarCreator.createTestJar(testJar);
URLConnection connection = new URL(null, "jar:" + testJar.toURI().toURL() + "!/nested.jar!/", this.handler)
.openConnection();
.openConnection();
assertThat(connection).isInstanceOf(JarURLConnection.class);
((JarURLConnection) connection).getJarFile().close();
URLConnection jdkConnection = new URL(null, "jar:file:" + testJar.toURI().toURL() + "!/nested.jar!/",
this.handler).openConnection();
this.handler)
.openConnection();
assertThat(jdkConnection).isNotInstanceOf(JarURLConnection.class);
assertThat(jdkConnection.getClass().getName()).endsWith(".JarURLConnection");
}

View File

@@ -234,7 +234,7 @@ class JarFileTests {
void getEntryTime() throws Exception {
java.util.jar.JarFile jdkJarFile = new java.util.jar.JarFile(this.rootJarFile);
assertThat(this.jarFile.getEntry("META-INF/MANIFEST.MF").getTime())
.isEqualTo(jdkJarFile.getEntry("META-INF/MANIFEST.MF").getTime());
.isEqualTo(jdkJarFile.getEntry("META-INF/MANIFEST.MF").getTime());
jdkJarFile.close();
}
@@ -280,7 +280,7 @@ class JarFileTests {
URL url = new URL(this.jarFile.getUrl(), "missing.dat");
assertThat(url).hasToString("jar:" + this.rootJarFile.toURI() + "!/missing.dat");
assertThatExceptionOfType(FileNotFoundException.class)
.isThrownBy(((JarURLConnection) url.openConnection())::getJarEntry);
.isThrownBy(((JarURLConnection) url.openConnection())::getJarEntry);
}
@Test
@@ -442,9 +442,9 @@ class JarFileTests {
StreamUtils.drain(expected.getInputStream(expectedEntry));
if (!actualEntry.getName().equals("META-INF/MANIFEST.MF")) {
assertThat(actualEntry.getCertificates()).as(actualEntry.getName())
.isEqualTo(expectedEntry.getCertificates());
.isEqualTo(expectedEntry.getCertificates());
assertThat(actualEntry.getCodeSigners()).as(actualEntry.getName())
.isEqualTo(expectedEntry.getCodeSigners());
.isEqualTo(expectedEntry.getCodeSigners());
}
}
assertThat(stopWatch.getTotalTimeSeconds()).isLessThan(3.0);
@@ -542,10 +542,11 @@ class JarFileTests {
try (JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))) {
URL context = nested.getUrl();
new URL(context, "jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat").openConnection()
.getInputStream().close();
.getInputStream()
.close();
assertThatExceptionOfType(FileNotFoundException.class)
.isThrownBy(new URL(context, "jar:" + this.rootJarFile.toURI() + "!/no.dat")
.openConnection()::getInputStream);
.isThrownBy(new URL(context, "jar:" + this.rootJarFile.toURI() + "!/no.dat")
.openConnection()::getInputStream);
}
}
finally {
@@ -630,7 +631,7 @@ class JarFileTests {
}
try (JarFile outerJarFile = new JarFile(outer)) {
try (JarFile nestedZip64JarFile = outerJarFile
.getNestedJarFile(outerJarFile.getJarEntry("nested-zip64.jar"))) {
.getNestedJarFile(outerJarFile.getJarEntry("nested-zip64.jar"))) {
List<JarEntry> entries = Collections.list(nestedZip64JarFile.entries());
assertThat(entries).hasSize(65537);
for (int i = 0; i < entries.size(); i++) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@@ -148,7 +148,7 @@ class JarFileWrapperTests {
// of additional memory being used since cleanup only occurs when the
// finalizer thread runs. See gh-22991
assertThatExceptionOfType(NoSuchMethodException.class)
.isThrownBy(() -> JarFileWrapper.class.getDeclaredMethod("close"));
.isThrownBy(() -> JarFileWrapper.class.getDeclaredMethod("close"));
}
@Test

View File

@@ -173,7 +173,7 @@ class JarURLConnectionTests {
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/w.jar!/3.dat");
try (JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))) {
assertThatExceptionOfType(FileNotFoundException.class)
.isThrownBy(JarURLConnection.get(url, nested)::getInputStream);
.isThrownBy(JarURLConnection.get(url, nested)::getInputStream);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 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.
@@ -45,7 +45,7 @@ class JarUrlProtocolHandler implements BeforeEachCallback, AfterEachCallback {
@SuppressWarnings("unchecked")
public void afterEach(ExtensionContext context) throws Exception {
Map<File, JarFile> rootFileCache = ((SoftReference<Map<File, JarFile>>) ReflectionTestUtils
.getField(Handler.class, "rootFileCache")).get();
.getField(Handler.class, "rootFileCache")).get();
if (rootFileCache != null) {
for (JarFile rootJarFile : rootFileCache.values()) {
rootJarFile.close();

View File

@@ -32,25 +32,25 @@ class StringSequenceTests {
@Test
void createWhenSourceIsNullShouldThrowException() {
assertThatNullPointerException().isThrownBy(() -> new StringSequence(null))
.withMessage("Source must not be null");
.withMessage("Source must not be null");
}
@Test
void createWithIndexWhenSourceIsNullShouldThrowException() {
assertThatNullPointerException().isThrownBy(() -> new StringSequence(null, 0, 0))
.withMessage("Source must not be null");
.withMessage("Source must not be null");
}
@Test
void createWhenStartIsLessThanZeroShouldThrowException() {
assertThatExceptionOfType(StringIndexOutOfBoundsException.class)
.isThrownBy(() -> new StringSequence("x", -1, 0));
.isThrownBy(() -> new StringSequence("x", -1, 0));
}
@Test
void createWhenEndIsGreaterThanLengthShouldThrowException() {
assertThatExceptionOfType(StringIndexOutOfBoundsException.class)
.isThrownBy(() -> new StringSequence("x", 0, 2));
.isThrownBy(() -> new StringSequence("x", 0, 2));
}
@Test