Skip to content
This repository was archived by the owner on Oct 23, 2020. It is now read-only.
This repository was archived by the owner on Oct 23, 2020. It is now read-only.

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

@erwindl0

Description

@erwindl0

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().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions