Clean up warnings in spring-web

This commit is contained in:
Sam Brannen 2016-07-15 18:38:27 +02:00
parent 58804da369
commit 3f317b7d3f
27 changed files with 31 additions and 64 deletions

View File

@ -39,7 +39,6 @@ import org.apache.http.protocol.HttpContext;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.http.HttpMethod;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* {@link org.springframework.http.client.ClientHttpRequestFactory} implementation that

View File

@ -24,7 +24,6 @@ import io.netty.handler.codec.http.cookie.DefaultCookie;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.io.netty.http.HttpClient;
import reactor.io.netty.http.HttpClientRequest;
import org.springframework.core.io.buffer.DataBuffer;

View File

@ -17,14 +17,11 @@
package org.springframework.http.client.reactive;
import java.util.Collection;
import java.util.function.Function;
import io.netty.buffer.ByteBuf;
import reactor.core.publisher.Flux;
import reactor.io.netty.http.HttpClientResponse;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@ -96,4 +93,5 @@ public class ReactorClientHttpResponse implements ClientHttpResponse {
"status=" + getStatusCode() +
'}';
}
}
}

View File

@ -38,11 +38,11 @@ import org.springframework.util.MimeType;
* Decode an arbitrary split byte stream representing JSON objects to a byte
* stream where each chunk is a well-formed JSON object.
*
* This class does not do any real parsing or validation. A sequence of byte
* <p>This class does not do any real parsing or validation. A sequence of bytes
* is considered a JSON object/array if it contains a matching number of opening
* and closing braces/brackets.
*
* Based on <a href="https://github.com/netty/netty/blob/master/codec/src/main/java/io/netty/handler/codec/json/JsonObjectDecoder.java">Netty JsonObjectDecoder</a>
* <p>Based on <a href="https://github.com/netty/netty/blob/master/codec/src/main/java/io/netty/handler/codec/json/JsonObjectDecoder.java">Netty JsonObjectDecoder</a>
*
* @author Sebastien Deleuze
* @since 5.0
@ -220,7 +220,6 @@ class JsonObjectDecoder extends AbstractDecoder<DataBuffer> {
* Override this method if you want to filter the json objects/arrays that
* get passed through the pipeline.
*/
@SuppressWarnings("UnusedParameters")
protected ByteBuf extractObject(ByteBuf buffer, int index, int length) {
return buffer.slice(index, length).retain();
}

View File

@ -79,7 +79,7 @@ public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessa
@Override
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) {
if (!(type instanceof ParameterizedType)) {
return ResourceRegion.class.isAssignableFrom((Class) type);
return ResourceRegion.class.isAssignableFrom((Class<?>) type);
}
ParameterizedType parameterizedType = (ParameterizedType) type;
if (!(parameterizedType.getRawType() instanceof Class)) {

View File

@ -181,7 +181,6 @@ public class CodecHttpMessageConverter<T> implements HttpMessageConverter<T> {
* @param elementType the type of element for encoding
* @return the content type, or {@code null}
*/
@SuppressWarnings("UnusedParameters")
protected MediaType getDefaultContentType(ResolvableType elementType) {
return (!this.writableMediaTypes.isEmpty() ? this.writableMediaTypes.get(0) : null);
}

View File

@ -100,4 +100,5 @@ public interface HttpMessageConverter<T> {
Mono<Void> write(Publisher<? extends T> inputStream,
ResolvableType type, MediaType contentType,
ReactiveHttpOutputMessage outputMessage);
}
}

View File

@ -39,7 +39,7 @@ import org.springframework.util.ResourceUtils;
/**
* Implementation of {@link HttpMessageConverter} that can read and write
* {@link Resource Resources} and supports byte range requests.
**
*
* @author Arjen Poutsma
* @since 5.0
*/
@ -53,6 +53,7 @@ public class ResourceHttpMessageConverter extends CodecHttpMessageConverter<Reso
super(new ResourceEncoder(bufferSize), new ResourceDecoder());
}
@Override
public Mono<Void> write(Publisher<? extends Resource> inputStream,
ResolvableType type, MediaType contentType,
@ -92,8 +93,7 @@ public class ResourceHttpMessageConverter extends CodecHttpMessageConverter<Reso
ZeroCopyHttpOutputMessage zeroCopyResponse =
(ZeroCopyHttpOutputMessage) outputMessage;
return zeroCopyResponse
.writeWith(file.get(), (long) 0, file.get().length());
return zeroCopyResponse.writeWith(file.get(), 0, file.get().length());
}
}
@ -127,5 +127,4 @@ public class ResourceHttpMessageConverter extends CodecHttpMessageConverter<Reso
return Optional.empty();
}
}

View File

@ -16,8 +16,6 @@
package org.springframework.http.converter.support;
import javax.xml.transform.Source;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

View File

