ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Millar (JIRA)" <>
Subject [jira] [Commented] (AXIOM-441) Fails to parse XML with empty default namespace attribute value
Date Tue, 13 Nov 2012 17:08:12 GMT


Paul Millar commented on AXIOM-441:

It turns out the bug is in axiom-api's StAXOMBuilder#processNamespaceData method.  The bug
is that this method assumes the parser's getNamespaceURI method will always returns a non-null

The Oracle and Woodstox JavaDoc are clear that this method may return null.  The getNamespaceURI
method in the StAX implementation that comes with Java 7 returns null for the element 'bar'
in the above example.  This results in an attempt to create a namespace object with a null
namespace, triggering the exception.

The patch fixes this by converting the null value to an empty String.  From the
method, an empty String seems the expected way of expressing "outside a namespace".  A prefix
of an empty String is how the default namespace is represented.  Therefore, adding a namespace
declaration of an empty String URI to an empty String prefix achieves the desired result of
taking the element outside of a defined namespace.

It would be good if someone with more familiarity with the code-base could double-check that
this is OK.

After applying the patch, the existing tests continue to pass ("mvn clean verify") and the
above XML is parsed correctly and builds the correct XML output.

NB. I've not added unit- or functional- tests for this patch as I'm not sure where such a
test would fit in with the existing test infrastructure.  There doesn't seem to be existing
unit tests for StAXOMBuilder and I'm not sure which of the more function-orientated tests
would be the most appropriate place.


> Fails to parse XML with empty default namespace attribute value
> ---------------------------------------------------------------
>                 Key: AXIOM-441
>                 URL:
>             Project: Axiom
>          Issue Type: Bug
>          Components: API, LLOM
>    Affects Versions: 1.2.13
>            Reporter: Paul Millar
>            Priority: Critical
>              Labels: patch
>         Attachments: patch-fix-StAXOMBuilder.diff
> From:
> "The attribute value in a default namespace declaration MAY be empty. This has the same
effect, within the scope of the declaration, of there being no default namespace."
> Here is a document that demonstrates this:
> <?xml version='1.0' encoding='UTF-8'?>
> <foo xmlns=''>
>     <bar xmlns=''>value</bar>
> </foo>
> The following code snippet (slightly modified from Axiom documentation) uses Axiom to
parse a String variable xmlData:
>         InputStream in =
>                 new ByteArrayInputStream(xmlData.getBytes(Charset.forName("UTF-8")));
>         OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(in);
>         OMElement documentElement = builder.getDocumentElement();
>         documentElement.serialize(System.out);
>         System.out.println();
> When given the above XML example, an IllegalArgumentException is thrown:
> Exception in thread "main" java.lang.IllegalArgumentException: Namespace URI may not
be null
> 	at<init>(
> 	at
> 	at
> 	at
> 	at
> 	at
> 	at
> 	at
> 	at
> 	at
> 	at
> 	at
> 	at
> 	at
> 	at
> 	at
> This looks like a bug.
> Cheers,
> Paul.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message