Rethrow XMLStreamExceptions as DecodingExceptions
Prior to this commit, Jaxb2XmlDecoder and XmlEventDecoder threw XMLStreamExceptions instead of DecodingExceptions (as the Decoder contract defines). This commit resolves this issue. Closes: gh-24778
This commit is contained in:
@@ -195,11 +195,16 @@ public class Jaxb2XmlDecoder extends AbstractDecoder<Object> {
|
||||
return unmarshal(events, targetType.toClass());
|
||||
}
|
||||
catch (XMLStreamException ex) {
|
||||
throw Exceptions.propagate(ex);
|
||||
throw new DecodingException(ex.getMessage(), ex);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
ex = (ex.getCause() instanceof XMLStreamException ? ex.getCause() : ex);
|
||||
throw Exceptions.propagate(ex);
|
||||
Throwable cause = ex.getCause();
|
||||
if (cause instanceof XMLStreamException) {
|
||||
throw new DecodingException(cause.getMessage(), cause);
|
||||
}
|
||||
else {
|
||||
throw Exceptions.propagate(ex);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
DataBufferUtils.release(dataBuffer);
|
||||
|
||||
@@ -34,11 +34,11 @@ import com.fasterxml.aalto.AsyncXMLStreamReader;
|
||||
import com.fasterxml.aalto.evt.EventAllocatorImpl;
|
||||
import com.fasterxml.aalto.stax.InputFactoryImpl;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.Exceptions;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.AbstractDecoder;
|
||||
import org.springframework.core.codec.DecodingException;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferLimitException;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
@@ -143,7 +143,7 @@ public class XmlEventDecoder extends AbstractDecoder<XMLEvent> {
|
||||
return result;
|
||||
}
|
||||
catch (XMLStreamException ex) {
|
||||
throw Exceptions.propagate(ex);
|
||||
throw new DecodingException(ex.getMessage(), ex);
|
||||
}
|
||||
finally {
|
||||
DataBufferUtils.release(buffer);
|
||||
@@ -204,7 +204,7 @@ public class XmlEventDecoder extends AbstractDecoder<XMLEvent> {
|
||||
return events;
|
||||
}
|
||||
catch (XMLStreamException ex) {
|
||||
throw Exceptions.propagate(ex);
|
||||
throw new DecodingException(ex.getMessage(), ex);
|
||||
}
|
||||
finally {
|
||||
DataBufferUtils.release(dataBuffer);
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -32,6 +31,7 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.DecodingException;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.testfixture.io.buffer.AbstractLeakCheckingTests;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -225,7 +225,7 @@ public class Jaxb2XmlDecoderTests extends AbstractLeakCheckingTests {
|
||||
Mono<Object> result = this.decoder.decodeToMono(source, ResolvableType.forClass(Pojo.class), null, HINTS);
|
||||
|
||||
StepVerifier.create(result).verifyErrorSatisfies(ex ->
|
||||
assertThat(Exceptions.unwrap(ex)).isInstanceOf(XMLStreamException.class));
|
||||
assertThat(Exceptions.unwrap(ex)).isInstanceOf(DecodingException.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user