@ -27,7 +27,6 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
/**

View File

@ -114,6 +114,7 @@ public class UndertowServerHttpResponse extends AbstractServerHttpResponse
try {
StreamSinkChannel responseChannel =
getUndertowExchange().getResponseChannel();
@SuppressWarnings("resource")
FileChannel in = new FileInputStream(file).getChannel();
long result = responseChannel.transferFrom(in, position, count);
if (result < count) {

View File

@ -43,7 +43,6 @@ import org.springframework.context.i18n.LocaleContext;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.remoting.support.RemoteInvocationResult;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**

View File

@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.transform.Source;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;

View File

@ -205,7 +205,7 @@ public final class WebClient {
}
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Mono<Void> writeRequestBody(Publisher<?> content,
ResolvableType requestType, ClientHttpRequest request,
List<HttpMessageConverter<?>> messageConverters) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -25,7 +25,8 @@ import org.springframework.http.HttpMethod;
*/
public class OkHttpAsyncClientHttpRequestFactoryTests extends AbstractAsyncHttpRequestFactoryTestCase {
@Override
@Override
@SuppressWarnings("deprecation")
protected AsyncClientHttpRequestFactory createRequestFactory() {
return new OkHttpClientHttpRequestFactory();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -26,6 +26,7 @@ import org.springframework.http.HttpMethod;
public class OkHttpClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTestCase {
@Override
@SuppressWarnings("deprecation")
protected ClientHttpRequestFactory createRequestFactory() {
return new OkHttpClientHttpRequestFactory();
}

View File

@ -84,9 +84,7 @@ public class JacksonJsonDecoderTests extends AbstractDataBufferAllocatingTestCas
assertValues(new Pojo("f1", "b1"), new Pojo("f2", "b2"));
}
@SuppressWarnings("unused")
void handle(List<Pojo> list) {
}
}

View File

@ -34,9 +34,9 @@ import org.springframework.http.MediaType;
import org.springframework.http.codec.Pojo;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.custommonkey.xmlunit.XMLAssert.fail;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author Sebastien Deleuze

View File

@ -197,7 +197,6 @@ public class SpringHandlerInstantiatorTests {
}
// Only needed when compiling against Jackson 2.7; gone in 2.8
@SuppressWarnings("deprecation")
public JavaType typeFromId(String s) {
return TypeFactory.defaultInstance().constructFromCanonical(s);
}

View File

@ -35,9 +35,8 @@ import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertThat;
/**
* Temporarily does not extend AbstractHttpHandlerIntegrationTests.
*
* @author Stephane Maldini
* @since 5.0
*/
public class AsyncIntegrationTests extends AbstractHttpHandlerIntegrationTests {
@ -50,12 +49,11 @@ public class AsyncIntegrationTests extends AbstractHttpHandlerIntegrationTests {
return new AsyncHandler();
}
@SuppressWarnings("unchecked")
@Test
public void basicTest() throws Exception {
URI url = new URI("http://localhost:" + port);
ResponseEntity<String> response = new RestTemplate().exchange(RequestEntity.get(url)
.build(), String.class);
ResponseEntity<String> response = new RestTemplate().exchange(
RequestEntity.get(url).build(), String.class);
assertThat(response.getBody(), Matchers.equalTo("hello"));
}
@ -65,8 +63,8 @@ public class AsyncIntegrationTests extends AbstractHttpHandlerIntegrationTests {
@Override
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
return response.writeWith(Flux.just("h", "e", "l", "l", "o")
.delay(Duration.ofMillis(100))
.publishOn(asyncGroup)
.delay(Duration.ofMillis(100))
.publishOn(asyncGroup)
.collect(dataBufferFactory::allocateBuffer, (buffer, str) -> buffer.write(str.getBytes())));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.http.server.reactive;
import java.util.ArrayList;
@ -37,7 +38,6 @@ import static org.junit.Assert.*;
* @author Rossen Stoyanchev
* @author Stephane Maldini
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public class ChannelSendOperatorTests {
private OneByOneAsyncWriter writer;
@ -176,15 +176,4 @@ public class ChannelSendOperatorTests {
}
}
private final static Subscription NO_OP_SUBSCRIPTION = new Subscription() {
@Override
public void request(long n) {
}
@Override
public void cancel() {
}
};
}

View File

@ -19,8 +19,6 @@ package org.springframework.http.server.reactive;
import org.junit.Before;
import org.junit.Test;
import static org.springframework.web.client.reactive.ClientWebRequestBuilders.get;
import static org.springframework.web.client.reactive.ResponseExtractors.bodyStream;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.test.TestSubscriber;
@ -87,4 +85,5 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest
return response.writeWith(responseBody);
}
}
}

View File

@ -89,17 +89,11 @@ public class RandomHandlerIntegrationTests extends AbstractHttpHandlerIntegratio
assertEquals(REQUEST_SIZE, (long) size);
});
response.getHeaders().setContentLength(RESPONSE_SIZE);
return requestSizeMono.then(response.writeWith(multipleChunks()));
}
private Publisher<DataBuffer> singleChunk() {
return Mono.just(randomBuffer(RESPONSE_SIZE));
}
private Publisher<DataBuffer> multipleChunks() {
int chunkSize = RESPONSE_SIZE / CHUNKS;
return Flux.range(1, CHUNKS).map(integer -> randomBuffer(chunkSize));

View File

@ -56,7 +56,7 @@ public class ZeroCopyIntegrationTests extends AbstractHttpHandlerIntegrationTest
RestTemplate restTemplate = new RestTemplate();
RequestEntity request =
RequestEntity<?> request =
RequestEntity.get(new URI("http://localhost:" + port)).build();
ResponseEntity<byte[]> response = restTemplate.exchange(request, byte[].class);

View File

@ -38,7 +38,6 @@ import static org.junit.Assert.*;
* @author Sam Brannen
* @since 16.05.2003
*/
@SuppressWarnings("deprecation")
public class CauchoRemotingTests {
@Rule

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.server.handler;
package org.springframework.web.server.handler;
import java.net.URI;
@ -37,8 +37,8 @@ import static org.junit.Assert.assertEquals;
/**
* @author Rossen Stoyanchev
* @since 5.0
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public class ExceptionHandlingHttpHandlerTests {
private MockServerHttpResponse response;

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.server.session;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Clock;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
@ -133,7 +133,6 @@ public class WebSessionIntegrationTests extends AbstractHttpHandlerIntegrationTe
assertNotNull(headerValues);
assertEquals(1, headerValues.size());
List<String> data = new ArrayList<>();
for (String s : headerValues.get(0).split(";")){
if (s.startsWith("SESSION=")) {
return s.substring("SESSION=".length());