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:
Arjen Poutsma
2020-06-10 15:56:45 +02:00
parent eb3be3ad88
commit 202799e6fe
3 changed files with 13 additions and 8 deletions

View File

@@ -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);

View File

@@ -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);