Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

NullPointerException in sOgrInput with NULL geometries #3

Closed
etdube opened this issue Sep 28, 2012 · 1 comment
Closed

NullPointerException in sOgrInput with NULL geometries #3

etdube opened this issue Sep 28, 2012 · 1 comment
Labels
Milestone

Comments

@etdube
Copy link

etdube commented Sep 28, 2012

I've encountered an issue while using the sOgrInput component in a job, when trying to read a MapInfo TAB file containing a NULL geometry. The job fails with a NullPointerException when reading the offending record. NULL geometries are a admittedly an uncommon and odd occurrence, but in this case I have no control over the TAB file contents.

I've been able to work around the problem and pass a NULL value by modifying the component's sOgrInput_begin.javajet code, to check when the call to org.gdal.ogr.Feature.GetGeometryRef() returns null and pass a null value instead of trying to invoke the ExportToWkt() method on the null ogrGeometry (and skip assigning the SRID as well).

Please find a patch with the fix below.


.../components/sOgrInput/sOgrInput_begin.javajet              | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/org.talend.sdi.designer.components.sandbox/components/sOgrInput/sOgrInput_begin.javajet b/org.talend.sdi.designer.components.sandbox/components/sOgrInput/sOgrInput_begin.javajet
index 9a23ea5..c71c259 100755
--- a/org.talend.sdi.designer.components.sandbox/components/sOgrInput/sOgrInput_begin.javajet
+++ b/org.talend.sdi.designer.components.sandbox/components/sOgrInput/sOgrInput_begin.javajet
@@ -169,10 +169,13 @@ while ((poFeature_<%=cid %> = poLayer_<%=cid %>.GetNextFeature()) != null) {

                             if (typeToGenerate.equals("Geometry")) {
%>
-    org.talend.sdi.geometry.Geometry geometry_<%=cid %> =
-        new org.talend.sdi.geometry.Geometry(
-            poFeature_<%=cid %>.GetGeometryRef().ExportToWkt());
-    geometry_<%=cid %>.setSRID(pszWKT_<%=cid %>);
+    org.gdal.ogr.Geometry ogrGeometry = poFeature_<%=cid %>.GetGeometryRef();
+    org.talend.sdi.geometry.Geometry geometry_<%=cid %> = ogrGeometry != null ?
+        new org.talend.sdi.geometry.Geometry(ogrGeometry.ExportToWkt()) : null;
+
+    if (geometry_<%=cid %> != null) {
+        geometry_<%=cid %>.setSRID(pszWKT_<%=cid %>);
+    }
     <%=conn.getName() %>.<%=column.getLabel() %> = geometry_<%=cid %>;
<%                                   
                             } else if (typeToGenerate.equals("String")) {
fxprunayre pushed a commit that referenced this issue Sep 30, 2012
@fxprunayre
Copy link
Member

Patch applied with a minor change to avoid variable name collision ogrGeometry_<%=cid %> which may happen when 2 components of same type are used in the same job. Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants