Use pattern matching for instanceof where appropriate

See gh-31475
This commit is contained in:
dreis2211
2022-06-20 18:14:16 +02:00
committed by Andy Wilkinson
parent a7b98e7312
commit 5db04da275
278 changed files with 1049 additions and 1126 deletions

View File

@@ -213,8 +213,8 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
}
private Object extractValue(Object value) {
if (value instanceof DeclaredType) {
return Elements.getQualifiedName(((DeclaredType) value).asElement());
if (value instanceof DeclaredType declaredType) {
return Elements.getQualifiedName(declaredType.asElement());
}
return value;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -38,19 +38,18 @@ final class Elements {
return getQualifiedName(enclosingElement) + "$"
+ ((DeclaredType) element.asType()).asElement().getSimpleName().toString();
}
if (element instanceof TypeElement) {
return ((TypeElement) element).getQualifiedName().toString();
if (element instanceof TypeElement typeElement) {
return typeElement.getQualifiedName().toString();
}
}
return null;
}
private static TypeElement getEnclosingTypeElement(TypeMirror type) {
if (type instanceof DeclaredType) {
DeclaredType declaredType = (DeclaredType) type;
if (type instanceof DeclaredType declaredType) {
Element enclosingElement = declaredType.asElement().getEnclosingElement();
if (enclosingElement instanceof TypeElement) {
return (TypeElement) enclosingElement;
if (enclosingElement instanceof TypeElement typeElement) {
return typeElement;
}
}
return null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -39,10 +39,9 @@ public final class Binding {
if (this == obj) {
return true;
}
if (!(obj instanceof Binding)) {
if (!(obj instanceof Binding binding)) {
return false;
}
Binding binding = (Binding) obj;
return Objects.equals(this.value, binding.value);
}

View File

@@ -55,11 +55,11 @@ public class InspectedContent implements Content {
@Override
public void writeTo(OutputStream outputStream) throws IOException {
if (this.content instanceof byte[]) {
FileCopyUtils.copy((byte[]) this.content, outputStream);
if (this.content instanceof byte[] bytes) {
FileCopyUtils.copy(bytes, outputStream);
}
else if (this.content instanceof File) {
InputStream inputStream = new FileInputStream((File) this.content);
else if (this.content instanceof File file) {
InputStream inputStream = new FileInputStream(file);
FileCopyUtils.copy(inputStream, outputStream);
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -48,11 +48,11 @@ class JsonReader {
return new RawConfigurationMetadata(groups, items, hints);
}
catch (Exception ex) {
if (ex instanceof IOException) {
throw (IOException) ex;
if (ex instanceof IOException ioException) {
throw ioException;
}
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
if (ex instanceof RuntimeException runtimeException) {
throw runtimeException;
}
throw new IllegalStateException(ex);
}
@@ -185,8 +185,7 @@ class JsonReader {
}
private Object readItemValue(Object value) throws Exception {
if (value instanceof JSONArray) {
JSONArray array = (JSONArray) value;
if (value instanceof JSONArray array) {
Object[] content = new Object[array.length()];
for (int i = 0; i < array.length(); i++) {
content[i] = array.get(i);

View File

@@ -212,11 +212,11 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
AnnotationMirror annotation = this.metadataEnv.getConfigurationPropertiesAnnotation(element);
if (annotation != null) {
String prefix = getPrefix(annotation);
if (element instanceof TypeElement) {
processAnnotatedTypeElement(prefix, (TypeElement) element, new Stack<>());
if (element instanceof TypeElement typeElement) {
processAnnotatedTypeElement(prefix, typeElement, new Stack<>());
}
else if (element instanceof ExecutableElement) {
processExecutableElement(prefix, (ExecutableElement) element, new Stack<>());
else if (element instanceof ExecutableElement executableElement) {
processExecutableElement(prefix, executableElement, new Stack<>());
}
}
}
@@ -235,7 +235,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
if ((!element.getModifiers().contains(Modifier.PRIVATE))
&& (TypeKind.VOID != element.getReturnType().getKind())) {
Element returns = this.processingEnv.getTypeUtils().asElement(element.getReturnType());
if (returns instanceof TypeElement) {
if (returns instanceof TypeElement typeElement) {
ItemMetadata group = ItemMetadata.newGroup(prefix,
this.metadataEnv.getTypeUtils().getQualifiedName(returns),
this.metadataEnv.getTypeUtils().getQualifiedName(element.getEnclosingElement()),
@@ -246,7 +246,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
}
else {
this.metadataCollector.add(group);
processTypeElement(prefix, (TypeElement) returns, element, seen);
processTypeElement(prefix, typeElement, element, seen);
}
}
}
@@ -273,8 +273,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
try {
String annotationName = this.metadataEnv.getTypeUtils().getQualifiedName(annotations.get(0));
AnnotationMirror annotation = this.metadataEnv.getAnnotation(element, annotationName);
if (element instanceof TypeElement) {
processEndpoint(annotation, (TypeElement) element);
if (element instanceof TypeElement typeElement) {
processEndpoint(annotation, typeElement);
}
}
catch (Exception ex) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -284,8 +284,7 @@ class TypeUtils {
public String visitTypeVariable(TypeVariable t, TypeDescriptor descriptor) {
TypeMirror typeMirror = descriptor.resolveGeneric(t);
if (typeMirror != null) {
if (typeMirror instanceof TypeVariable) {
TypeVariable typeVariable = (TypeVariable) typeMirror;
if (typeMirror instanceof TypeVariable typeVariable) {
// Still unresolved, let's use the upper bound, checking first if
// a cycle may exist
if (!hasCycle(typeVariable)) {
@@ -302,9 +301,8 @@ class TypeUtils {
private boolean hasCycle(TypeVariable variable) {
TypeMirror upperBound = variable.getUpperBound();
if (upperBound instanceof DeclaredType) {
return ((DeclaredType) upperBound).getTypeArguments().stream()
.anyMatch((candidate) -> candidate.equals(variable));
if (upperBound instanceof DeclaredType declaredType) {
return declaredType.getTypeArguments().stream().anyMatch((candidate) -> candidate.equals(variable));
}
return false;
}
@@ -333,18 +331,17 @@ class TypeUtils {
return getQualifiedName(enclosingElement) + "$"
+ ((DeclaredType) element.asType()).asElement().getSimpleName();
}
if (element instanceof TypeElement) {
return ((TypeElement) element).getQualifiedName().toString();
if (element instanceof TypeElement typeElement) {
return typeElement.getQualifiedName().toString();
}
throw new IllegalStateException("Could not extract qualified name from " + element);
}
private TypeElement getEnclosingTypeElement(TypeMirror type) {
if (type instanceof DeclaredType) {
DeclaredType declaredType = (DeclaredType) type;
if (type instanceof DeclaredType declaredType) {
Element enclosingElement = declaredType.asElement().getEnclosingElement();
if (enclosingElement instanceof TypeElement) {
return (TypeElement) enclosingElement;
if (enclosingElement instanceof TypeElement typeElement) {
return typeElement;
}
}
return null;
@@ -373,8 +370,7 @@ class TypeUtils {
}
private void registerIfNecessary(TypeMirror variable, TypeMirror resolution) {
if (variable instanceof TypeVariable) {
TypeVariable typeVariable = (TypeVariable) variable;
if (variable instanceof TypeVariable typeVariable) {
if (this.generics.keySet().stream()
.noneMatch((candidate) -> getParameterName(candidate).equals(getParameterName(typeVariable)))) {
this.generics.put(typeVariable, resolution);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -52,11 +52,11 @@ public class JsonMarshaller {
outputStream.write(object.toString(2).getBytes(StandardCharsets.UTF_8));
}
catch (Exception ex) {
if (ex instanceof IOException) {
throw (IOException) ex;
if (ex instanceof IOException ioException) {
throw ioException;
}
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
if (ex instanceof RuntimeException runtimeException) {
throw runtimeException;
}
throw new IllegalStateException(ex);
}
@@ -150,8 +150,7 @@ public class JsonMarshaller {
}
private Object readItemValue(Object value) throws Exception {
if (value instanceof JSONArray) {
JSONArray array = (JSONArray) value;
if (value instanceof JSONArray array) {
Object[] content = new Object[array.length()];
for (int i = 0; i < array.length(); i++) {
content[i] = array.get(i);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -126,9 +126,9 @@ public abstract class AbstractFieldValuesProcessorTests {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement annotation : annotations) {
for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
if (element instanceof TypeElement) {
if (element instanceof TypeElement typeElement) {
try {
this.values.putAll(this.processor.getFieldValues((TypeElement) element));
this.values.putAll(this.processor.getFieldValues(typeElement));
}
catch (Exception ex) {
throw new IllegalStateException(ex);

View File

@@ -264,10 +264,9 @@ final class JavaPluginAction implements PluginApplicationAction {
@Override
public void execute(Task task) {
if (!(task instanceof JavaCompile)) {
if (!(task instanceof JavaCompile compile)) {
return;
}
JavaCompile compile = (JavaCompile) task;
if (hasConfigurationProcessorOnClasspath(compile)) {
configureAdditionalMetadataLocations(compile);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -49,8 +49,8 @@ public final class VersionExtractor {
URL codeSourceLocation = cls.getProtectionDomain().getCodeSource().getLocation();
try {
URLConnection connection = codeSourceLocation.openConnection();
if (connection instanceof JarURLConnection) {
return getImplementationVersion(((JarURLConnection) connection).getJarFile());
if (connection instanceof JarURLConnection jarURLConnection) {
return getImplementationVersion(jarURLConnection.getJarFile());
}
try (JarFile jarFile = new JarFile(new File(codeSourceLocation.toURI()))) {
return getImplementationVersion(jarFile);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -88,8 +88,8 @@ class Context {
private static File findSource(URL location) throws IOException, URISyntaxException {
URLConnection connection = location.openConnection();
if (connection instanceof JarURLConnection) {
return getRootJarFile(((JarURLConnection) connection).getJarFile());
if (connection instanceof JarURLConnection jarURLConnection) {
return getRootJarFile(jarURLConnection.getJarFile());
}
return new File(location.toURI());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -113,8 +113,8 @@ public class DefaultLaunchScript implements LaunchScript {
}
private String parseFilePropertyValue(Object propertyValue) throws IOException {
if (propertyValue instanceof File) {
return loadContent((File) propertyValue);
if (propertyValue instanceof File file) {
return loadContent(file);
}
return loadContent(new File(propertyValue.toString()));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -99,8 +99,8 @@ public class JarWriter extends AbstractJarWriter implements AutoCloseable {
}
private JarArchiveEntry asJarArchiveEntry(ZipEntry entry) throws ZipException {
if (entry instanceof JarArchiveEntry) {
return (JarArchiveEntry) entry;
if (entry instanceof JarArchiveEntry jarArchiveEntry) {
return jarArchiveEntry;
}
return new JarArchiveEntry(entry);
}

View File

@@ -205,8 +205,8 @@ public abstract class Packager {
private void writeLoaderClasses(AbstractJarWriter writer) throws IOException {
Layout layout = getLayout();
if (layout instanceof CustomLoaderLayout) {
((CustomLoaderLayout) getLayout()).writeLoadedClasses(writer);
if (layout instanceof CustomLoaderLayout customLoaderLayout) {
customLoaderLayout.writeLoadedClasses(writer);
}
else if (layout.isExecutable()) {
writer.writeLoaderClasses();
@@ -223,8 +223,8 @@ public abstract class Packager {
}
private EntryTransformer getEntityTransformer() {
if (getLayout() instanceof RepackagingLayout) {
return new RepackagingEntryTransformer((RepackagingLayout) getLayout());
if (getLayout() instanceof RepackagingLayout repackagingLayout) {
return new RepackagingEntryTransformer(repackagingLayout);
}
return EntryTransformer.NONE;
}
@@ -349,8 +349,8 @@ public abstract class Packager {
private void addBootAttributesForLayout(Attributes attributes) {
Layout layout = getLayout();
if (layout instanceof RepackagingLayout) {
attributes.putValue(BOOT_CLASSES_ATTRIBUTE, ((RepackagingLayout) layout).getRepackagedClassesLocation());
if (layout instanceof RepackagingLayout repackagingLayout) {
attributes.putValue(BOOT_CLASSES_ATTRIBUTE, repackagingLayout.getRepackagedClassesLocation());
}
else {
attributes.putValue(BOOT_CLASSES_ATTRIBUTE, layout.getClassesLocation());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -60,8 +60,8 @@ final class SizeCalculatingEntryWriter implements EntryWriter {
}
private InputStream getContentInputStream() throws FileNotFoundException {
if (this.content instanceof File) {
return new FileInputStream((File) this.content);
if (this.content instanceof File file) {
return new FileInputStream(file);
}
return new ByteArrayInputStream((byte[]) this.content);
}
@@ -110,8 +110,8 @@ final class SizeCalculatingEntryWriter implements EntryWriter {
@Override
public void write(byte[] b, int off, int len) throws IOException {
int updatedSize = this.size + len;
if (updatedSize > THRESHOLD && this.outputStream instanceof ByteArrayOutputStream) {
this.outputStream = convertToFileOutputStream((ByteArrayOutputStream) this.outputStream);
if (updatedSize > THRESHOLD && this.outputStream instanceof ByteArrayOutputStream byteArrayOutputStream) {
this.outputStream = convertToFileOutputStream(byteArrayOutputStream);
}
this.outputStream.write(b, off, len);
this.size = updatedSize;
@@ -137,8 +137,8 @@ final class SizeCalculatingEntryWriter implements EntryWriter {
}
Object getContent() {
return (this.outputStream instanceof ByteArrayOutputStream)
? ((ByteArrayOutputStream) this.outputStream).toByteArray() : this.tempFile;
return (this.outputStream instanceof ByteArrayOutputStream byteArrayOutputStream)
? byteArrayOutputStream.toByteArray() : this.tempFile;
}
int getSize() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -217,8 +217,8 @@ public class LaunchedURLClassLoader extends URLClassLoader {
for (URL url : getURLs()) {
try {
URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
JarFile jarFile = ((JarURLConnection) connection).getJarFile();
if (connection instanceof JarURLConnection jarURLConnection) {
JarFile jarFile = jarURLConnection.getJarFile();
if (jarFile.getEntry(classEntryName) != null && jarFile.getEntry(packageEntryName) != null
&& jarFile.getManifest() != null) {
definePackage(packageName, jarFile.getManifest(), url);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -269,8 +269,8 @@ public class PropertiesLauncher extends Launcher {
}
catch (IOException ex) {
// Close the HTTP connection (if applicable).
if (con instanceof HttpURLConnection) {
((HttpURLConnection) con).disconnect();
if (con instanceof HttpURLConnection httpURLConnection) {
httpURLConnection.disconnect();
}
throw ex;
}
@@ -283,8 +283,7 @@ public class PropertiesLauncher extends Launcher {
URLConnection connection = url.openConnection();
try {
connection.setUseCaches(connection.getClass().getSimpleName().startsWith("JNLP"));
if (connection instanceof HttpURLConnection) {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
if (connection instanceof HttpURLConnection httpConnection) {
httpConnection.setRequestMethod("HEAD");
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
@@ -297,8 +296,8 @@ public class PropertiesLauncher extends Launcher {
return (connection.getContentLength() >= 0);
}
finally {
if (connection instanceof HttpURLConnection) {
((HttpURLConnection) connection).disconnect();
if (connection instanceof HttpURLConnection httpURLConnection) {
httpURLConnection.disconnect();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -109,13 +109,13 @@ public class Handler extends URLStreamHandler {
return (connection != null) ? connection : openFallbackHandlerConnection(url);
}
catch (Exception ex) {
if (reason instanceof IOException) {
if (reason instanceof IOException ioException) {
log(false, "Unable to open fallback handler", ex);
throw (IOException) reason;
throw ioException;
}
log(true, "Unable to open fallback handler", ex);
if (reason instanceof RuntimeException) {
throw (RuntimeException) reason;
if (reason instanceof RuntimeException runtimeException) {
throw runtimeException;
}
throw new IllegalStateException(reason);
}

View File

@@ -278,8 +278,8 @@ public class JarFile extends AbstractJarFile implements Iterable<java.util.jar.J
@Override
public synchronized InputStream getInputStream(ZipEntry entry) throws IOException {
ensureOpen();
if (entry instanceof JarEntry) {
return this.entries.getInputStream((JarEntry) entry);
if (entry instanceof JarEntry jarEntry) {
return this.entries.getInputStream(jarEntry);
}
return getInputStream((entry != null) ? entry.getName() : null);
}

View File

@@ -229,7 +229,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
T entry = doGetEntry(name, type, cacheEntry, null);
if (!isMetaInfEntry(name) && isMultiReleaseJar()) {
int version = RUNTIME_VERSION;
AsciiBytes nameAlias = (entry instanceof JarEntry) ? ((JarEntry) entry).getAsciiBytesName()
AsciiBytes nameAlias = (entry instanceof JarEntry jarEntry) ? jarEntry.getAsciiBytesName()
: new AsciiBytes(name.toString());
while (version > BASE_VERSION) {
T versionedEntry = doGetEntry("META-INF/versions/" + version + "/" + name, type, cacheEntry, nameAlias);

View File

@@ -113,11 +113,11 @@ class JarFileWrapper extends AbstractJarFile {
}
static JarFile unwrap(java.util.jar.JarFile jarFile) {
if (jarFile instanceof JarFile) {
return (JarFile) jarFile;
if (jarFile instanceof JarFile file) {
return file;
}
if (jarFile instanceof JarFileWrapper) {
return unwrap(((JarFileWrapper) jarFile).parent);
if (jarFile instanceof JarFileWrapper wrapper) {
return unwrap(wrapper.parent);
}
throw new IllegalStateException("Not a JarFile or Wrapper");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -120,10 +120,9 @@ final class StringSequence implements CharSequence {
if (this == obj) {
return true;
}
if (!(obj instanceof CharSequence)) {
if (!(obj instanceof CharSequence other)) {
return false;
}
CharSequence other = (CharSequence) obj;
int n = length();
if (n != other.length()) {
return false;

View File

@@ -108,8 +108,8 @@ class CustomLayersProvider {
NodeList children = element.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child instanceof Element) {
ContentSelector<T> selector = selectorFactory.apply((Element) child);
if (child instanceof Element childElement) {
ContentSelector<T> selector = selectorFactory.apply(childElement);
selectors.add(selector);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -59,8 +59,7 @@ class JavaCompilerPluginConfiguration {
Plugin plugin = this.project.getPlugin("org.apache.maven.plugins:maven-compiler-plugin");
if (plugin != null) {
Object pluginConfiguration = plugin.getConfiguration();
if (pluginConfiguration instanceof Xpp3Dom) {
Xpp3Dom dom = (Xpp3Dom) pluginConfiguration;
if (pluginConfiguration instanceof Xpp3Dom dom) {
return getNodeValue(dom, propertyName);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -48,8 +48,8 @@ final class VersionExtractor {
URL codeSourceLocation = cls.getProtectionDomain().getCodeSource().getLocation();
try {
URLConnection connection = codeSourceLocation.openConnection();
if (connection instanceof JarURLConnection) {
return getImplementationVersion(((JarURLConnection) connection).getJarFile());
if (connection instanceof JarURLConnection jarURLConnection) {
return getImplementationVersion(jarURLConnection.getJarFile());
}
try (JarFile jarFile = new JarFile(new File(codeSourceLocation.toURI()))) {
return getImplementationVersion(jarFile);

View File

@@ -115,8 +115,8 @@ final class ModifiedClassPathClassLoader extends URLClassLoader {
}
private static Stream<URL> doExtractUrls(ClassLoader classLoader) {
if (classLoader instanceof URLClassLoader) {
return Stream.of(((URLClassLoader) classLoader).getURLs());
if (classLoader instanceof URLClassLoader urlClassLoader) {
return Stream.of(urlClassLoader.getURLs());
}
return Stream.of(ManagementFactory.getRuntimeMXBean().getClassPath().split(File.pathSeparator))
.map(ModifiedClassPathClassLoader::toURL);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -193,8 +193,8 @@ class OutputCapture implements CapturedOutput {
}
private static PrintStream getSystemStream(PrintStream printStream) {
while (printStream instanceof PrintStreamCapture) {
printStream = ((PrintStreamCapture) printStream).getParent();
while (printStream instanceof PrintStreamCapture printStreamCapture) {
printStream = printStreamCapture.getParent();
}
return printStream;
}