提交 1022683d 编写于 作者: R Rossen Stoyanchev

Fix compiler warnings

上级 cb798726
......@@ -23,6 +23,7 @@ import org.springframework.core.NestedRuntimeException;
*
* @author Sebastien Deleuze
*/
@SuppressWarnings("serial")
public class CodecException extends NestedRuntimeException {
public CodecException(String msg, Throwable cause) {
......
......@@ -32,8 +32,8 @@ import org.springframework.core.convert.converter.GenericConverter;
public class MonoToCompletableFutureConverter implements GenericConverter {
@Override
public Set<ConvertiblePair> getConvertibleTypes() {
Set<GenericConverter.ConvertiblePair> pairs = new LinkedHashSet<>();
public Set<GenericConverter.ConvertiblePair> getConvertibleTypes() {
Set<GenericConverter.ConvertiblePair> pairs = new LinkedHashSet<>(2);
pairs.add(new GenericConverter.ConvertiblePair(Mono.class, CompletableFuture.class));
pairs.add(new GenericConverter.ConvertiblePair(CompletableFuture.class, Mono.class));
return pairs;
......@@ -45,10 +45,10 @@ public class MonoToCompletableFutureConverter implements GenericConverter {
return null;
}
else if (CompletableFuture.class.isAssignableFrom(sourceType.getType())) {
return Mono.fromFuture((CompletableFuture) source);
return Mono.fromFuture((CompletableFuture<?>) source);
}
else if (CompletableFuture.class.isAssignableFrom(targetType.getType())) {
return Mono.from((Publisher) source).toFuture();
return Mono.from((Publisher<?>) source).toFuture();
}
return null;
}
......
......@@ -40,7 +40,7 @@ public final class ReactorToRxJava1Converter implements GenericConverter {
@Override
public Set<GenericConverter.ConvertiblePair> getConvertibleTypes() {
Set<GenericConverter.ConvertiblePair> pairs = new LinkedHashSet<>();
Set<GenericConverter.ConvertiblePair> pairs = new LinkedHashSet<>(6);
pairs.add(new GenericConverter.ConvertiblePair(Flux.class, Observable.class));
pairs.add(new GenericConverter.ConvertiblePair(Observable.class, Flux.class));
pairs.add(new GenericConverter.ConvertiblePair(Mono.class, Single.class));
......@@ -56,22 +56,22 @@ public final class ReactorToRxJava1Converter implements GenericConverter {
return null;
}
if (Observable.class.isAssignableFrom(sourceType.getType())) {
return RxJava1ObservableConverter.toPublisher((Observable) source);
return RxJava1ObservableConverter.toPublisher((Observable<?>) source);
}
else if (Observable.class.isAssignableFrom(targetType.getType())) {
return RxJava1ObservableConverter.fromPublisher((Publisher) source);
return RxJava1ObservableConverter.fromPublisher((Publisher<?>) source);
}
else if (Single.class.isAssignableFrom(sourceType.getType())) {
return RxJava1SingleConverter.toPublisher((Single) source);
return RxJava1SingleConverter.toPublisher((Single<?>) source);
}
else if (Single.class.isAssignableFrom(targetType.getType())) {
return RxJava1SingleConverter.fromPublisher((Publisher) source);
return RxJava1SingleConverter.fromPublisher((Publisher<?>) source);
}
else if (Completable.class.isAssignableFrom(sourceType.getType())) {
return RxJava1CompletableConverter.toPublisher((Completable) source);
}
else if (Completable.class.isAssignableFrom(targetType.getType())) {
return RxJava1CompletableConverter.fromPublisher((Publisher) source);
return RxJava1CompletableConverter.fromPublisher((Publisher<?>) source);
}
return null;
}
......
......@@ -25,9 +25,9 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ResolvableType;
import org.springframework.core.codec.AbstractEncoder;
import org.springframework.core.codec.CodecException;
import org.springframework.core.codec.Encoder;
import org.springframework.core.codec.AbstractEncoder;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.FlushingDataBuffer;
......@@ -96,20 +96,7 @@ public class SseEventEncoder extends AbstractEncoder<Object> {
sb.append(((String)data).replaceAll("\\n", "\ndata:")).append("\n");
}
else {
Optional<Encoder<?>> encoder = dataEncoders
.stream()
.filter(e -> e.canEncode(ResolvableType.forClass(data.getClass()), mediaType))
.findFirst();
if (encoder.isPresent()) {
dataBuffer = ((Encoder<Object>)encoder.get())
.encode(Mono.just(data), bufferFactory,
ResolvableType.forClass(data.getClass()), mediaType)
.concatWith(encodeString("\n", bufferFactory));
}
else {
throw new CodecException("No suitable encoder found!");
}
dataBuffer = applyEncoder(data, mediaType, bufferFactory);
}
}
......@@ -126,6 +113,21 @@ public class SseEventEncoder extends AbstractEncoder<Object> {
}
@SuppressWarnings("unchecked")
private <T> Flux<DataBuffer> applyEncoder(Object data, MediaType mediaType, DataBufferFactory bufferFactory) {
ResolvableType elementType = ResolvableType.forClass(data.getClass());
Optional<Encoder<?>> encoder = dataEncoders
.stream()
.filter(e -> e.canEncode(elementType, mediaType))
.findFirst();
if (!encoder.isPresent()) {
return Flux.error(new CodecException("No suitable encoder found!"));
}
return ((Encoder<T>) encoder.get())
.encode(Mono.just((T) data), bufferFactory, elementType, mediaType)
.concatWith(encodeString("\n", bufferFactory));
}
private Mono<DataBuffer> encodeString(String str, DataBufferFactory bufferFactory) {
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
DataBuffer buffer = bufferFactory.allocateBuffer(bytes.length).write(bytes);
......
......@@ -84,6 +84,7 @@ public class XmlEventDecoder extends AbstractDecoder<XMLEvent> {
}
@Override
@SuppressWarnings("unchecked")
public Flux<XMLEvent> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Object... hints) {
Flux<DataBuffer> flux = Flux.from(inputStream);
......@@ -96,10 +97,8 @@ public class XmlEventDecoder extends AbstractDecoder<XMLEvent> {
flatMap(dataBuffer -> {
try {
InputStream is = dataBuffer.asInputStream();
XMLEventReader eventReader =
inputFactory.createXMLEventReader(is);
return Flux
.fromIterable((Iterable<XMLEvent>) () -> eventReader);
XMLEventReader eventReader = inputFactory.createXMLEventReader(is);
return Flux.fromIterable((Iterable<XMLEvent>) () -> eventReader);
}
catch (XMLStreamException ex) {
return Mono.error(ex);
......
......@@ -38,6 +38,7 @@ import org.springframework.util.Assert;
* @author Rossen Stoyanchev
*/
@WebServlet(asyncSupported = true)
@SuppressWarnings("serial")
public class ServletHttpHandlerAdapter extends HttpServlet {
private static final int DEFAULT_BUFFER_SIZE = 8192;
......
......@@ -34,7 +34,7 @@ import org.springframework.util.MultiValueMap;
*
* @author Brian Clozel
*/
public class ClientWebRequest {
public class ClientWebRequest {
protected final HttpMethod httpMethod;
......@@ -44,7 +44,7 @@ public class ClientWebRequest {
private MultiValueMap<String, HttpCookie> cookies;
protected Publisher body;
protected Publisher<?> body;
protected ResolvableType elementType;
......@@ -78,11 +78,11 @@ public class ClientWebRequest {
this.cookies = cookies;
}
public Publisher getBody() {
public Publisher<?> getBody() {
return body;
}
public void setBody(Publisher body) {
public void setBody(Publisher<?> body) {
this.body = body;
}
......
......@@ -59,7 +59,7 @@ public class DefaultClientWebRequestBuilder implements ClientWebRequestBuilder {
private final MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
private Publisher body;
private Publisher<?> body;
private ResolvableType elementType;
......
......@@ -43,8 +43,8 @@ public class ResponseExtractors {
* Extract the response body and decode it, returning it as a {@code Mono<T>}
* @see ResolvableType#forClassWithGenerics(Class, Class[])
*/
@SuppressWarnings("unchecked")
public static <T> ResponseExtractor<Mono<T>> body(ResolvableType bodyType) {
// noinspection unchecked
return (clientResponse, messageConverters) -> (Mono<T>) clientResponse
.flatMap(resp -> decodeResponseBody(resp, bodyType,
messageConverters))
......@@ -81,6 +81,7 @@ public class ResponseExtractors {
* a single type {@code T}
* @see ResolvableType#forClassWithGenerics(Class, Class[])
*/
@SuppressWarnings("unchecked")
public static <T> ResponseExtractor<Mono<ResponseEntity<T>>> response(
ResolvableType bodyType) {
return (clientResponse, messageConverters) -> clientResponse.then(response -> {
......@@ -92,7 +93,6 @@ public class ResponseExtractors {
Mono.just(response.getStatusCode()));
}).map(tuple -> {
Object body = (tuple.getT1() != EMPTY_BODY ? tuple.getT1() : null);
// noinspection unchecked
return new ResponseEntity<>((T) body, tuple.getT2(), tuple.getT3());
});
}
......@@ -138,6 +138,7 @@ public class ResponseExtractors {
return (clientResponse, messageConverters) -> clientResponse.map(resp -> resp.getHeaders());
}
@SuppressWarnings("unchecked")
protected static <T> Flux<T> decodeResponseBody(ClientHttpResponse response,
ResolvableType responseType,
List<HttpMessageConverter<?>> messageConverters) {
......@@ -150,7 +151,6 @@ public class ResponseExtractors {
"Could not decode response body of type '" + contentType
+ "' with target type '" + responseType.toString() + "'"));
}
// noinspection unchecked
return (Flux<T>) converter.get().read(responseType, response);
}
......
......@@ -204,6 +204,7 @@ public final class WebClient {
}
}
@SuppressWarnings("unchecked")
protected Mono<Void> writeRequestBody(Publisher<?> content,
ResolvableType requestType, ClientHttpRequest request,
List<HttpMessageConverter<?>> messageConverters) {
......@@ -215,7 +216,6 @@ public final class WebClient {
"Could not encode request body of type '" + contentType
+ "' with target type '" + requestType.toString() + "'"));
}
// noinspection unchecked
return converter.get().write((Publisher) content, requestType, contentType, request);
}
......
......@@ -24,6 +24,7 @@ import org.springframework.core.NestedRuntimeException;
*
* @author Brian Clozel
*/
@SuppressWarnings("serial")
public class WebClientException extends NestedRuntimeException {
public WebClientException(String msg) {
......
......@@ -40,15 +40,15 @@ import rx.Single;
*
* @author Brian Clozel
*/
public class RxJava1ResponseExtractors {
public class RxJava1ResponseExtractors {
/**
* Extract the response body and decode it, returning it as a {@code Single<T>}
*/
@SuppressWarnings("unchecked")
public static <T> ResponseExtractor<Single<T>> body(Class<T> sourceClass) {
ResolvableType resolvableType = ResolvableType.forClass(sourceClass);
//noinspection unchecked
return (clientResponse, messageConverters) -> (Single<T>) RxJava1SingleConverter
.fromPublisher(clientResponse
.flatMap(resp -> decodeResponseBody(resp, resolvableType, messageConverters)).next());
......@@ -69,20 +69,19 @@ public class RxJava1ResponseExtractors {
* Extract the full response body as a {@code ResponseEntity}
* with its body decoded as a single type {@code T}
*/
@SuppressWarnings("unchecked")
public static <T> ResponseExtractor<Single<ResponseEntity<T>>> response(Class<T> sourceClass) {
ResolvableType resolvableType = ResolvableType.forClass(sourceClass);
return (clientResponse, messageConverters) -> (Single<ResponseEntity<T>>)
return (clientResponse, messageConverters) ->
RxJava1SingleConverter.fromPublisher(clientResponse
.then(response ->
Mono.when(
decodeResponseBody(response, resolvableType, messageConverters).next(),
Mono.just(response.getHeaders()),
Mono.just(response.getStatusCode())))
.map(tuple -> {
//noinspection unchecked
return new ResponseEntity<>((T) tuple.getT1(), tuple.getT2(), tuple.getT3());
}));
.map(tuple ->
new ResponseEntity<>((T) tuple.getT1(), tuple.getT2(), tuple.getT3())));
}
/**
......@@ -107,6 +106,7 @@ public class RxJava1ResponseExtractors {
.fromPublisher(clientResponse.map(resp -> resp.getHeaders()));
}
@SuppressWarnings("unchecked")
protected static <T> Flux<T> decodeResponseBody(ClientHttpResponse response, ResolvableType responseType,
List<HttpMessageConverter<?>> messageConverters) {
......@@ -116,7 +116,6 @@ public class RxJava1ResponseExtractors {
return Flux.error(new IllegalStateException("Could not decode response body of type '" + contentType +
"' with target type '" + responseType.toString() + "'"));
}
//noinspection unchecked
return (Flux<T>) converter.get().read(responseType, response);
}
......
......@@ -130,8 +130,9 @@ public abstract class ContentNegotiatingResultHandlerSupport implements Ordered
return (mediaTypes.isEmpty() ? Collections.singletonList(MediaType.ALL) : mediaTypes);
}
@SuppressWarnings("unchecked")
private List<MediaType> getProducibleTypes(ServerWebExchange exchange, List<MediaType> mediaTypes) {
Optional<?> optional = exchange.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);
Optional<Object> optional = exchange.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);
if (optional.isPresent()) {
Set<MediaType> set = (Set<MediaType>) optional.get();
return new ArrayList<>(set);
......
......@@ -313,7 +313,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
public Set<String> getAllowedMethods() {
return this.partialMatches.stream().
flatMap(m -> m.getInfo().getMethodsCondition().getMethods().stream()).
map(Enum::name).
map(requestMethod -> requestMethod.name()).
collect(Collectors.toCollection(LinkedHashSet::new));
}
......
......@@ -249,12 +249,12 @@ public class ViewResolutionResultHandler extends ContentNegotiatingResultHandler
return StringUtils.stripFilenameExtension(path);
}
@SuppressWarnings("unchecked")
private Object updateModel(Object value, HandlerResult result) {
if (value instanceof Model) {
result.getModel().addAllAttributes(((Model) value).asMap());
}
else if (value instanceof Map) {
//noinspection unchecked
result.getModel().addAllAttributes((Map<String, ?>) value);
}
else {
......
......@@ -26,6 +26,7 @@ import org.springframework.http.MediaType;
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("serial")
public class MediaTypeNotSupportedStatusException extends ResponseStatusException {
private final List<MediaType> supportedMediaTypes;
......
......@@ -28,6 +28,7 @@ import org.springframework.util.Assert;
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("serial")
public class MethodNotAllowedException extends ResponseStatusException {
private String method;
......
......@@ -26,6 +26,7 @@ import org.springframework.http.MediaType;
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("serial")
public class NotAcceptableStatusException extends ResponseStatusException {
private final List<MediaType> supportedMediaTypes;
......
......@@ -24,6 +24,7 @@ import org.springframework.util.Assert;
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("serial")
public class ResponseStatusException extends NestedRuntimeException {
private final HttpStatus status;
......
......@@ -27,6 +27,7 @@ import org.springframework.http.HttpStatus;
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("serial")
public class ServerErrorException extends ResponseStatusException {
private final MethodParameter parameter;
......
......@@ -27,6 +27,7 @@ import org.springframework.http.HttpStatus;
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("serial")
public class ServerWebInputException extends ResponseStatusException {
private final MethodParameter parameter;
......
......@@ -27,6 +27,7 @@ import org.springframework.http.MediaType;
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("serial")
public class UnsupportedMediaTypeStatusException extends ResponseStatusException {
private final MediaType contentType;
......
......@@ -34,6 +34,9 @@ import org.springframework.util.Assert;
*/
public class DefaultWebSession implements ConfigurableWebSession, Serializable {
private static final long serialVersionUID = -3567697426432961630L;
private final String id;
private final Map<String, Object> attributes;
......
......@@ -274,5 +274,11 @@ public class Jaxb2DecoderTests extends AbstractDataBufferAllocatingTestCase {
return false;
}
@Override
public int hashCode() {
int result = this.foo.hashCode();
result = 31 * result + this.bar.hashCode();
return result;
}
}
}
......@@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.Test;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册