Skip to content

Commit 6685e78

Browse files
committed
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
1 parent 8685b2f commit 6685e78

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,7 +54,6 @@
5454
import org.springframework.beans.factory.support.BeanNameGenerator;
5555
import org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase;
5656
import org.springframework.context.annotation.DeferredImportSelector.Group;
57-
import org.springframework.core.NestedIOException;
5857
import org.springframework.core.OrderComparator;
5958
import org.springframework.core.Ordered;
6059
import org.springframework.core.annotation.AnnotationAttributes;
@@ -680,6 +679,7 @@ private Collection<SourceClass> asSourceClasses(String[] classNames, Predicate<S
680679
/**
681680
* Factory method to obtain a {@link SourceClass} from a class name.
682681
*/
682+
@SuppressWarnings("deprecation")
683683
SourceClass asSourceClass(@Nullable String className, Predicate<String> filter) throws IOException {
684684
if (className == null || filter.test(className)) {
685685
return this.objectSourceClass;
@@ -690,7 +690,7 @@ SourceClass asSourceClass(@Nullable String className, Predicate<String> filter)
690690
return new SourceClass(ClassUtils.forName(className, this.resourceLoader.getClassLoader()));
691691
}
692692
catch (ClassNotFoundException ex) {
693-
throw new NestedIOException("Failed to load class [" + className + "]", ex);
693+
throw new org.springframework.core.NestedIOException("Failed to load class [" + className + "]", ex);
694694
}
695695
}
696696
return new SourceClass(this.metadataReaderFactory.getMetadataReader(className));
@@ -1073,6 +1073,7 @@ public Collection<SourceClass> getAnnotationAttributes(String annType, String at
10731073
return result;
10741074
}
10751075

1076+
@SuppressWarnings("deprecation")
10761077
private SourceClass getRelated(String className) throws IOException {
10771078
if (this.source instanceof Class) {
10781079
try {
@@ -1082,7 +1083,7 @@ private SourceClass getRelated(String className) throws IOException {
10821083
catch (ClassNotFoundException ex) {
10831084
// Ignore -> fall back to ASM next, except for core java types.
10841085
if (className.startsWith("java")) {
1085-
throw new NestedIOException("Failed to load class [" + className + "]", ex);
1086+
throw new org.springframework.core.NestedIOException("Failed to load class [" + className + "]", ex);
10861087
}
10871088
return new SourceClass(metadataReaderFactory.getMetadataReader(className));
10881089
}

spring-core/src/main/java/org/springframework/core/NestedExceptionUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,6 @@
2929
* @since 2.0
3030
* @see NestedRuntimeException
3131
* @see NestedCheckedException
32-
* @see NestedIOException
3332
* @see org.springframework.web.util.NestedServletException
3433
*/
3534
public abstract class NestedExceptionUtils {

spring-core/src/main/java/org/springframework/core/NestedIOException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
* @see #printStackTrace
3838
* @see org.springframework.core.NestedCheckedException
3939
* @see org.springframework.core.NestedRuntimeException
40+
* @deprecated as of 5.3.23, in favor of using {@link IOException} directly
4041
*/
42+
@Deprecated
4143
@SuppressWarnings("serial")
4244
public class NestedIOException extends IOException {
4345

spring-core/src/main/java/org/springframework/core/io/AbstractResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.apache.commons.logging.Log;
3030
import org.apache.commons.logging.LogFactory;
3131

32-
import org.springframework.core.NestedIOException;
3332
import org.springframework.lang.Nullable;
3433
import org.springframework.util.ResourceUtils;
3534

@@ -119,13 +118,14 @@ public URL getURL() throws IOException {
119118
* by {@link #getURL()}.
120119
*/
121120
@Override
121+
@SuppressWarnings("deprecation")
122122
public URI getURI() throws IOException {
123123
URL url = getURL();
124124
try {
125125
return ResourceUtils.toURI(url);
126126
}
127127
catch (URISyntaxException ex) {
128-
throw new NestedIOException("Invalid URI [" + url + "]", ex);
128+
throw new org.springframework.core.NestedIOException("Invalid URI [" + url + "]", ex);
129129
}
130130
}
131131

spring-core/src/main/java/org/springframework/core/io/VfsResource.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@
2222
import java.net.URI;
2323
import java.net.URL;
2424

25-
import org.springframework.core.NestedIOException;
2625
import org.springframework.lang.Nullable;
2726
import org.springframework.util.Assert;
2827

@@ -72,22 +71,24 @@ public boolean isReadable() {
7271
}
7372

7473
@Override
74+
@SuppressWarnings("deprecation")
7575
public URL getURL() throws IOException {
7676
try {
7777
return VfsUtils.getURL(this.resource);
7878
}
7979
catch (Exception ex) {
80-
throw new NestedIOException("Failed to obtain URL for file " + this.resource, ex);
80+
throw new org.springframework.core.NestedIOException("Failed to obtain URL for file " + this.resource, ex);
8181
}
8282
}
8383

8484
@Override
85+
@SuppressWarnings("deprecation")
8586
public URI getURI() throws IOException {
8687
try {
8788
return VfsUtils.getURI(this.resource);
8889
}
8990
catch (Exception ex) {
90-
throw new NestedIOException("Failed to obtain URI for " + this.resource, ex);
91+
throw new org.springframework.core.NestedIOException("Failed to obtain URI for " + this.resource, ex);
9192
}
9293
}
9394

spring-core/src/main/java/org/springframework/core/serializer/DefaultDeserializer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import java.io.ObjectInputStream;
2222

2323
import org.springframework.core.ConfigurableObjectInputStream;
24-
import org.springframework.core.NestedIOException;
2524
import org.springframework.lang.Nullable;
2625

2726
/**
@@ -65,14 +64,14 @@ public DefaultDeserializer(@Nullable ClassLoader classLoader) {
6564
* @see ObjectInputStream#readObject()
6665
*/
6766
@Override
68-
@SuppressWarnings("resource")
67+
@SuppressWarnings("deprecation")
6968
public Object deserialize(InputStream inputStream) throws IOException {
7069
ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream, this.classLoader);
7170
try {
7271
return objectInputStream.readObject();
7372
}
7473
catch (ClassNotFoundException ex) {
75-
throw new NestedIOException("Failed to deserialize object type", ex);
74+
throw new org.springframework.core.NestedIOException("Failed to deserialize object type", ex);
7675
}
7776
}
7877

spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import java.io.InputStream;
2121

2222
import org.springframework.asm.ClassReader;
23-
import org.springframework.core.NestedIOException;
2423
import org.springframework.core.io.Resource;
2524
import org.springframework.core.type.AnnotationMetadata;
2625
import org.springframework.core.type.ClassMetadata;
@@ -51,13 +50,14 @@ final class SimpleMetadataReader implements MetadataReader {
5150
this.annotationMetadata = visitor.getMetadata();
5251
}
5352

53+
@SuppressWarnings("deprecation")
5454
private static ClassReader getClassReader(Resource resource) throws IOException {
5555
try (InputStream is = resource.getInputStream()) {
5656
try {
5757
return new ClassReader(is);
5858
}
5959
catch (IllegalArgumentException ex) {
60-
throw new NestedIOException("ASM ClassReader failed to parse class file - " +
60+
throw new org.springframework.core.NestedIOException("ASM ClassReader failed to parse class file - " +
6161
"probably due to a new Java class file version that isn't supported yet: " + resource, ex);
6262
}
6363
}

0 commit comments

Comments
 (0)