Announcement Announcement Module
Collapse
No announcement yet.
NullPointerException MappingMongoConverter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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?

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Attachment
        Attachment
        Attachment

        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 Files
        Last edited by marcovmx; Feb 13th, 2012, 01:34 PM.

        Comment


        • #5
          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?

          Comment


          • #6
            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.

            Comment


            • #7
              I see...

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

              Thanks!

              Comment

              Working...
              X