albfernandez / javadbf

Java library for reading and writing Xbase (dBase/DBF) files.
GNU Lesser General Public License v3.0
220 stars 98 forks source link

DBFReader: row.getString() does not return null for NULL MEMO field #121

Closed HelmutL closed 6 months ago

HelmutL commented 6 months ago

If a MEMO field is null, reading it by getString() does not deliver a null but a shrt String containing binary zeros.

Bug: DBFReader.readMemoField() should test nBlock against 0 instead of null

    Number nBlock =  null;
    if (field.getLength() == 10) {
        nBlock = DBFUtils.readNumericStoredAsText(this.dataInputStream, field.getLength());
    }
    else {
        nBlock = DBFUtils.readLittleEndianInt(this.dataInputStream);
    }
    if (this.memoFile != null && /* nBlock != null*/ nBlock.intValue() != 0) {
        DBFDataType type = field.getType();
        if (type == DBFDataType.MEMO && fieldsAsBinary.contains(field.getName().toUpperCase())) {
            type = DBFDataType.BINARY;
        }
        return memoFile.readData(nBlock.intValue(), type);
    }
    return null;
albfernandez commented 6 months ago

Thanks for the issue.

Fixed, checking for null (just in case) and nBlock being a positive value.