Issue Details (XML | Word | Printable)

Key: GEOT-742
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Justin Deoliveira
Reporter: Pierrick Brihaye
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
GeoTools

GMLFilterGeometry thows NullPointerException

Created: 27/Oct/05 02:32 AM   Updated: 13/Jun/07 11:31 AM
Return to search
Component/s: core main
Affects Version/s: 2.2.M0, 2.4-M1
Fix Version/s: None

File Attachments: 1. File airports.gml (6 kB)
2. Text File patch.txt (13 kB)
3. XML File Test.xml (9 kB)

Environment: Java 5.0, Windows XP


 Description  « Hide

When trying to get the geometries contained in the attached file (Test.xml) with the following code snippet :

import java.io.IOException;
import org.geotools.gml.GMLFilterDocument;
import org.geotools.gml.GMLFilterGeometry;
import org.geotools.gml.TestHandler;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

public class Test {

public static void main(String[] args) {
String fileName = "./Test.xml";
try { TestHandler contentHandler = new TestHandler(); GMLFilterGeometry geometryFilter = new GMLFilterGeometry(contentHandler); GMLFilterDocument documentFilter = new GMLFilterDocument(geometryFilter); XMLReader parser; parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); parser.setContentHandler(documentFilter); parser.parse(fileName); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
}
}

... I get the following exception :

Exception in thread "main" java.lang.NullPointerException
at org.geotools.gml.GMLFilterGeometry.gmlCoordinates(GMLFilterGeometry.java:131)
at org.geotools.gml.GMLFilterDocument$CoordinateReader.readCoordinates(GMLFilterDocument.java:399)
at org.geotools.gml.GMLFilterDocument.endElement(GMLFilterDocument.java:258)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(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.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at Test.main(Test.java:22)

When trying with the other attached file (aiports.gml)., I get the results I expect.

I welcome any suggestion to improve the retrieving of geometries in a GML file, but NPEs should be handled IMHO.



Sort Order: Ascending order - Click to sort in descending order
Jody Garnett added a comment - 05/Mar/06 06:38 PM
sorry an xml bug for yeah

Pierrick Brihaye added a comment - 19/Apr/07 07:52 AM
Still present in 2.4-M1, this time with a file taken at :

http://www.ordnancesurvey.co.uk/oswebsite/products/osmastermap/layers/topography/sample.html
(2182-SS7886-2c1.gz )

As far as I can see, the method is :

public void gmlCoordinates(double x, double y) throws SAXException {
        currentHandler.addCoordinate(new com.vividsolutions.jts.geom.Coordinate(
                x, y));
    }

... so, I assume that currentHandler == null.

It is still not clear to me if the problem is linked to an unitialized currentHandler or to an odd geometrical information such as in :

<osgb:Rectangle srsName='osgb:BNG'>
<gml:coordinates>278000.000,186000.000 280000.000,188000.000</gml:coordinates>
</osgb:Rectangle>

Pierrick Brihaye added a comment - 01/May/07 09:14 AM
A quick patch to wrap NPEs and topology exceptions to SAX ones.

Not as verbose as one could expect but that's probably better than nothing.

Still trying to understand Geotools build system to submit a test case (which works on mylocal installation).

Pierrick Brihaye added a comment - 13/Jun/07 11:31 AM