From ab1b8dee58532f704bd7cc41365a63226f6e5fd3 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 6 Apr 2019 15:59:14 +0200 Subject: [PATCH] Ensure XmlEventDecoder compiles on JDK 9 and 11 --- .../springframework/http/codec/xml/XmlEventDecoder.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java index 027177d7db8..e6eeace45cc 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java @@ -18,6 +18,7 @@ package org.springframework.http.codec.xml; import java.io.InputStream; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -76,6 +77,7 @@ import org.springframework.util.xml.StaxUtils; * by other decoders which are registered by default. * * @author Arjen Poutsma + * @author Sam Brannen * @since 5.0 */ public class XmlEventDecoder extends AbstractDecoder { @@ -94,7 +96,7 @@ public class XmlEventDecoder extends AbstractDecoder { @Override - @SuppressWarnings({"rawtypes", "unchecked"}) // on JDK 9 where XMLEventReader is Iterator + @SuppressWarnings({"rawtypes", "unchecked", "cast"}) // on JDK 9 where XMLEventReader is Iterator instead of simply Iterator public Flux decode(Publisher inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map hints) { @@ -110,7 +112,9 @@ public class XmlEventDecoder extends AbstractDecoder { InputStream is = dataBuffer.asInputStream(); return () -> { try { - return inputFactory.createXMLEventReader(is); + // Explicit cast to (Iterator) is necessary on JDK 9+ since XMLEventReader + // now extends Iterator instead of simply Iterator + return (Iterator) inputFactory.createXMLEventReader(is); } catch (XMLStreamException ex) { throw Exceptions.propagate(ex);