I've been running into a lot of JAXB serialization errors that are caused by the fact that code is creating invalid qualified names in various places. I'm investigating the API I'm using and other java XML options, and one thing that's strange is that classes which implement qualified names don't appear to do any input checking at all.
This is really problematic, because complex code generates various JAXB objects, and it's not until marshalling time when you figure out something has gone horribly wrong. The exception stack typically doesn't tell you which element/attribute is wrong, just that something's wrong.
Wouldn't it make more sense for these libraries to make it more difficult to create un-serializable content in the first place?
Here's a code snippet: why does this work? Shouldn't it throw an IllegalArgumentException
? In other APIs which define QName, the behavior is the same. The javadocs for this class specify that if the namespace is null, you'll get an IllegalArgumentException
but not otherwise.
QName q = new QName("Namespace URI is supposed to be an anyURI, but clearly !!THIS ISN'T!!",
"Local part is supposed to be an NCName, but clearly !!THIS ISN'T!!",
"<><><><>&&& Laughably Invalid Namespace Prefix");
System.out.println(q);
References: Relevant javadoc for QName, spec constraints stating name is an anyURI, and localpart is an NCName. In other words, according to the spec, the code above is blatantly invalid, irrespective of serialization.