0

I have a following piece of pretty standard JAXB code

  StringReader is = new StringReader(rspString);
    Unmarshaller ums = Util.createUnMarshaller(cL, Schemas.RECEIPT_SCHEMA, GetReceiptCallResponse.class);
    UnmarshallerHandler umsHandler = ums.getUnmarshallerHandler();
    XMLFilter filter = Util.createSaxNamespaceFilter();
    filter.setContentHandler(umsHandler);

    InputSource xml = new InputSource(is);

    filter.parse(xml);

which runs fine in production and as a part of unit test. However it fails when it is run by Maven/Cobertura plugin. Strangely enough, the code runs fine when it is run by maven surefire plugin (without coverage measurement). Also, it runs fine from IntelliJ IDE both when it is run as a unit test and under an IntelliJ coverage tool. Seems like the only difference is the cobertura tool itself.

I checked the schema and XML files on input, everything looks alright. And the code is getting exactly the same input when run with or without cobertura.

The specific error I am getting is this:

testFailingParseWithCobertura(org.vlad.taxestime.ReceiptImporterTest)  Time elapsed: 10.33 sec  <<< ERROR!
org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'count' is not allowed to appear in element 'Receipts'.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:458)
Vlad
  • 9,180
  • 5
  • 48
  • 67
  • 2
    I've never had much success with Cobertura on anything non-trivial. If you don't care about the coverage tool, try JaCoCo. – Harald Wellmann Mar 24 '14 at 19:54
  • Your exception is related to schema validation. Is the exception real in that the attribute `count` is not allowed to appear in the element `Receipts`? If so it's possible that the other environments should have been throwing the exception but weren't – bdoughan Mar 24 '14 at 20:33
  • @BlaiseDoughan, nope the exception only occurs when the code is run under cobertura tool. It never occurs when unit test are run without the coverage, also it works fine in production and in the IntelliJ IDE. In fact in IntelliJ it works both when it run with or without coverage tool. – Vlad Mar 24 '14 at 22:27

1 Answers1

0

After upgrading to Maven cobertura plugin 2.7 and Junit 4.11 the issue went away

Vlad
  • 9,180
  • 5
  • 48
  • 67