From 7622d1e3fa74df407666059dc08898215299a4b4 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 12 Jun 2019 14:11:39 +0200 Subject: [PATCH] Polishing --- .../core/CollectionFactory.java | 2 +- ...bstractLobStreamingResultSetExtractor.java | 4 +- .../jdbc/object/SqlFunction.java | 4 +- .../oxm/jaxb/Jaxb2Marshaller.java | 2 +- .../mock/web/MockServletContext.java | 20 +++++++--- .../MethodMapTransactionAttributeSource.java | 4 +- .../mock/web/test/MockServletContext.java | 40 ++++++++++++++----- 7 files changed, 53 insertions(+), 23 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/CollectionFactory.java b/spring-core/src/main/java/org/springframework/core/CollectionFactory.java index 9835a29ec4a..c72d2a5d24b 100644 --- a/spring-core/src/main/java/org/springframework/core/CollectionFactory.java +++ b/spring-core/src/main/java/org/springframework/core/CollectionFactory.java @@ -43,7 +43,7 @@ import org.springframework.util.MultiValueMap; import org.springframework.util.ReflectionUtils; /** - * Factory for collections that is aware of Java 5, Java 6, and Spring collection types. + * Factory for collections that is aware of common Java and Spring collection types. * *

Mainly for internal use within the framework. * 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 6418e3d2fbc..2c7e5404d4c 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-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. @@ -79,7 +79,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 37574dea870..1aee7bd876c 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-2016 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. @@ -160,7 +160,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 cb6805cd2de..5fa0ceaeb9f 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 @@ -1019,7 +1019,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-test/src/main/java/org/springframework/mock/web/MockServletContext.java b/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java index 70353f0da0b..20f9418a546 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -311,7 +311,9 @@ public class MockServletContext implements ServletContext { return resourcePaths; } catch (IOException ex) { - logger.warn("Couldn't get resource paths for " + resource, ex); + if (logger.isWarnEnabled()) { + logger.warn("Could not get resource paths for " + resource, ex); + } return null; } } @@ -330,7 +332,9 @@ public class MockServletContext implements ServletContext { throw ex; } catch (IOException ex) { - logger.warn("Couldn't get URL for " + resource, ex); + if (logger.isWarnEnabled()) { + logger.warn("Could not get URL for " + resource, ex); + } return null; } } @@ -346,7 +350,9 @@ public class MockServletContext implements ServletContext { return resource.getInputStream(); } catch (IOException ex) { - logger.warn("Couldn't open InputStream for " + resource, ex); + if (logger.isWarnEnabled()) { + logger.warn("Could not open InputStream for " + resource, ex); + } return null; } } @@ -414,8 +420,8 @@ public class MockServletContext implements ServletContext { registerNamedDispatcher(this.defaultServletName, new MockRequestDispatcher(this.defaultServletName)); } - @Override @Deprecated + @Override @Nullable public Servlet getServlet(String name) { return null; @@ -457,7 +463,9 @@ public class MockServletContext implements ServletContext { return resource.getFile().getAbsolutePath(); } catch (IOException ex) { - logger.warn("Couldn't determine real path of resource " + resource, ex); + if (logger.isWarnEnabled()) { + logger.warn("Could not determine real path of resource " + resource, ex); + } return null; } } 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 d2306c1925c..56709a7dc9b 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/test/java/org/springframework/mock/web/test/MockServletContext.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java index b2bee41aaba..9fb12f934f1 100644 --- a/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java +++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -48,6 +48,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MimeType; @@ -129,14 +130,17 @@ public class MockServletContext implements ServletContext { private final Set declaredRoles = new LinkedHashSet<>(); + @Nullable private Set sessionTrackingModes; private final SessionCookieConfig sessionCookieConfig = new MockSessionCookieConfig(); private int sessionTimeout; + @Nullable private String requestCharacterEncoding; + @Nullable private String responseCharacterEncoding; private final Map mimeTypes = new LinkedHashMap<>(); @@ -165,7 +169,7 @@ public class MockServletContext implements ServletContext { * and no base path. * @param resourceLoader the ResourceLoader to use (or null for the default) */ - public MockServletContext(ResourceLoader resourceLoader) { + public MockServletContext(@Nullable ResourceLoader resourceLoader) { this("", resourceLoader); } @@ -178,7 +182,7 @@ public class MockServletContext implements ServletContext { * @param resourceLoader the ResourceLoader to use (or null for the default) * @see #registerNamedDispatcher */ - public MockServletContext(String resourceBasePath, ResourceLoader resourceLoader) { + public MockServletContext(String resourceBasePath, @Nullable ResourceLoader resourceLoader) { this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader()); this.resourceBasePath = resourceBasePath; @@ -262,6 +266,7 @@ public class MockServletContext implements ServletContext { } @Override + @Nullable public String getMimeType(String filePath) { String extension = StringUtils.getFilenameExtension(filePath); if (this.mimeTypes.containsKey(extension)) { @@ -285,6 +290,7 @@ public class MockServletContext implements ServletContext { } @Override + @Nullable public Set getResourcePaths(String path) { String actualPath = (path.endsWith("/") ? path : path + "/"); Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath)); @@ -305,12 +311,15 @@ public class MockServletContext implements ServletContext { return resourcePaths; } catch (IOException ex) { - logger.warn("Couldn't get resource paths for " + resource, ex); + if (logger.isWarnEnabled()) { + logger.warn("Could not get resource paths for " + resource, ex); + } return null; } } @Override + @Nullable public URL getResource(String path) throws MalformedURLException { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); if (!resource.exists()) { @@ -323,12 +332,15 @@ public class MockServletContext implements ServletContext { throw ex; } catch (IOException ex) { - logger.warn("Couldn't get URL for " + resource, ex); + if (logger.isWarnEnabled()) { + logger.warn("Could not get URL for " + resource, ex); + } return null; } } @Override + @Nullable public InputStream getResourceAsStream(String path) { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); if (!resource.exists()) { @@ -338,7 +350,9 @@ public class MockServletContext implements ServletContext { return resource.getInputStream(); } catch (IOException ex) { - logger.warn("Couldn't open InputStream for " + resource, ex); + if (logger.isWarnEnabled()) { + logger.warn("Could not open InputStream for " + resource, ex); + } return null; } } @@ -406,8 +420,9 @@ public class MockServletContext implements ServletContext { registerNamedDispatcher(this.defaultServletName, new MockRequestDispatcher(this.defaultServletName)); } - @Override @Deprecated + @Override + @Nullable public Servlet getServlet(String name) { return null; } @@ -441,13 +456,16 @@ public class MockServletContext implements ServletContext { } @Override + @Nullable public String getRealPath(String path) { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); try { return resource.getFile().getAbsolutePath(); } catch (IOException ex) { - logger.warn("Couldn't determine real path of resource " + resource, ex); + if (logger.isWarnEnabled()) { + logger.warn("Could not determine real path of resource " + resource, ex); + } return null; } } @@ -484,6 +502,7 @@ public class MockServletContext implements ServletContext { } @Override + @Nullable public Object getAttribute(String name) { Assert.notNull(name, "Attribute name must not be null"); return this.attributes.get(name); @@ -495,7 +514,7 @@ public class MockServletContext implements ServletContext { } @Override - public void setAttribute(String name, Object value) { + public void setAttribute(String name, @Nullable Object value) { Assert.notNull(name, "Attribute name must not be null"); if (value != null) { this.attributes.put(name, value); @@ -521,6 +540,7 @@ public class MockServletContext implements ServletContext { } @Override + @Nullable public ClassLoader getClassLoader() { return ClassUtils.getDefaultClassLoader(); } @@ -630,6 +650,7 @@ public class MockServletContext implements ServletContext { * @see javax.servlet.ServletContext#getServletRegistration(java.lang.String) */ @Override + @Nullable public ServletRegistration getServletRegistration(String servletName) { return null; } @@ -668,6 +689,7 @@ public class MockServletContext implements ServletContext { * @see javax.servlet.ServletContext#getFilterRegistration(java.lang.String) */ @Override + @Nullable public FilterRegistration getFilterRegistration(String filterName) { return null; }