java.lang.NullPointerException: null

Spring JIRA | Benjamin M | 2 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    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

    Spring JIRA | 2 years ago | Benjamin M
    java.lang.NullPointerException: null
  2. 0

    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

    Spring JIRA | 2 years ago | Benjamin M
    java.lang.NullPointerException: null

    Root Cause Analysis

    1. java.lang.NullPointerException

      null

      at org.springframework.data.mongodb.core.convert.UpdateMapper.processTypeHintForNestedDocuments()
    2. Spring Data MongoDB - Core
      MongoTemplate.updateFirst
      1. org.springframework.data.mongodb.core.convert.UpdateMapper.processTypeHintForNestedDocuments(UpdateMapper.java:155)
      2. org.springframework.data.mongodb.core.convert.UpdateMapper.getTypeHintForEntity(UpdateMapper.java:145)
      3. org.springframework.data.mongodb.core.convert.UpdateMapper.delegateConvertToMongoType(UpdateMapper.java:70)
      4. org.springframework.data.mongodb.core.convert.QueryMapper.convertSimpleOrDBObject(QueryMapper.java:362)
      5. org.springframework.data.mongodb.core.convert.QueryMapper.getMappedValue(QueryMapper.java:308)
      6. org.springframework.data.mongodb.core.convert.UpdateMapper.getMappedObjectForField(UpdateMapper.java:93)
      7. org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:123)
      8. org.springframework.data.mongodb.core.convert.QueryMapper.convertSimpleOrDBObject(QueryMapper.java:359)
      9. org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:242)
      10. org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:100)
      11. org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:1095)
      12. org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:1086)
      13. org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:461)
      14. org.springframework.data.mongodb.core.MongoTemplate.doUpdate(MongoTemplate.java:1086)
      15. org.springframework.data.mongodb.core.MongoTemplate.updateFirst(MongoTemplate.java:1060)
      15 frames