From 6685e78c3679b8ec9f2bf06d59239e15f29b8524 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 5 Aug 2022 10:04:47 +0200 Subject: [PATCH] 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 --- .../context/annotation/ConfigurationClassParser.java | 9 +++++---- .../org/springframework/core/NestedExceptionUtils.java | 3 +-- .../java/org/springframework/core/NestedIOException.java | 2 ++ .../org/springframework/core/io/AbstractResource.java | 4 ++-- .../java/org/springframework/core/io/VfsResource.java | 9 +++++---- .../core/serializer/DefaultDeserializer.java | 7 +++---- .../core/type/classreading/SimpleMetadataReader.java | 6 +++--- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index 423078625f97..fe58c8f2d648 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -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.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 @@ private Collection asSourceClasses(String[] classNames, Predicate filter) throws IOException { if (className == null || filter.test(className)) { return this.objectSourceClass; @@ -690,7 +690,7 @@ SourceClass asSourceClass(@Nullable String className, Predicate filter) 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 @@ public Collection getAnnotationAttributes(String annType, String at return result; } + @SuppressWarnings("deprecation") private SourceClass getRelated(String className) throws IOException { if (this.source instanceof Class) { try { @@ -1082,7 +1083,7 @@ private SourceClass getRelated(String className) throws IOException { 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)); } diff --git a/spring-core/src/main/java/org/springframework/core/NestedExceptionUtils.java b/spring-core/src/main/java/org/springframework/core/NestedExceptionUtils.java index db879c36765e..c1e74fef9494 100644 --- a/spring-core/src/main/java/org/springframework/core/NestedExceptionUtils.java +++ b/spring-core/src/main/java/org/springframework/core/NestedExceptionUtils.java @@ -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 @@ * @since 2.0 * @see NestedRuntimeException * @see NestedCheckedException - * @see NestedIOException * @see org.springframework.web.util.NestedServletException */ public abstract class NestedExceptionUtils { diff --git a/spring-core/src/main/java/org/springframework/core/NestedIOException.java b/spring-core/src/main/java/org/springframework/core/NestedIOException.java index 235a0ae62368..89f7b5502ac6 100644 --- a/spring-core/src/main/java/org/springframework/core/NestedIOException.java +++ b/spring-core/src/main/java/org/springframework/core/NestedIOException.java @@ -37,7 +37,9 @@ * @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 { diff --git a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java index ed342fc60c18..081a09228ec4 100644 --- a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java @@ -29,7 +29,6 @@ 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 URL getURL() throws IOException { * 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); } } diff --git a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java index 6751d60e699b..eb6d26d5ddcc 100644 --- a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java @@ -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.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 boolean isReadable() { } @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); } } diff --git a/spring-core/src/main/java/org/springframework/core/serializer/DefaultDeserializer.java b/spring-core/src/main/java/org/springframework/core/serializer/DefaultDeserializer.java index 3fbe57fcad28..45ccaa298531 100644 --- a/spring-core/src/main/java/org/springframework/core/serializer/DefaultDeserializer.java +++ b/spring-core/src/main/java/org/springframework/core/serializer/DefaultDeserializer.java @@ -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.ObjectInputStream; import org.springframework.core.ConfigurableObjectInputStream; -import org.springframework.core.NestedIOException; import org.springframework.lang.Nullable; /** @@ -65,14 +64,14 @@ public DefaultDeserializer(@Nullable ClassLoader classLoader) { * @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); } } diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReader.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReader.java index 7298d62c1729..f9501624b1b5 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReader.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReader.java @@ -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.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); } }