GeoTools

GMLFilterGeometry thows NullPointerException

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 2.2.M0, 2.4-M1
  • Fix Version/s: None
  • Component/s: main
  • Labels:
    None
  • Environment:
    Java 5.0, Windows XP

Description

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.

  1. airports.gml
    27/Oct/05 2:32 AM
    6 kB
    Pierrick Brihaye
  2. patch.txt
    01/May/07 9:14 AM
    13 kB
    Pierrick Brihaye
  3. Test.xml
    27/Oct/05 2:32 AM
    9 kB
    Pierrick Brihaye

Activity

Hide
Jody Garnett added a comment -
sorry an xml bug for yeah
Show
Jody Garnett added a comment - sorry an xml bug for yeah
Hide
Pierrick Brihaye added a comment -
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>
Show
Pierrick Brihaye added a comment - 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>
Hide
Pierrick Brihaye added a comment -
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).
Show
Pierrick Brihaye added a comment - 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).
Hide
Pierrick Brihaye added a comment -
Show
Pierrick Brihaye added a comment - Just to not forget about it : http://www.nabble.com/Re%3A-Issue-742-%28GML-SAX-parsing%29-p10380930.html
Hide
Justin Deoliveira added a comment -
An old one.. the old GMLFilterGeometry stuff is deprecated/unmaintained. The patch needs some cleanup to. If a new patch surfaces i will happily apply it.
Show
Justin Deoliveira added a comment - An old one.. the old GMLFilterGeometry stuff is deprecated/unmaintained. The patch needs some cleanup to. If a new patch surfaces i will happily apply it.
Hide
Andrea Aime added a comment -
Mass closing all issues in resolved state that have not been reopened nor commented over in the last month
Show
Andrea Aime added a comment - Mass closing all issues in resolved state that have not been reopened nor commented over in the last month

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: