impetus-opensource/Kundera — Issue #19: NullPointerException if some field of Entity are not filled
Author: rsinelle
Created: 2012-01-04 20:35:03+00:00
State: open

Tested on 2.0.4.

I have on Entityt with different type of field: Long, Date. I try to store this entity with junit test

If the field with Long type is null,the exception is
java.lang.NullPointerException
at com.impetus.kundera.property.accessor.LongAccessor.toBytes(LongAccessor.java:47)
at com.impetus.kundera.property.PropertyAccessorHelper.get(PropertyAccessorHelper.java:169)
at com.impetus.client.cassandra.pelops.PelopsDataHandler.addColumnsToThriftRow(PelopsDataHandler.java:481)
at com.impetus.client.cassandra.pelops.PelopsDataHandler.toThriftRow(PelopsDataHandler.java:454)
at com.impetus.client.cassandra.pelops.PelopsClient.populateTfRow(PelopsClient.java:479)
at com.impetus.client.cassandra.pelops.PelopsClient.persist(PelopsClient.java:344)

If the field with Date type is null, the exception is :
java.lang.NullPointerException
at com.impetus.kundera.index.DocumentIndexer.addFieldToDocument(DocumentIndexer.java:275)
at com.impetus.kundera.index.DocumentIndexer.addEntityFieldsToDocument(DocumentIndexer.java:206)
at com.impetus.kundera.index.LuceneIndexer.indexDocument(LuceneIndexer.java:534)
at com.impetus.kundera.index.LuceneIndexer.index(LuceneIndexer.java:196)
at com.impetus.kundera.index.IndexManager.write(IndexManager.java:104)

If the field with Integer type is null, the exception is :
java.lang.NullPointerException
at com.impetus.kundera.property.accessor.IntegerAccessor.toBytes(IntegerAccessor.java:43)
at com.impetus.kundera.property.PropertyAccessorHelper.get(PropertyAccessorHelper.java:169)
at com.impetus.client.cassandra.pelops.PelopsDataHandler.addColumnsToThriftRow(PelopsDataHandler.java:481)
at com.impetus.client.cassandra.pelops.PelopsDataHandler.toThriftRow(PelopsDataHandler.java:454)
at com.impetus.client.cassandra.pelops.PelopsClient.populateTfRow(PelopsClient.java:479)
at com.impetus.client.cassandra.pelops.PelopsClient.persist(PelopsClient.java:344)

It work with String type only because you have surronded with try catch (exception)

And another point, please remove e.printStackTrace(); line 40 of StringAccessor class