Skip to content

Commit 049437e

Browse files
committed
Log exception when closing InputStream in AbstractResource
Prior to this commit, exceptions thrown while closing an InputStream in AbstractResource were silently ignored. This commit improves diagnostics for such failure scenarios by logging the exception at DEBUG level. Closes gh-23116
1 parent 5cbc0cd commit 049437e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

+9-1
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-2019 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.
@@ -27,6 +27,7 @@
2727
import java.nio.channels.ReadableByteChannel;
2828

2929
import org.springframework.core.NestedIOException;
30+
import org.springframework.core.log.LogAccessor;
3031
import org.springframework.lang.Nullable;
3132
import org.springframework.util.ResourceUtils;
3233

@@ -39,10 +40,13 @@
3940
* throw an exception; and "toString" will return the description.
4041
*
4142
* @author Juergen Hoeller
43+
* @author Sam Brannen
4244
* @since 28.12.2003
4345
*/
4446
public abstract class AbstractResource implements Resource {
4547

48+
private static final LogAccessor logAccessor = new LogAccessor(AbstractResource.class);
49+
4650
/**
4751
* This implementation checks whether a File can be opened,
4852
* falling back to whether an InputStream can be opened.
@@ -61,6 +65,8 @@ public boolean exists() {
6165
return true;
6266
}
6367
catch (Throwable isEx) {
68+
logAccessor.debug(ex,
69+
() -> "Could not close InputStream for resource: " + getDescription());
6470
return false;
6571
}
6672
}
@@ -158,6 +164,8 @@ public long contentLength() throws IOException {
158164
is.close();
159165
}
160166
catch (IOException ex) {
167+
logAccessor.debug(ex,
168+
() -> "Could not close InputStream for resource: " + getDescription());
161169
}
162170
}
163171
}

0 commit comments

Comments
 (0)