users@jaxb.java.net

NullPointerException in class W3CDomHandler

From: AndyGl <crow.abyss_at_web.de>
Date: Wed, 19 Aug 2009 03:57:20 -0700 (PDT)

Hi,
I am getting a NPE in class W3CDomHandler at line 83. Line 83 is the last
line in the method:

    public Element getElement(DOMResult r) {
        // JAXP spec is ambiguous about what really happens in this case,
        // so work defensively
        Node n = r.getNode();
        if( n instanceof Document ) {
            return ((Document)n).getDocumentElement();
        }
        if( n instanceof Element )
            return (Element)n;
        if( n instanceof DocumentFragment )
            return (Element)n.getChildNodes().item(0);

        // if the result object contains something strange,
        // it is not a user problem, but it is a JAXB provider's problem.
        // That's why we throw a runtime exception.
        throw new IllegalStateException(n.toString());
    }

So this NPE can only happen if there is no Node n available. The NPE could
be simply fixed by changing the line to something like
    throw new IllegalStateException("Node: "+(n==null?"null":n.toString()));

But anyway there is something going wrong. Anyone has an idea what would be
cause of the exception? The given XML contains some elements not specified
in the XSD but I think this should not cause this exception but a "better"
one saying whats wrong.

Andy

-- 
View this message in context: http://www.nabble.com/NullPointerException-in-class-W3CDomHandler-tp25041924p25041924.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.