NullPointerException on ShapeFiles without dBase Table

Topics: Data Access, WinForms Controls
Dec 2, 2013 at 1:50 PM
By chance I found a rare case of a NullPointerException in the Shapefile class.
I opened a Shape file without a DBF file. According to the source code is checked presence of dbf file (see ShapeFile.cs:OpenDbfStream()). Should, however, lack the DBF file, the map is not drawn because in ShapeFile.cs:GetFeature(uint rowId, Feature DataTable dt) the dbfReader variable equals null. Would not it be better to check if dbfReader != null?

Line dt = dbfReader.NewTable; would crash.
public FeatureDataRow GetFeature(uint rowId, FeatureDataTable dt)
        {
            FeatureDataRow ret = null;
            using (Stream s = OpenShapefileStream())
            {
                using (BinaryReader br = new BinaryReader(s))
                {
                    using (DbaseReader dbfReader = OpenDbfStream())
                    {
                        if (dt == null)
                            dt = dbfReader.NewTable;
                        ret = getFeature(rowId, dt, br, dbfReader);
                        dbfReader.Close();
                    }
                    br.Close();
                }
                s.Close();
            }
            return ret;
        }
I admit that the case is likely to occur very rarely, but for the sake of completeness ...