Closed ALVIS-Software closed 2 years ago
cab you add a unit test (or at least some sample data) that reproduces the error?
looking at the code, before returning false
we should reset _columnValues
private member, probably.
Thank you for feedback. The error occures for empty shapefiles (0 features), where already the first read call will fail. That's why I added the return clause before trying to access features's attributes.
Can you post an unit test and some data to see what happens? This can be helpful
Please use this test case to reproduce bug and confirm my fix above. Put it it ShapeFileDataWriterTests.cs, line 55.
[Test]
public void TestWriteAndReadEmptyShapefile()
{
const string filename = "__empty";
TestCreateEmptyShapefile();
using (ShapefileDataReader shpReader = new ShapefileDataReader(filename, Factory))
{
var success = shpReader.Read();
Assert.Pass();
Assert.IsFalse(success);
}
}
It reuses one existing test that creates and empty file. Without my fix, the shpReader.Read();
will throw the NRE.
With fix applied, it will pass.
fixed with 477fd02a770ea72fd17766a290f686320f308a3d
https://github.com/NetTopologySuite/NetTopologySuite.IO.ShapeFile/blob/63dd59f2e1614a7e79dee780e0be001643ff892d/src/NetTopologySuite.IO.ShapeFile/ShapefileDataReader.FullFat.cs#L89
After checking the 2 read call results there is not return if one/both have return false. Adding 2 lines fixes a NRE in next call:
if (!_moreRecords) return false;