Consistent not-null assertions for configured interceptors

Closes gh-25088
This commit is contained in:
Juergen Hoeller 2020-05-18 14:23:05 +02:00
parent 06cfd80c1c
commit c35b21b49f
2 changed files with 7 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -87,17 +87,20 @@ public abstract class AbstractMessageChannel implements MessageChannel, Intercep
@Override
public void setInterceptors(List<ChannelInterceptor> interceptors) {
Assert.noNullElements(interceptors, "'interceptors' must not contain null elements");
this.interceptors.clear();
this.interceptors.addAll(interceptors);
}
@Override
public void addInterceptor(ChannelInterceptor interceptor) {
Assert.notNull(interceptor, "'interceptor' must not be null");
this.interceptors.add(interceptor);
}
@Override
public void addInterceptor(int index, ChannelInterceptor interceptor) {
Assert.notNull(interceptor, "'interceptor' must not be null");
this.interceptors.add(index, interceptor);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -24,6 +24,7 @@ import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.InterceptingClientHttpRequestFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
@ -57,6 +58,7 @@ public abstract class InterceptingHttpAccessor extends HttpAccessor {
* @see AnnotationAwareOrderComparator
*/
public void setInterceptors(List<ClientHttpRequestInterceptor> interceptors) {
Assert.noNullElements(interceptors, "'interceptors' must not contain null elements");
// Take getInterceptors() List as-is when passed in here
if (this.interceptors != interceptors) {
this.interceptors.clear();