diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java index 969d5bf8fd..5427df2052 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.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. @@ -80,7 +80,7 @@ public abstract class AbstractLobStreamingResultSetExtractor implements Resul } } catch (IOException ex) { - throw new LobRetrievalFailureException("Couldn't stream LOB content", ex); + throw new LobRetrievalFailureException("Could not stream LOB content", ex); } } return null; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java index 0811e7206d..4a4a52f108 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.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. @@ -161,7 +161,7 @@ public class SqlFunction extends MappingSqlQuery { public int run(Object... parameters) { Object obj = super.findObject(parameters); if (!(obj instanceof Number)) { - throw new TypeMismatchDataAccessException("Couldn't convert result object [" + obj + "] to int"); + throw new TypeMismatchDataAccessException("Could not convert result object [" + obj + "] to int"); } return ((Number) obj).intValue(); } diff --git a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java index ded4206f2f..3de7935952 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java @@ -1025,7 +1025,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi return FileCopyUtils.copyToByteArray(dataHandler.getInputStream()); } catch (IOException ex) { - throw new UnmarshallingFailureException("Couldn't read attachment", ex); + throw new UnmarshallingFailureException("Could not read attachment", ex); } } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java index 14aede9de9..b67eb000e3 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.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. @@ -153,7 +153,7 @@ public class MethodMapTransactionAttributeSource } if (matchingMethods.isEmpty()) { throw new IllegalArgumentException( - "Couldn't find method '" + mappedName + "' on class [" + clazz.getName() + "]"); + "Could not find method '" + mappedName + "' on class [" + clazz.getName() + "]"); } // Register all matching methods diff --git a/spring-web/src/main/java/org/springframework/web/context/ContextCleanupListener.java b/spring-web/src/main/java/org/springframework/web/context/ContextCleanupListener.java index 4742be00ef..5635fe5752 100644 --- a/spring-web/src/main/java/org/springframework/web/context/ContextCleanupListener.java +++ b/spring-web/src/main/java/org/springframework/web/context/ContextCleanupListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -54,22 +54,26 @@ public class ContextCleanupListener implements ServletContextListener { /** - * Find all ServletContext attributes which implement {@link DisposableBean} - * and destroy them, removing all affected ServletContext attributes eventually. - * @param sc the ServletContext to check + * Find all Spring-internal ServletContext attributes which implement + * {@link DisposableBean} and invoke the destroy method on them. + * @param servletContext the ServletContext to check + * @see DisposableBean#destroy() */ - static void cleanupAttributes(ServletContext sc) { - Enumeration attrNames = sc.getAttributeNames(); + static void cleanupAttributes(ServletContext servletContext) { + Enumeration attrNames = servletContext.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = attrNames.nextElement(); if (attrName.startsWith("org.springframework.")) { - Object attrValue = sc.getAttribute(attrName); + Object attrValue = servletContext.getAttribute(attrName); if (attrValue instanceof DisposableBean) { try { ((DisposableBean) attrValue).destroy(); } catch (Throwable ex) { - logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex); + if (logger.isWarnEnabled()) { + logger.warn("Invocation of destroy method failed on ServletContext " + + "attribute with name '" + attrName + "'", ex); + } } } } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java b/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java index 281dbb3614..53e39ee716 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -188,8 +188,8 @@ public class ServletRequestAttributes extends AbstractRequestAttributes { public void removeAttribute(String name, int scope) { if (scope == SCOPE_REQUEST) { if (isRequestActive()) { - this.request.removeAttribute(name); removeRequestDestructionCallback(name); + this.request.removeAttribute(name); } } else { @@ -197,9 +197,8 @@ public class ServletRequestAttributes extends AbstractRequestAttributes { if (session != null) { this.sessionAttributesToUpdate.remove(name); try { - session.removeAttribute(name); - // Remove any registered destruction callback as well. session.removeAttribute(DESTRUCTION_CALLBACK_NAME_PREFIX + name); + session.removeAttribute(name); } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextScope.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextScope.java index 03d348566c..eb850ef194 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextScope.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextScope.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -78,8 +78,10 @@ public class ServletContextScope implements Scope, DisposableBean { public Object remove(String name) { Object scopedObject = this.servletContext.getAttribute(name); if (scopedObject != null) { + synchronized (this.destructionCallbacks) { + this.destructionCallbacks.remove(name); + } this.servletContext.removeAttribute(name); - this.destructionCallbacks.remove(name); return scopedObject; } else { @@ -89,7 +91,9 @@ public class ServletContextScope implements Scope, DisposableBean { @Override public void registerDestructionCallback(String name, Runnable callback) { - this.destructionCallbacks.put(name, callback); + synchronized (this.destructionCallbacks) { + this.destructionCallbacks.put(name, callback); + } } @Override @@ -112,10 +116,12 @@ public class ServletContextScope implements Scope, DisposableBean { */ @Override public void destroy() { - for (Runnable runnable : this.destructionCallbacks.values()) { - runnable.run(); + synchronized (this.destructionCallbacks) { + for (Runnable runnable : this.destructionCallbacks.values()) { + runnable.run(); + } + this.destructionCallbacks.clear(); } - this.destructionCallbacks.clear(); } }