Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XStreamMarshaller should convert XStream StreamException to Spring exception in case of unmarshalling an empty stream [SPR-9536] #14170

Closed
spring-projects-issues opened this issue Jun 23, 2012 · 1 comment

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jun 23, 2012

Neil Brown opened SPR-9536 and commented

The constructor for an XStream XppReader can throw an XStream StreamException, e.g. in the case where it is constructed from an empty stream. (This can occur if an attempt is made to unmarshall an empty HTTP request). For consistency, the Spring XStreamMarshaller should catch this occurrence of a StreamException, and convert (wrap and rethrow) it to a Spring UnmarshallingFailureException as it does in other cases.

TestCase follows -

import java.io.StringReader;

import javax.xml.transform.stream.StreamSource;

import org.junit.Before;
import org.junit.Test;
import org.springframework.oxm.UnmarshallingFailureException;
import org.springframework.oxm.xstream.XStreamMarshaller;

import com.thoughtworks.xstream.io.StreamException;
import com.thoughtworks.xstream.io.xml.XppReader;

/**
 * Unit tests for {@link XStreamMarshaller}.
 */
public class XStreamMarshallerTest {
  
  private XStreamMarshaller uut;

  /**
   * Set-up test fixtures.
   */
  @Before
  public void setUp() {
    this.uut = new XStreamMarshaller();
  }

  /**
   * Tests {@link org.springframework.oxm.xstream.XStreamMarshaller#unmarshalReader(java.io.Reader)} in the case
   * where the input stream is empty, and the marshaller is not configured to use a supplied stream driver, and so 
   * creates a new instance of {@link XppReader}.
   * <p>
   * In this scenario {@link XppReader#XppReader(java.io.Reader, com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer)} 
   * throws a {@link StreamException} when {@link XppReader#moveDown()} is invoked on the empty stream. The 
   * {@link XStreamMarshaller} should convert the {@link StreamException} to a generic Spring 
   * {@link UnmarshallingFailureException}.
   * 
   * @throws Exception If an unexpected error occurs on execution of this test.
   */
  @Test(expected=UnmarshallingFailureException.class)
  public final void testUnmarshalReader() throws Exception {
    this.uut.unmarshal(new StreamSource(new StringReader("")));
  }
}

Affects: 3.1.1

Sub-tasks:

  • #14174 Backport XStreamMarshaller should convert XStream StreamException to Spring exception in case of unmarshalling an empty stream
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 28, 2012

Juergen Hoeller commented

Arjen, I've slightly refined your original fix so that our IllegalArgumentException doesn't get wrapped in unmarshalDomNode. The actual culprit of this issue seems to be in unmarshalReader anyway.

Juergen

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants