Spring Social Facebook
  1. Spring Social Facebook
  2. SOCIALFB-75

FqlResult.getList(String fieldName, FqlResultMapper<T> mapper) throws null pointer when field value is null

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 1.1.0.RELEASE
    • Fix Version/s: 1.1.0.M1
    • Component/s: API Binding
    • Labels:
      None
    • Environment:
      using spring social FB library 1.1.0-release, snapshot from April 2, 2012

      Description

      Using FQL to access the stream table, many of the json elements return are null at times.
      if you call FqlResult.getList(String fieldName, FqlResultMapper<T> mapper) with a field that exists, but is null, a null pointer exception will be thrown:

      java.lang.NullPointerException
      at org.springframework.social.facebook.api.FqlResult.getList(FqlResult.java:163)
      at com.inqmobile.inqcloud.domain.facebook.FbStreamItemMapper.mapObject(FbStreamItemMapper.java:58)
      at com.inqmobile.inqcloud.domain.facebook.FbStreamItemMapper.mapObject(FbStreamItemMapper.java:1)
      at org.springframework.social.facebook.api.impl.FqlTemplate.query(FqlTemplate.java:48)

      which corresponds to
      List<Map<String, Object>> arrayItems = (List<Map<String, Object>>) resultMap.get(fieldName);
      for (Map<String, Object> arrayItem : arrayItems) { ~~~~~ this line ~~~~~
      response.add(mapper.mapObject(new FqlResult(arrayItem)));
      }

      Expected behavior is to return null if the json value is null.

      https://graph.facebook.com/fql?q=SELECT post_id, message, action_links FROM stream WHERE source_id=100002487294420 LIMIT 1
      returns
      { "data": [

      { "post_id": "100002487294420_404871966208922", "message": "Robert Blair http://sphotos.xx.fbcdn.net/hphotos-ash4/s320x320/375127_183841518401962_100003283444808_309767_1436664147_n.jpg wat is dat! ", "action_links": null }

      ]
      }

      note that other getXYZ calls throw null pointer or number format exceptions if the value is null, as opposed to not present.
      Facebook fql will sometimes return null for values documented as type 'int'
      I would like the ability to call getLong without first checking if the original result is null.
      Might also want to expose resultMap.containsKey() on the FqlResult class too.

        Activity

        Hide
        Craig Walls added a comment -

        Added hasValue() and hasField() methods to FqlResult and also check for non-null values in all getter methods before evaluating to a specific type.

        Show
        Craig Walls added a comment - Added hasValue() and hasField() methods to FqlResult and also check for non-null values in all getter methods before evaluating to a specific type.
        Hide
        Robert Blair added a comment -

        Thanks. I'll let you know if I find problems with it.

        Show
        Robert Blair added a comment - Thanks. I'll let you know if I find problems with it.

          People

          • Assignee:
            Craig Walls
            Reporter:
            Robert Blair
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: