Consistent use of Collection.toArray with zero-sized array argument
Includes consistent use of ClassUtils.toClassArray (as non-null variant) Issue: SPR-16523
This commit is contained in:
@@ -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.
|
||||
@@ -116,7 +116,7 @@ public class HandlerExecutionChain {
|
||||
@Nullable
|
||||
public HandlerInterceptor[] getInterceptors() {
|
||||
if (this.interceptors == null && this.interceptorList != null) {
|
||||
this.interceptors = this.interceptorList.toArray(new HandlerInterceptor[this.interceptorList.size()]);
|
||||
this.interceptors = this.interceptorList.toArray(new HandlerInterceptor[0]);
|
||||
}
|
||||
return this.interceptors;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -317,8 +317,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
*/
|
||||
@Nullable
|
||||
protected final HandlerInterceptor[] getAdaptedInterceptors() {
|
||||
int count = this.adaptedInterceptors.size();
|
||||
return (count > 0 ? this.adaptedInterceptors.toArray(new HandlerInterceptor[count]) : null);
|
||||
return (!this.adaptedInterceptors.isEmpty() ?
|
||||
this.adaptedInterceptors.toArray(new HandlerInterceptor[0]) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,14 +327,13 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
*/
|
||||
@Nullable
|
||||
protected final MappedInterceptor[] getMappedInterceptors() {
|
||||
List<MappedInterceptor> mappedInterceptors = new ArrayList<>();
|
||||
List<MappedInterceptor> mappedInterceptors = new ArrayList<>(this.adaptedInterceptors.size());
|
||||
for (HandlerInterceptor interceptor : this.adaptedInterceptors) {
|
||||
if (interceptor instanceof MappedInterceptor) {
|
||||
mappedInterceptors.add((MappedInterceptor) interceptor);
|
||||
}
|
||||
}
|
||||
int count = mappedInterceptors.size();
|
||||
return (count > 0 ? mappedInterceptors.toArray(new MappedInterceptor[count]) : null);
|
||||
return (!mappedInterceptors.isEmpty() ? mappedInterceptors.toArray(new MappedInterceptor[0]) : null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -47,7 +47,6 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage
|
||||
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ReflectionUtils.MethodFilter;
|
||||
import org.springframework.web.accept.ContentNegotiationManager;
|
||||
@@ -151,7 +150,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||
|
||||
private DeferredResultProcessingInterceptor[] deferredResultInterceptors = new DeferredResultProcessingInterceptor[0];
|
||||
|
||||
private ReactiveAdapterRegistry reactiveRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||
private ReactiveAdapterRegistry reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||
|
||||
private boolean ignoreDefaultModelOnRedirect = false;
|
||||
|
||||
@@ -410,8 +409,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||
* @param interceptors the interceptors to register
|
||||
*/
|
||||
public void setCallableInterceptors(List<CallableProcessingInterceptor> interceptors) {
|
||||
Assert.notNull(interceptors, "CallableProcessingInterceptor List must not be null");
|
||||
this.callableInterceptors = interceptors.toArray(new CallableProcessingInterceptor[interceptors.size()]);
|
||||
this.callableInterceptors = interceptors.toArray(new CallableProcessingInterceptor[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,18 +417,27 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||
* @param interceptors the interceptors to register
|
||||
*/
|
||||
public void setDeferredResultInterceptors(List<DeferredResultProcessingInterceptor> interceptors) {
|
||||
Assert.notNull(interceptors, "DeferredResultProcessingInterceptor List must not be null");
|
||||
this.deferredResultInterceptors = interceptors.toArray(new DeferredResultProcessingInterceptor[interceptors.size()]);
|
||||
this.deferredResultInterceptors = interceptors.toArray(new DeferredResultProcessingInterceptor[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the registry for reactive library types to be supported as
|
||||
* return values from controller methods.
|
||||
* @since 5.0
|
||||
* @deprecated as of 5.0.5, in favor of {@link #setReactiveAdapterRegistry}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setReactiveRegistry(ReactiveAdapterRegistry reactiveRegistry) {
|
||||
Assert.notNull(reactiveRegistry, "ReactiveAdapterRegistry is required");
|
||||
this.reactiveRegistry = reactiveRegistry;
|
||||
this.reactiveAdapterRegistry = reactiveRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the registry for reactive library types to be supported as
|
||||
* return values from controller methods.
|
||||
* @since 5.0.5
|
||||
*/
|
||||
public void setReactiveAdapterRegistry(ReactiveAdapterRegistry reactiveAdapterRegistry) {
|
||||
this.reactiveAdapterRegistry = reactiveAdapterRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -438,7 +445,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||
* @since 5.0
|
||||
*/
|
||||
public ReactiveAdapterRegistry getReactiveAdapterRegistry() {
|
||||
return this.reactiveRegistry;
|
||||
return this.reactiveAdapterRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -702,7 +709,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||
handlers.add(new ModelMethodProcessor());
|
||||
handlers.add(new ViewMethodReturnValueHandler());
|
||||
handlers.add(new ResponseBodyEmitterReturnValueHandler(getMessageConverters(),
|
||||
this.reactiveRegistry, this.taskExecutor, this.contentNegotiationManager));
|
||||
this.reactiveAdapterRegistry, this.taskExecutor, this.contentNegotiationManager));
|
||||
handlers.add(new StreamingResponseBodyReturnValueHandler());
|
||||
handlers.add(new HttpEntityMethodProcessor(getMessageConverters(),
|
||||
this.contentNegotiationManager, this.requestResponseBodyAdvice));
|
||||
|
||||
@@ -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.
|
||||
@@ -387,7 +387,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
||||
if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
|
||||
PathResourceResolver pathResolver = (PathResourceResolver) getResourceResolvers().get(i);
|
||||
if (ObjectUtils.isEmpty(pathResolver.getAllowedLocations())) {
|
||||
pathResolver.setAllowedLocations(getLocations().toArray(new Resource[getLocations().size()]));
|
||||
pathResolver.setAllowedLocations(getLocations().toArray(new Resource[0]));
|
||||
}
|
||||
if (this.urlPathHelper != null) {
|
||||
pathResolver.setLocationCharsets(this.locationCharsets);
|
||||
|
||||
@@ -180,7 +180,7 @@ public class GroovyMarkupConfigurer extends TemplateConfiguration
|
||||
}
|
||||
ClassLoader classLoader = getApplicationContext().getClassLoader();
|
||||
Assert.state(classLoader != null, "No ClassLoader");
|
||||
return (!urls.isEmpty() ? new URLClassLoader(urls.toArray(new URL[urls.size()]), classLoader) : classLoader);
|
||||
return (!urls.isEmpty() ? new URLClassLoader(urls.toArray(new URL[0]), classLoader) : classLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user