Results 1 to 7 of 7

Thread: NullPointerException MappingMongoConverter

  1. #1
    Join Date
    Aug 2011
    Location
    Mexico City / Atlanta GA
    Posts
    30

    Default NullPointerException MappingMongoConverter

    Hi,

    I am working with spring mongodb (1.0.0.RELEASE) and spring webflow, I am getting a null pointer exception:

    Code:
    java.lang.NullPointerException: null
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeMapInternal(MappingMongoConverter.java:535) ~[spring-data-mongodb-1.0.0.RELEASE.jar:na]
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:319) ~[spring-data-mongodb-1.0.0.RELEASE.jar:na]
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeMapInternal(MappingMongoConverter.java:547) ~[spring-data-mongodb-1.0.0.RELEASE.jar:na]
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:407) ~[spring-data-mongodb-1.0.0.RELEASE.jar:na]
    Looking at that line in MappingMongoConverter.writeMapInternal the exception occurs in:
    Code:
     if (conversions.isSimpleType(key.getClass())) {
    Spring is trying to convert a null Map {null=[]}. That object is contained into a spring webflow messagesMemento object, which means I don't have control over it.

    It seems this is a bug. I will be reporting it shortly.

    Grettings,
    Marco

  2. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    492

    Default

    Besides the fact that an NPE is quite ugly here, are you saying you (or Webflow) pipe in a Map containing an entry with a null key? How shall we actually persist that one to Mongo. Just thinking about it briefly we actually either have to skip this attribute - which is not what I'd call principle of least surprise - or throw an exception rendering the entire object graph unmappable. What do you think?

  3. #3
    Join Date
    Aug 2011
    Location
    Mexico City / Atlanta GA
    Posts
    30

    Default

    Hi Oliver,

    are you saying you (or Webflow) pipe in a Map containing an entry with a null key?
    Yes, Webflow does it. I think throwing a more meaningful exception would help to quickly identify the problem without having to look the source code, though the occurrence of this scenario might be very low . I currently worked around it by skipping the object containing the map through my custom ConversationManager (a Webflow object), it is still under test and hope it does not have a side effect. Moreover, a better solution would come from the Webflow guys by inquiring the reason of that null key entry in the map.

    Thanks,
    Marco

  4. #4
    Join Date
    Aug 2011
    Location
    Mexico City / Atlanta GA
    Posts
    30

    Default

    Hi,

    I am facing a different issue now,

    My object to persist has an association of type org.springframework.webflow.execution.repository.i mpl.SimpleFlowExecutionSnapshotGroup, that has a property "private Map snapshots = new HashMap();".

    The code flow goes all the way through CachingMongoPersistentProperty(AbstractPersistentP roperty<P>).isEntity() to evaluate if the snapshots property is of a simple type. It turns out information.getActualType() returns null, causing getType() to break. See attached image for more details.

    npe-SpringMongo1.jpg
    npe-SpringMongo2.jpg
    npe-SpringMongo3.jpg

    In my ivy.xml I have:
    <dependency org="org.springframework.data" name="spring-data-mongodb" rev="1.0.0.RELEASE" />
    <dependency org="org.springframework.data" name="spring-data-commons-core" rev="1.2.0.RELEASE" />
    Attached Images Attached Images
    Last edited by marcovmx; Feb 13th, 2012 at 01:34 PM.

  5. #5
    Join Date
    Aug 2011
    Location
    Mexico City / Atlanta GA
    Posts
    30

    Default

    My temporary solution is changing:

    Code:
    	protected boolean isEntity() {
    		boolean isComplexType = true;
    		isComplexType = !simpleTypeHolder.isSimpleType(information.getActualType().getType());
    		return isComplexType && !isTransient() && !isCollectionLike() && !isMap();
    	}
    for:

    Code:
    	protected boolean isEntity() {
    		boolean isComplexType = true;
    		if (!isMap()) {
    			isComplexType = !simpleTypeHolder.isSimpleType(information.getActualType().getType());
    		}
    		return isComplexType && !isTransient() && !isCollectionLike();
    	}
    Not optimal but it's a pain reliever. 'information.getActualType()' returning null for a HashMap sound like a bug to me. What do you think?

  6. #6
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    492

    Default

    I'd rather say it's a bug in isEntity(). The reason we return null from a variety of methods in the TypeInformation hierarchy is that we'd like to be able to discover whether a type actually carries generic parameters or not in a variety of places. If we simply returned Object for that call there was no way to differentiate a Map from a Map<Object, Object>. Feel free to raise a Jira against Spring Data Commons.

  7. #7
    Join Date
    Aug 2011
    Location
    Mexico City / Atlanta GA
    Posts
    30

    Default

    I see...

    Jira created: https://jira.springsource.org/browse/DATACMNS-132

    Thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •