Deprecate NestedIOException

NestedIOException has been removed in Spring Framework 6 and this commit
marks it as deprecated in 5.x. Users that were relying on this exception
should use IOException directly.

Closes gh-28929
This commit is contained in:
Stephane Nicoll 2022-08-05 10:04:47 +02:00
parent 8685b2f5bf
commit 6685e78c36
7 changed files with 21 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-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.
@ -54,7 +54,6 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase;
import org.springframework.context.annotation.DeferredImportSelector.Group;
import org.springframework.core.NestedIOException;
import org.springframework.core.OrderComparator;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAttributes;
@ -680,6 +679,7 @@ class ConfigurationClassParser {
/**
* Factory method to obtain a {@link SourceClass} from a class name.
*/
@SuppressWarnings("deprecation")
SourceClass asSourceClass(@Nullable String className, Predicate<String> filter) throws IOException {
if (className == null || filter.test(className)) {
return this.objectSourceClass;
@ -690,7 +690,7 @@ class ConfigurationClassParser {
return new SourceClass(ClassUtils.forName(className, this.resourceLoader.getClassLoader()));
}
catch (ClassNotFoundException ex) {
throw new NestedIOException("Failed to load class [" + className + "]", ex);
throw new org.springframework.core.NestedIOException("Failed to load class [" + className + "]", ex);
}
}
return new SourceClass(this.metadataReaderFactory.getMetadataReader(className));
@ -1073,6 +1073,7 @@ class ConfigurationClassParser {
return result;
}
@SuppressWarnings("deprecation")
private SourceClass getRelated(String className) throws IOException {
if (this.source instanceof Class) {
try {
@ -1082,7 +1083,7 @@ class ConfigurationClassParser {
catch (ClassNotFoundException ex) {
// Ignore -> fall back to ASM next, except for core java types.
if (className.startsWith("java")) {
throw new NestedIOException("Failed to load class [" + className + "]", ex);
throw new org.springframework.core.NestedIOException("Failed to load class [" + className + "]", ex);
}
return new SourceClass(metadataReaderFactory.getMetadataReader(className));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-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.
@ -29,7 +29,6 @@ import org.springframework.lang.Nullable;
* @since 2.0
* @see NestedRuntimeException
* @see NestedCheckedException
* @see NestedIOException
* @see org.springframework.web.util.NestedServletException
*/
public abstract class NestedExceptionUtils {

View File

@ -37,7 +37,9 @@ import org.springframework.lang.Nullable;
* @see #printStackTrace
* @see org.springframework.core.NestedCheckedException
* @see org.springframework.core.NestedRuntimeException
* @deprecated as of 5.3.23, in favor of using {@link IOException} directly
*/
@Deprecated
@SuppressWarnings("serial")
public class NestedIOException extends IOException {

View File

@ -29,7 +29,6 @@ import java.nio.channels.ReadableByteChannel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.NestedIOException;
import org.springframework.lang.Nullable;
import org.springframework.util.ResourceUtils;
@ -119,13 +118,14 @@ public abstract class AbstractResource implements Resource {
* by {@link #getURL()}.
*/
@Override
@SuppressWarnings("deprecation")
public URI getURI() throws IOException {
URL url = getURL();
try {
return ResourceUtils.toURI(url);
}
catch (URISyntaxException ex) {
throw new NestedIOException("Invalid URI [" + url + "]", ex);
throw new org.springframework.core.NestedIOException("Invalid URI [" + url + "]", ex);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-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.
@ -22,7 +22,6 @@ import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import org.springframework.core.NestedIOException;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@ -72,22 +71,24 @@ public class VfsResource extends AbstractResource {
}
@Override
@SuppressWarnings("deprecation")
public URL getURL() throws IOException {
try {
return VfsUtils.getURL(this.resource);
}
catch (Exception ex) {
throw new NestedIOException("Failed to obtain URL for file " + this.resource, ex);
throw new org.springframework.core.NestedIOException("Failed to obtain URL for file " + this.resource, ex);
}
}
@Override
@SuppressWarnings("deprecation")
public URI getURI() throws IOException {
try {
return VfsUtils.getURI(this.resource);
}
catch (Exception ex) {
throw new NestedIOException("Failed to obtain URI for " + this.resource, ex);
throw new org.springframework.core.NestedIOException("Failed to obtain URI for " + this.resource, ex);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-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.
@ -21,7 +21,6 @@ import java.io.InputStream;
import java.io.ObjectInputStream;
import org.springframework.core.ConfigurableObjectInputStream;
import org.springframework.core.NestedIOException;
import org.springframework.lang.Nullable;
/**
@ -65,14 +64,14 @@ public class DefaultDeserializer implements Deserializer<Object> {
* @see ObjectInputStream#readObject()
*/
@Override
@SuppressWarnings("resource")
@SuppressWarnings("deprecation")
public Object deserialize(InputStream inputStream) throws IOException {
ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream, this.classLoader);
try {
return objectInputStream.readObject();
}
catch (ClassNotFoundException ex) {
throw new NestedIOException("Failed to deserialize object type", ex);
throw new org.springframework.core.NestedIOException("Failed to deserialize object type", ex);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-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.
@ -20,7 +20,6 @@ import java.io.IOException;
import java.io.InputStream;
import org.springframework.asm.ClassReader;
import org.springframework.core.NestedIOException;
import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
@ -51,13 +50,14 @@ final class SimpleMetadataReader implements MetadataReader {
this.annotationMetadata = visitor.getMetadata();
}
@SuppressWarnings("deprecation")
private static ClassReader getClassReader(Resource resource) throws IOException {
try (InputStream is = resource.getInputStream()) {
try {
return new ClassReader(is);
}
catch (IllegalArgumentException ex) {
throw new NestedIOException("ASM ClassReader failed to parse class file - " +
throw new org.springframework.core.NestedIOException("ASM ClassReader failed to parse class file - " +
"probably due to a new Java class file version that isn't supported yet: " + resource, ex);
}
}