impetus-opensource/Kundera — Issue #28: Error in DocumentIndexer
Author: zenbones
Created: 2012-01-25 21:53:21+00:00
State: open

In the code below, if the value is null, then .toString() is going to blow up with a null pointer exception and never reach the LOG.warn(). Null fields are certainly going to occur, so should there be a better way of handling this? Some way of indexing null values (a database does).

private void addFieldToDocument(Object object, Document document, java.lang.reflect.Field field, String colName,
String indexName)
{
try
{
String value = PropertyAccessorHelper.getObject(object, field).toString();
if (value != null)
{
Field luceneField = new Field(getCannonicalPropertyName(indexName, colName), value, Field.Store.YES,
Field.Index.ANALYZED_NO_NORMS);
document.add(luceneField);
}
else
{
LOG.warn("value is null for field" + field.getName());
}
}
catch (PropertyAccessException e)
{
LOG.error("Error in accessing field:" + e.getMessage());
}
}