jxapi icon indicating copy to clipboard operation
jxapi copied to clipboard

NPE in Group.serialize() when no members are set in statement

Open erwindl0 opened this issue 5 years ago • 0 comments

I'm sending a XAPI statement with a team specified in the context.

According to the spec, a Group does not need to contain its memberlist (ico identified groups at least) : https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#2422-when-the-actor-objecttype-is-group

So I'm sending something as for example :

  "team": {
   "objectType": "Group",
   "name": "AR2",
   "account": {
    "name": "123",
    "homePage": "https://www.example.com/groups/"
   }
  }

This is parsed by jxapi in a Group instance with uninitialized member collection (i.e. null).

When for whatever reason you want to serialize the received statement again, Group.serialize() throws an NPE. The related code is:

public JsonElement serialize() {
		JsonObject obj = (JsonObject) super.serialize();
		JsonArray members = new JsonArray();
		for (Agent agent : this.member) {
			members.add(agent.serialize());
		}
		obj.add("member", members);
		return obj;
	}

There's no null check on this.member, contrary to eg the code in gov.adlnet.xapi.model.Context.serialize().

erwindl0 avatar Sep 10 '20 15:09 erwindl0