{"record":{"id":"96b232d3c0752387","repo":"pentaho/pentaho-kettle","slug":"error-reading-shape-file","errorCode":null,"errorMessage":"Error reading shape file","messagePattern":"Error reading shape file","errorType":"exception","errorClass":"GisException","httpStatus":null,"severity":"error","filePath":"plugins/shapefilereader/core/src/main/java/org/pentaho/gis/shapefiles/ShapeFile.java","lineNumber":158,"sourceCode":"              throw new GisException( \"shape type : \" + btype + \" not recognized! (\" + Shape.getEsriTypeDesc( btype ) + \")\" );\n          }\n\n          // Get a row from the associated DBF file...\n          Object[] row = xbase.getRow( fields );\n          if ( row != null ) {\n            esi.setDbfData( row );\n            esi.setDbfMeta( xbase.getFields() );\n          }\n\n          shapes.add( esi );\n          id++;\n        }\n      }\n\n      dis.close();\n      xbase.close();\n    } catch ( IOException e ) {\n      throw new GisException( \"Error reading shape file\", e );\n    }\n  }\n\n  public int getNrShapes() {\n    return shapes.size();\n  }\n\n  public ShapeInterface getShape( int i ) {\n    return shapes.get( i );\n  }\n\n  public void addShape( ShapeInterface esi ) {\n    shapes.add( esi );\n  }\n\n  public ShapeFileHeader getFileHeader() {\n    return fileheader;\n  }","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/shapefilereader/core/src/main/java/org/pentaho/gis/shapefiles/ShapeFile.java#L140-L176","documentation":"ShapeFile.readFile wraps any IOException from reading the .shp stream or the XBase DBF rows into a GisException 'Error reading shape file'. It is a generic I/O failure while walking shape records, after the file was opened successfully.","triggerScenarios":"The DataInputStream over the .shp hits EOF early (truncated file), a disk/network read fails, or xbase.getRow throws an IOException while pairing DBF rows with shapes.","commonSituations":"Incomplete downloads/copies of the .shp, files with mismatched .shp/.dbf record counts, network-mounted shapefiles with dropped connections, or corrupt headers claiming more bytes than exist.","solutions":["Verify the .shp file size against the length recorded in its 100-byte main header; re-download/re-copy if truncated.","Ensure .shp and .dbf record counts match (use a shapefile validator such as shpcheck or ogrinfo).","Copy the shapefile set to local disk instead of reading over the network.","Check the wrapped IOException cause for the exact read failure."],"exampleFix":"// before\nFileInputStream in = new FileInputStream( \"/mnt/net/data.shp\" ); // network drop mid-read\n// after\nFile local = new File( \"/tmp/data.shp\" );\nFiles.copy( Paths.get( \"/mnt/net/data.shp\" ), local.toPath() ); // full local copy first\nFileInputStream in = new FileInputStream( local );","handlingStrategy":"validation","validationCode":"File shp = new File( path );\ntry ( RandomAccessFile raf = new RandomAccessFile( shp, \"r\" ) ) {\n  byte[] h = new byte[100]; raf.readFully( h );\n  long expected = Integer.reverseBytes( ByteBuffer.wrap( h ).getInt( 24 ) ) * 2L;\n  if ( shp.length() < expected ) throw new IllegalStateException( \".shp truncated: \" + shp.length() + \" < \" + expected );\n}","typeGuard":null,"tryCatchPattern":"try {\n  shapeFile.readFile();\n} catch ( GisException e ) {\n  if ( e.getCause() instanceof IOException ) {\n    log.error( \"I/O failure reading shapefile, re-fetch the file\", e );\n  }\n}","preventionTips":["Verify file integrity (size vs header-declared length) before reading.","Copy shapefiles from network shares to local disk first.","Keep .shp and .dbf record counts in sync; validate with ogrinfo."],"tags":["shapefile","io","file-read","gis"],"backgroundTag":"file-read-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}