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
This commit is contained in:
parent
5cbc0cd8a3
commit
049437e111
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
|
@ -27,6 +27,7 @@ import java.nio.channels.Channels;
|
|||
import java.nio.channels.ReadableByteChannel;
|
||||
|
||||
import org.springframework.core.NestedIOException;
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
|
|
@ -39,10 +40,13 @@ import org.springframework.util.ResourceUtils;
|
|||
* throw an exception; and "toString" will return the description.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 28.12.2003
|
||||
*/
|
||||
public abstract class AbstractResource implements Resource {
|
||||
|
||||
private static final LogAccessor logAccessor = new LogAccessor(AbstractResource.class);
|
||||
|
||||
/**
|
||||
* This implementation checks whether a File can be opened,
|
||||
* falling back to whether an InputStream can be opened.
|
||||
|
|
@ -61,6 +65,8 @@ public abstract class AbstractResource implements Resource {
|
|||
return true;
|
||||
}
|
||||
catch (Throwable isEx) {
|
||||
logAccessor.debug(ex,
|
||||
() -> "Could not close InputStream for resource: " + getDescription());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -158,6 +164,8 @@ public abstract class AbstractResource implements Resource {
|
|||
is.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logAccessor.debug(ex,
|
||||
() -> "Could not close InputStream for resource: " + getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue