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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase; import org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase;
import org.springframework.context.annotation.DeferredImportSelector.Group; import org.springframework.context.annotation.DeferredImportSelector.Group;
import org.springframework.core.NestedIOException;
import org.springframework.core.OrderComparator; import org.springframework.core.OrderComparator;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationAttributes;
@ -680,6 +679,7 @@ class ConfigurationClassParser {
/** /**
* Factory method to obtain a {@link SourceClass} from a class name. * Factory method to obtain a {@link SourceClass} from a class name.
*/ */
@SuppressWarnings("deprecation")
SourceClass asSourceClass(@Nullable String className, Predicate<String> filter) throws IOException { SourceClass asSourceClass(@Nullable String className, Predicate<String> filter) throws IOException {
if (className == null || filter.test(className)) { if (className == null || filter.test(className)) {
return this.objectSourceClass; return this.objectSourceClass;
@ -690,7 +690,7 @@ class ConfigurationClassParser {
return new SourceClass(ClassUtils.forName(className, this.resourceLoader.getClassLoader())); return new SourceClass(ClassUtils.forName(className, this.resourceLoader.getClassLoader()));
} }
catch (ClassNotFoundException ex) { 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)); return new SourceClass(this.metadataReaderFactory.getMetadataReader(className));
@ -1073,6 +1073,7 @@ class ConfigurationClassParser {
return result; return result;
} }
@SuppressWarnings("deprecation")
private SourceClass getRelated(String className) throws IOException { private SourceClass getRelated(String className) throws IOException {
if (this.source instanceof Class) { if (this.source instanceof Class) {
try { try {
@ -1082,7 +1083,7 @@ class ConfigurationClassParser {
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
// Ignore -> fall back to ASM next, except for core java types. // Ignore -> fall back to ASM next, except for core java types.
if (className.startsWith("java")) { 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)); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0
* @see NestedRuntimeException * @see NestedRuntimeException
* @see NestedCheckedException * @see NestedCheckedException
* @see NestedIOException
* @see org.springframework.web.util.NestedServletException * @see org.springframework.web.util.NestedServletException
*/ */
public abstract class NestedExceptionUtils { public abstract class NestedExceptionUtils {

View File

@ -37,7 +37,9 @@ import org.springframework.lang.Nullable;
* @see #printStackTrace * @see #printStackTrace
* @see org.springframework.core.NestedCheckedException * @see org.springframework.core.NestedCheckedException
* @see org.springframework.core.NestedRuntimeException * @see org.springframework.core.NestedRuntimeException
* @deprecated as of 5.3.23, in favor of using {@link IOException} directly
*/ */
@Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class NestedIOException extends IOException { 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.core.NestedIOException;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
@ -119,13 +118,14 @@ public abstract class AbstractResource implements Resource {
* by {@link #getURL()}. * by {@link #getURL()}.
*/ */
@Override @Override
@SuppressWarnings("deprecation")
public URI getURI() throws IOException { public URI getURI() throws IOException {
URL url = getURL(); URL url = getURL();
try { try {
return ResourceUtils.toURI(url); return ResourceUtils.toURI(url);
} }
catch (URISyntaxException ex) { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.URI;
import java.net.URL; import java.net.URL;
import org.springframework.core.NestedIOException;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -72,22 +71,24 @@ public class VfsResource extends AbstractResource {
} }
@Override @Override
@SuppressWarnings("deprecation")
public URL getURL() throws IOException { public URL getURL() throws IOException {
try { try {
return VfsUtils.getURL(this.resource); return VfsUtils.getURL(this.resource);
} }
catch (Exception ex) { 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 @Override
@SuppressWarnings("deprecation")
public URI getURI() throws IOException { public URI getURI() throws IOException {
try { try {
return VfsUtils.getURI(this.resource); return VfsUtils.getURI(this.resource);
} }
catch (Exception ex) { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 java.io.ObjectInputStream;
import org.springframework.core.ConfigurableObjectInputStream; import org.springframework.core.ConfigurableObjectInputStream;
import org.springframework.core.NestedIOException;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
/** /**
@ -65,14 +64,14 @@ public class DefaultDeserializer implements Deserializer<Object> {
* @see ObjectInputStream#readObject() * @see ObjectInputStream#readObject()
*/ */
@Override @Override
@SuppressWarnings("resource") @SuppressWarnings("deprecation")
public Object deserialize(InputStream inputStream) throws IOException { public Object deserialize(InputStream inputStream) throws IOException {
ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream, this.classLoader); ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream, this.classLoader);
try { try {
return objectInputStream.readObject(); return objectInputStream.readObject();
} }
catch (ClassNotFoundException ex) { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 java.io.InputStream;
import org.springframework.asm.ClassReader; import org.springframework.asm.ClassReader;
import org.springframework.core.NestedIOException;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata; import org.springframework.core.type.ClassMetadata;
@ -51,13 +50,14 @@ final class SimpleMetadataReader implements MetadataReader {
this.annotationMetadata = visitor.getMetadata(); this.annotationMetadata = visitor.getMetadata();
} }
@SuppressWarnings("deprecation")
private static ClassReader getClassReader(Resource resource) throws IOException { private static ClassReader getClassReader(Resource resource) throws IOException {
try (InputStream is = resource.getInputStream()) { try (InputStream is = resource.getInputStream()) {
try { try {
return new ClassReader(is); return new ClassReader(is);
} }
catch (IllegalArgumentException ex) { 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); "probably due to a new Java class file version that isn't supported yet: " + resource, ex);
} }
} }