java.lang.NullPointerException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Following code throws a NullPointerException: {code} mongoOperations.updateFirst( new Query(), new Update().set("date", null), TestEntity.class ); {code} Where {{TestEntity}} simply this: {code} @Document(collection="test") public class TestEntity { @Id private String id; public String getId() { return id; } private LocalDate date; public LocalDate getDate() { return date; } public void setDate(LocalDate date) { this.date = date; } } {code} StackTrace: {code} java.lang.NullPointerException: null at org.springframework.data.mongodb.core.convert.UpdateMapper.processTypeHintForNestedDocuments(UpdateMapper.java:155) at org.springframework.data.mongodb.core.convert.UpdateMapper.getTypeHintForEntity(UpdateMapper.java:145) at org.springframework.data.mongodb.core.convert.UpdateMapper.delegateConvertToMongoType(UpdateMapper.java:70) at org.springframework.data.mongodb.core.convert.QueryMapper.convertSimpleOrDBObject(QueryMapper.java:362) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedValue(QueryMapper.java:308) at org.springframework.data.mongodb.core.convert.UpdateMapper.getMappedObjectForField(UpdateMapper.java:93) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:123) at org.springframework.data.mongodb.core.convert.QueryMapper.convertSimpleOrDBObject(QueryMapper.java:359) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:242) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:100) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:1095) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:1086) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:461) at org.springframework.data.mongodb.core.MongoTemplate.doUpdate(MongoTemplate.java:1086) at org.springframework.data.mongodb.core.MongoTemplate.updateFirst(MongoTemplate.java:1060) {code} Using {{mongoOperations.save / insert}} works as expected. And using field of type String works as well. I tried to debug it, but I can't figure out why this happens. It looks like it treats {{LocalDate}} as a {{MongoPersistentEntity}}, but it doesn't do that for a {{String}} ?! I also tried to provide my own Converter for {{LocalDate}} to {{Date}} and backwords, but this results in the same exception. Here's the full code: http://pastebin.com/xEq54Umh And pom.xml: http://pastebin.com/wDhWzx8s It also happens with mongo-java-driver 2.12.5 and/or spring-data-mongodb 1.6.3
    via by Benjamin M,
  • Following code throws a NullPointerException: {code} mongoOperations.updateFirst( new Query(), new Update().set("date", null), TestEntity.class ); {code} Where {{TestEntity}} simply this: {code} @Document(collection="test") public class TestEntity { @Id private String id; public String getId() { return id; } private LocalDate date; public LocalDate getDate() { return date; } public void setDate(LocalDate date) { this.date = date; } } {code} StackTrace: {code} java.lang.NullPointerException: null at org.springframework.data.mongodb.core.convert.UpdateMapper.processTypeHintForNestedDocuments(UpdateMapper.java:155) at org.springframework.data.mongodb.core.convert.UpdateMapper.getTypeHintForEntity(UpdateMapper.java:145) at org.springframework.data.mongodb.core.convert.UpdateMapper.delegateConvertToMongoType(UpdateMapper.java:70) at org.springframework.data.mongodb.core.convert.QueryMapper.convertSimpleOrDBObject(QueryMapper.java:362) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedValue(QueryMapper.java:308) at org.springframework.data.mongodb.core.convert.UpdateMapper.getMappedObjectForField(UpdateMapper.java:93) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:123) at org.springframework.data.mongodb.core.convert.QueryMapper.convertSimpleOrDBObject(QueryMapper.java:359) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:242) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:100) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:1095) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:1086) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:461) at org.springframework.data.mongodb.core.MongoTemplate.doUpdate(MongoTemplate.java:1086) at org.springframework.data.mongodb.core.MongoTemplate.updateFirst(MongoTemplate.java:1060) {code} Using {{mongoOperations.save / insert}} works as expected. And using field of type String works as well. I tried to debug it, but I can't figure out why this happens. It looks like it treats {{LocalDate}} as a {{MongoPersistentEntity}}, but it doesn't do that for a {{String}} ?! I also tried to provide my own Converter for {{LocalDate}} to {{Date}} and backwords, but this results in the same exception. Here's the full code: http://pastebin.com/xEq54Umh And pom.xml: http://pastebin.com/wDhWzx8s It also happens with mongo-java-driver 2.12.5 and/or spring-data-mongodb 1.6.3
    via by Benjamin M,
    • java.lang.NullPointerException: null at org.springframework.data.mongodb.core.convert.UpdateMapper.processTypeHintForNestedDocuments(UpdateMapper.java:155) at org.springframework.data.mongodb.core.convert.UpdateMapper.getTypeHintForEntity(UpdateMapper.java:145) at org.springframework.data.mongodb.core.convert.UpdateMapper.delegateConvertToMongoType(UpdateMapper.java:70) at org.springframework.data.mongodb.core.convert.QueryMapper.convertSimpleOrDBObject(QueryMapper.java:362) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedValue(QueryMapper.java:308) at org.springframework.data.mongodb.core.convert.UpdateMapper.getMappedObjectForField(UpdateMapper.java:93) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:123) at org.springframework.data.mongodb.core.convert.QueryMapper.convertSimpleOrDBObject(QueryMapper.java:359) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:242) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:100) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:1095) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:1086) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:461) at org.springframework.data.mongodb.core.MongoTemplate.doUpdate(MongoTemplate.java:1086) at org.springframework.data.mongodb.core.MongoTemplate.updateFirst(MongoTemplate.java:1060)
    No Bugmate found.