Ant XJC task problems with spaces in paths · Issue #416 · javaee/jaxb-v2 (original) (raw)
Running the Ant XJC task on a set of schema with spaces in directory names (e.g.
c:\documents and settings\myuser\workspace\jaxbtest) is hitting issues when
dealing with schema imports.
The errors being returned:
[xjc] Compiling file:/C:/Documents and
Settings/myuser/workspace/jaxbtest/src/schema/one.xsd and others
[xjc] [ERROR] 'ContentType' is already defined
[xjc] line 14 of
file:/C:/Documents%20and%20Settings/myuser/workspace/jaxbtest/src/schema/two.xsd
[xjc] [ERROR] (related to above error) the first definition appears here
[xjc] line 9 of
file:/C:/Documents%20and%20Settings/myuser/workspace/jaxbtest/src/schema/two.xsd
[xjc] failure in the XJC task. Use the Ant -verbose switch for more details
It looks like it is getting confused with spaces in the file names, the first
one having spaces in the URL and the others having proper escaping with %20.
Running the same code from a directory without spaces does not exhibit the same
problem and the schema compiles without error.
From a bit of digging around in the XJC Ant task code, it looks like the cause
of the problem is in the com.sun.tools.xjc.XJC2Task class, getInputSource(File)
method: where a java.io.File's now deprecated toURL() method is being called to
convert a file to a URL (line 567).
return new InputSource(f.toURL().toExternalForm());
This call is now deprecated since it doesn't properly escape spaces in file
names. After changing this straight toURL() to use toURI():
return new InputSource(f.toURI().toURL().toExternalForm());
the problem seemed to be fixed, and the schema now compile.
More info at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015239.
Environment
Operating System: All
Platform: All
Affected Versions
[2.1.4]