Browse Source

Polishing

pull/25598/head
Juergen Hoeller 7 years ago
parent
commit
7622d1e3fa
  1. 2
      spring-core/src/main/java/org/springframework/core/CollectionFactory.java
  2. 4
      spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java
  3. 4
      spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java
  4. 2
      spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java
  5. 20
      spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java
  6. 4
      spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java
  7. 40
      spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java

2
spring-core/src/main/java/org/springframework/core/CollectionFactory.java

@ -43,7 +43,7 @@ import org.springframework.util.MultiValueMap;
import org.springframework.util.ReflectionUtils; 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.
* *
* <p>Mainly for internal use within the framework. * <p>Mainly for internal use within the framework.
* *

4
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -79,7 +79,7 @@ public abstract class AbstractLobStreamingResultSetExtractor<T> implements Resul
} }
} }
catch (IOException ex) { catch (IOException ex) {
throw new LobRetrievalFailureException("Couldn't stream LOB content", ex); throw new LobRetrievalFailureException("Could not stream LOB content", ex);
} }
} }
return null; return null;

4
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -160,7 +160,7 @@ public class SqlFunction<T> extends MappingSqlQuery<T> {
public int run(Object... parameters) { public int run(Object... parameters) {
Object obj = super.findObject(parameters); Object obj = super.findObject(parameters);
if (!(obj instanceof Number)) { 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(); return ((Number) obj).intValue();
} }

2
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()); return FileCopyUtils.copyToByteArray(dataHandler.getInputStream());
} }
catch (IOException ex) { catch (IOException ex) {
throw new UnmarshallingFailureException("Couldn't read attachment", ex); throw new UnmarshallingFailureException("Could not read attachment", ex);
} }
} }

20
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; return resourcePaths;
} }
catch (IOException ex) { 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; return null;
} }
} }
@ -330,7 +332,9 @@ public class MockServletContext implements ServletContext {
throw ex; throw ex;
} }
catch (IOException 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; return null;
} }
} }
@ -346,7 +350,9 @@ public class MockServletContext implements ServletContext {
return resource.getInputStream(); return resource.getInputStream();
} }
catch (IOException ex) { 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; return null;
} }
} }
@ -414,8 +420,8 @@ public class MockServletContext implements ServletContext {
registerNamedDispatcher(this.defaultServletName, new MockRequestDispatcher(this.defaultServletName)); registerNamedDispatcher(this.defaultServletName, new MockRequestDispatcher(this.defaultServletName));
} }
@Override
@Deprecated @Deprecated
@Override
@Nullable @Nullable
public Servlet getServlet(String name) { public Servlet getServlet(String name) {
return null; return null;
@ -457,7 +463,9 @@ public class MockServletContext implements ServletContext {
return resource.getFile().getAbsolutePath(); return resource.getFile().getAbsolutePath();
} }
catch (IOException ex) { 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; return null;
} }
} }

