From 049437e11106f45b7fdc155225b06680aeb165cb Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 12 Jun 2019 13:54:58 +0300 Subject: [PATCH] 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 --- .../org/springframework/core/io/AbstractResource.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 455b5a655c..8837f47292 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 @@ -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()); } } }