This is an automated email from the ASF dual-hosted git repository.

jsorel pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 5077c372fd Fix shapefile DBF field parsing, tolerate character 
patterns as missing number values
5077c372fd is described below

commit 5077c372fd40972b6153593b2a3d4a3d0314cdde
Author: jsorel <johann.so...@geomatys.com>
AuthorDate: Tue Jun 25 12:02:53 2024 +0200

    Fix shapefile DBF field parsing, tolerate character patterns as missing 
number values
---
 .../apache/sis/storage/shapefile/dbf/DBFField.java | 38 +++++++++++++++++++---
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git 
a/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/dbf/DBFField.java
 
b/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/dbf/DBFField.java
index 341b4d4a86..ebea49f5d0 100644
--- 
a/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/dbf/DBFField.java
+++ 
b/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/dbf/DBFField.java
@@ -245,20 +245,50 @@ public final class DBFField {
 
     private Object readNumber(ChannelDataInput channel) throws IOException {
         final String str = new String(channel.readBytes(fieldLength)).trim();
-        if (str.isEmpty()) return 0L;
-        else return Double.parseDouble(str);
+        if (str.isEmpty()) return 0.0;
+        try {
+            return Double.valueOf(str);
+        } catch (NumberFormatException ex) {
+            /**
+             * We have encounter various files where null values of numbers 
are encoded
+             * as filled strings of * or - characters.
+             * DBF isn't clear on this, being an old format with many versions 
and variants
+             * we are tolerant
+             */
+            return 0.0;
+        }
     }
 
     private Object readNumberInt(ChannelDataInput channel) throws IOException {
         final String str = new String(channel.readBytes(fieldLength)).trim();
         if (str.isEmpty()) return 0;
-        else return Integer.parseInt(str);
+        try {
+            return Integer.valueOf(str);
+        } catch (NumberFormatException ex) {
+            /**
+             * We have encounter various files where null values of numbers 
are encoded
+             * as filled strings of * or - characters.
+             * DBF isn't clear on this, being an old format with many versions 
and variants
+             * we are tolerant
+             */
+            return 0;
+        }
     }
 
     private Object readNumberLong(ChannelDataInput channel) throws IOException 
{
         final String str = new String(channel.readBytes(fieldLength)).trim();
         if (str.isEmpty()) return 0L;
-        else return Long.parseLong(str);
+        try {
+            return Long.parseLong(str);
+        } catch (NumberFormatException ex) {
+            /**
+             * We have encounter various files where null values of numbers 
are encoded
+             * as filled strings of * or - characters.
+             * DBF isn't clear on this, being an old format with many versions 
and variants
+             * we are tolerant
+             */
+            return 0L;
+        }
     }
 
     private Object readLogic(ChannelDataInput channel) throws IOException {

Reply via email to