4
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -153,7 +153,7 @@ public class MethodMapTransactionAttributeSource
} }
if (matchingMethods.isEmpty()) { if (matchingMethods.isEmpty()) {
throw new IllegalArgumentException( 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 // Register all matching methods

40
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.core.io.ResourceLoader;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.MediaTypeFactory; import org.springframework.http.MediaTypeFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.MimeType; import org.springframework.util.MimeType;
@ -129,14 +130,17 @@ public class MockServletContext implements ServletContext {
private final Set<String> declaredRoles = new LinkedHashSet<>(); private final Set<String> declaredRoles = new LinkedHashSet<>();
@Nullable
private Set<SessionTrackingMode> sessionTrackingModes; private Set<SessionTrackingMode> sessionTrackingModes;
private final SessionCookieConfig sessionCookieConfig = new MockSessionCookieConfig(); private final SessionCookieConfig sessionCookieConfig = new MockSessionCookieConfig();
private int sessionTimeout; private int sessionTimeout;
@Nullable
private String requestCharacterEncoding; private String requestCharacterEncoding;
@Nullable
private String responseCharacterEncoding; private String responseCharacterEncoding;
private final Map<String, MediaType> mimeTypes = new LinkedHashMap<>(); private final Map<String, MediaType> mimeTypes = new LinkedHashMap<>();
@ -165,7 +169,7 @@ public class MockServletContext implements ServletContext {
* and no base path. * and no base path.
* @param resourceLoader the ResourceLoader to use (or null for the default) * @param resourceLoader the ResourceLoader to use (or null for the default)
*/ */
public MockServletContext(ResourceLoader resourceLoader) { public MockServletContext(@Nullable ResourceLoader resourceLoader) {
this("", resourceLoader); this("", resourceLoader);
} }
@ -178,7 +182,7 @@ public class MockServletContext implements ServletContext {
* @param resourceLoader the ResourceLoader to use (or null for the default) * @param resourceLoader the ResourceLoader to use (or null for the default)
* @see #registerNamedDispatcher * @see #registerNamedDispatcher
*/ */
public MockServletContext(String resourceBasePath, ResourceLoader resourceLoader) { public MockServletContext(String resourceBasePath, @Nullable ResourceLoader resourceLoader) {
this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader()); this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader());
this.resourceBasePath = resourceBasePath; this.resourceBasePath = resourceBasePath;
@ -262,6 +266,7 @@ public class MockServletContext implements ServletContext {
} }
@Override @Override
@Nullable
public String getMimeType(String filePath) { public String getMimeType(String filePath) {
String extension = StringUtils.getFilenameExtension(filePath); String extension = StringUtils.getFilenameExtension(filePath);
if (this.mimeTypes.containsKey(extension)) { if (this.mimeTypes.containsKey(extension)) {
@ -285,6 +290,7 @@ public class MockServletContext implements ServletContext {
} }
@Override @Override
@Nullable
public Set<String> getResourcePaths(String path) { public Set<String> getResourcePaths(String path) {
String actualPath = (path.endsWith("/") ? path : path + "/"); String actualPath = (path.endsWith("/") ? path : path + "/");
Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath)); Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath));
@ -305,12 +311,15 @@ public class MockServletContext implements ServletContext {
return resourcePaths; return resourcePaths;
} }
catch (IOException ex) { 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; return null;
} }
} }
@Override @Override
@Nullable
public URL getResource(String path) throws MalformedURLException { public URL getResource(String path) throws MalformedURLException {
Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); Resource resource = this.resourceLoader.getResource(getResourceLocation(path));
if (!resource.exists()) { if (!resource.exists()) {
@ -323,12 +332,15 @@ public class MockServletContext implements ServletContext {
throw ex; throw ex;
} }
catch (IOException 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; return null;
} }
} }
@Override @Override
@Nullable
public InputStream getResourceAsStream(String path) { public InputStream getResourceAsStream(String path) {
Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); Resource resource = this.resourceLoader.getResource(getResourceLocation(path));
if (!resource.exists()) { if (!resource.exists()) {
@ -338,7 +350,9 @@ public class MockServletContext implements ServletContext {
return resource.getInputStream(); return resource.getInputStream();
} }
catch (IOException ex) { 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; return null;
} }
} }
@ -406,8 +420,9 @@ public class MockServletContext implements ServletContext {
registerNamedDispatcher(this.defaultServletName, new MockRequestDispatcher(this.defaultServletName)); registerNamedDispatcher(this.defaultServletName, new MockRequestDispatcher(this.defaultServletName));
} }
@Override
@Deprecated @Deprecated
@Override
@Nullable
public Servlet getServlet(String name) { public Servlet getServlet(String name) {
return null; return null;
} }
@ -441,13 +456,16 @@ public class MockServletContext implements ServletContext {
} }
@Override @Override
@Nullable
public String getRealPath(String path) { public String getRealPath(String path) {
Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); Resource resource = this.resourceLoader.getResource(getResourceLocation(path));
try { try {
return resource.getFile().getAbsolutePath(); return resource.getFile().getAbsolutePath();
} }
catch (IOException ex) { 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; return null;
} }
} }
@ -484,6 +502,7 @@ public class MockServletContext implements ServletContext {
} }
@Override @Override
@Nullable
public Object getAttribute(String name) { public Object getAttribute(String name) {
Assert.notNull(name, "Attribute name must not be null"); Assert.notNull(name, "Attribute name must not be null");
return this.attributes.get(name); return this.attributes.get(name);
@ -495,7 +514,7 @@ public class MockServletContext implements ServletContext {
} }
@Override @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"); Assert.notNull(name, "Attribute name must not be null");
if (value != null) { if (value != null) {
this.attributes.put(name, value); this.attributes.put(name, value);
@ -521,6 +540,7 @@ public class MockServletContext implements ServletContext {
} }
@Override @Override
@Nullable
public ClassLoader getClassLoader() { public ClassLoader getClassLoader() {
return ClassUtils.getDefaultClassLoader(); return ClassUtils.getDefaultClassLoader();
} }
@ -630,6 +650,7 @@ public class MockServletContext implements ServletContext {
* @see javax.servlet.ServletContext#getServletRegistration(java.lang.String) * @see javax.servlet.ServletContext#getServletRegistration(java.lang.String)
*/ */
@Override @Override
@Nullable
public ServletRegistration getServletRegistration(String servletName) { public ServletRegistration getServletRegistration(String servletName) {
return null; return null;
} }
@ -668,6 +689,7 @@ public class MockServletContext implements ServletContext {
* @see javax.servlet.ServletContext#getFilterRegistration(java.lang.String) * @see javax.servlet.ServletContext#getFilterRegistration(java.lang.String)
*/ */
@Override @Override
@Nullable
public FilterRegistration getFilterRegistration(String filterName) { public FilterRegistration getFilterRegistration(String filterName) {
return null; return null;
} }

Loading…
Cancel
Save