XML-XSD schema location strategies do break on Windows
------------------------------------------------------

                 Key: GEOT-1635
                 URL: http://jira.codehaus.org/browse/GEOT-1635
             Project: GeoTools
          Issue Type: Bug
          Components: core xml
    Affects Versions: 2.5-M0
            Reporter: Andrea Aime
            Priority: Critical


Trying to unit test wcs 1.1.1 xml readers I've stumbled on what looks like unix 
specific behaviour or assumptions.

If you try to run, on gs trunk, communit/wcs111, the 
GetCapabilitiesTest.tstPostBasic() test, you'll be greeted by the following 
error message (on Windows, on linux I don't know):

{code}
java.lang.NullPointerException
        at org.eclipse.emf.common.util.URI.createURIWithCache(URI.java:655)
        at org.eclipse.emf.common.util.URI.createURI(URI.java:535)
        at 
org.eclipse.xsd.impl.XSDSchemaDirectiveImpl.resolve(XSDSchemaDirectiveImpl.java:343)
        at 
org.eclipse.xsd.impl.XSDImportImpl.importSchema(XSDImportImpl.java:411)
        at 
org.eclipse.xsd.impl.XSDSchemaImpl.resolveSchema(XSDSchemaImpl.java:2136)
        at 
org.eclipse.xsd.impl.XSDSchemaImpl.resolveNamedComponent(XSDSchemaImpl.java:2164)
        at 
org.eclipse.xsd.impl.XSDSchemaImpl.resolveElementDeclaration(XSDSchemaImpl.java:2212)
        at 
org.eclipse.xsd.impl.XSDConcreteComponentImpl.resolveElementDeclaration(XSDConcreteComponentImpl.java:2540)
        at 
org.eclipse.xsd.impl.XSDElementDeclarationImpl.patch(XSDElementDeclarationImpl.java:649)
        at 
org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcreteComponentImpl.java:526)
        at org.eclipse.xsd.impl.XSDParticleImpl.patch(XSDParticleImpl.java:508)
        at 
org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcreteComponentImpl.java:526)
        at 
org.eclipse.xsd.impl.XSDModelGroupImpl.patch(XSDModelGroupImpl.java:423)
        at 
org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcreteComponentImpl.java:526)
        at org.eclipse.xsd.impl.XSDParticleImpl.patch(XSDParticleImpl.java:508)
        at 
org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcreteComponentImpl.java:526)
        at 
org.eclipse.xsd.impl.XSDNamedComponentImpl.patch(XSDNamedComponentImpl.java:768)
        at 
org.eclipse.xsd.impl.XSDTypeDefinitionImpl.patch(XSDTypeDefinitionImpl.java:245)
        at 
org.eclipse.xsd.impl.XSDComplexTypeDefinitionImpl.patch(XSDComplexTypeDefinitionImpl.java:993)
        at 
org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcreteComponentImpl.java:526)
        at org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java:1505)
        at 
org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchemaImpl.java:2335)
        at 
org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDConcreteComponentImpl.java:1240)
        at 
org.eclipse.xsd.impl.XSDSchemaImpl.setSchemaLocation(XSDSchemaImpl.java:829)
        at org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl.java:756)
        at org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl.java:784)
        at 
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1094)
        at 
org.eclipse.xsd.impl.XSDSchemaDirectiveImpl.resolve(XSDSchemaDirectiveImpl.java:352)
        at org.eclipse.xsd.impl.XSDIncludeImpl.patch(XSDIncludeImpl.java:233)
        at 
org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcreteComponentImpl.java:526)
        at org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java:1505)
        at 
org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchemaImpl.java:2335)
        at 
org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDConcreteComponentImpl.java:1240)
        at 
org.eclipse.xsd.impl.XSDSchemaImpl.setSchemaLocation(XSDSchemaImpl.java:829)
        at org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl.java:756)
        at org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl.java:784)
        at 
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1094)
        at 
org.eclipse.xsd.impl.XSDSchemaDirectiveImpl.resolve(XSDSchemaDirectiveImpl.java:352)
        at org.eclipse.xsd.impl.XSDIncludeImpl.patch(XSDIncludeImpl.java:233)
        at 
org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcreteComponentImpl.java:526)
        at org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java:1505)
        at 
org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchemaImpl.java:2335)
        at 
org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDConcreteComponentImpl.java:1240)
        at 
org.eclipse.xsd.impl.XSDSchemaImpl.setSchemaLocation(XSDSchemaImpl.java:829)
        at org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl.java:756)
        at org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl.java:784)
        at 
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1094)
        at 
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:900)
        at org.geotools.xml.Schemas.parse(Schemas.java:237)
        at org.geotools.xml.XSD.buildSchema(XSD.java:169)
        at org.geotools.xml.XSD.getSchema(XSD.java:126)
        at org.geotools.xml.SchemaLocator.locateSchema(SchemaLocator.java:80)
        at 
org.geotools.xml.impl.ParserHandler.startElement(ParserHandler.java:273)
        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown 
Source)
        at 
org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
        at org.apache.xerces.impl.xs.XMLSchemaValidator.emptyElement(Unknown 
Source)
        at 
org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
        at 
org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown
 Source)
        at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
 Source)
        at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown 
Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.geotools.xml.Parser.parse(Parser.java:179)
        at org.geotools.xml.Parser.parse(Parser.java:157)
        at org.geoserver.wcs.xml.v1_1_1.WcsXmlReader.read(WcsXmlReader.java:43)
        at org.geoserver.ows.Dispatcher.parseRequestXML(Dispatcher.java:1058)
        at org.geoserver.ows.Dispatcher.dispatch(Dispatcher.java:375)
        at 
org.geoserver.ows.Dispatcher.handleRequestInternal(Dispatcher.java:185)
        at 
org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:139)
        at 
org.geoserver.test.GeoServerTestSupport.dispatch(GeoServerTestSupport.java:618)
        at 
org.geoserver.test.GeoServerTestSupport.post(GeoServerTestSupport.java:328)
        at 
org.geoserver.test.GeoServerTestSupport.postAsDOM(GeoServerTestSupport.java:429)
        at 
org.geoserver.wcs.GetCapabilitiesTest.testPostBasic(GetCapabilitiesTest.java:40)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at junit.framework.TestCase.runTest(TestCase.java:154)
        at junit.framework.TestCase.runBare(TestCase.java:127)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:118)
        at 
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
{code}

Little debugging shows the issue is probably  in Schemas.parse(String location, 
List locators, List resolvers),
where the is code looking like

{code}
if (new File(location).exists()) {
            location = new File(location).getCanonicalFile().toURI().toString();

            //location = new File(location).getCanonicalPath();
        }
{code}

the location in my case is 
file:/C:/progetti/geoserver/src/trunkClean/geoserver/community/wcs111/target/classes/org/geoserver/wcs/xml/v1_1_1/wcsAll.xsd
 and the
test fails, possibly because there is the hard disk unit in the middle.

The following test:

{code}
    public static void main(String[] args) throws Exception {
        final String path = 
"file:/C:/progetti/geoserver/src/trunkClean/geoserver/community/wcs111/target/classes/org/geoserver/wcs/xml/v1_1_1/wcsAll.xsd";
        if(new File(path).exists())
            System.out.println("Found as file");
        if(new File(new URI(path)).exists())
            System.out.println("Found as uri -> file");
            
    }
{code}

shows that only the second if succeeds. 
This is not the firt time I've been hit by the assumpiton that URI and File are 
interchangeable in the xml-xsd code... this may work on unix but
it breaks on windows.

Moving to some thing else while I'm waiting for the fix.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to