XMLCatalog not used from xjc/xjctask when strict validation is enabled · Issue #616 · javaee/jaxb-v2 (original) (raw)
Even when a proper XML catalog is setup, xjc/xjctask downloads resources from
system ids specified in XML schema when compiling a schema containing DOCTYPE
declaration. I've investigated the problem and concluded that this problem is
caused in class
com.sun.tools.xjc.reader.xmlschema.parser.SchemaConstraintChecker.java, where a
strict checking of XMLSchema is performed (when requested, i.e. when -nv is not
used). The problem is in SAXSource being used in method getSchemaSource, because
when using (an array of) SAXSource as an input for SchemaFactory.newSchema, an
XMLReader is internally being constructed and this XMLReader does not have an
EntityResolver set up. Hence using LSResourceResolver for SchemaFactory is no
good because this resolver is need even before, when SAXSource generated SAXEvents.
A quick fix is to turn strict validation off (using -nv switch). A quick patch
in source could be local within the method getSchemaSource - at the beginning
create an XMLReader, set its EntityResolver (which must be passed from method
check to method getSchemaSource as a method parameter) and use two-arg ctor of
SAXSource, specifying the XMLReader as the first argument (and InputSource as
the second one). But I'm not sure if this is the best solution. Maybe it is. I
could submit this patch here, if someone thinks its useful.
BTW: I've observed this issue in version 2.1.10 and it is not possible to
specify it as the JAXB version for this issue, so that's why I use 2.1.9.
Environment
Operating System: All
Platform: All
Affected Versions
[2.1.12]