Skip to content

Loading a group crashes due to roleIdsToView being null #7

Description

@unshowered

I am attempting to load a group with the following code:

String groupId = ""; // Fill in a group ID here
GroupsApi groupsApi = new GroupsApi();
Group group = groupsApi.getGroup(groupId, false);

This crashes with the following exception:

Error: Expected the field `roleIdsToView` to be an array in the JSON string but got `null`
java.lang.IllegalArgumentException: Expected the field `roleIdsToView` to be an array in the JSON string but got `null`
	at io.github.vrchatapi.model.GroupGallery.validateJsonObject(GroupGallery.java:481)
	at io.github.vrchatapi.model.Group.validateJsonObject(Group.java:1218)
	at io.github.vrchatapi.model.Group$CustomTypeAdapterFactory$1.read(Group.java:1263)
	at io.github.vrchatapi.model.Group$CustomTypeAdapterFactory$1.read(Group.java:1253)
	at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:308)
	at com.google.gson.Gson.fromJson(Gson.java:1361)
	at com.google.gson.Gson.fromJson(Gson.java:1262)
	at com.google.gson.Gson.fromJson(Gson.java:1171)
	at com.google.gson.Gson.fromJson(Gson.java:1137)
	at io.github.vrchatapi.JSON.deserialize(JSON.java:340)
	at io.github.vrchatapi.ApiClient.deserialize(ApiClient.java:851)
	at io.github.vrchatapi.ApiClient.handleResponse(ApiClient.java:1061)
	at io.github.vrchatapi.ApiClient.execute(ApiClient.java:985)
	at io.github.vrchatapi.api.GroupsApi.getGroupWithHttpInfo(GroupsApi.java:2606)
	at io.github.vrchatapi.api.GroupsApi.getGroup(GroupsApi.java:2584)

Looking into this, it does appear that that field is marked as nullable in the specification: https://github.com/vrchatapi/specification/blob/main/openapi/components/schemas/GroupGallery.yaml#L21

and the raw response from the server looks like this:

{
"roleIdsToView": null,
}

Inspecting the generated code and setting a breakpoint leads me to this generated code snippet:

      // ensure the optional json data is an array if present
      if (jsonObj.get("roleIdsToView") != null && !jsonObj.get("roleIdsToView").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `roleIdsToView` to be an array in the JSON string but got `%s`", jsonObj.get("roleIdsToView").toString()));
      }

Setting a breakpoint on the throw line reveals that jsonObj.get("roleIdsToView") is not set to null, but to JsonNull:
Image

causing the check for null to fail and the code to crash. I'm assuming this would affect other nullable fields as well; is there a flag or something that needs to be changed with the codegen to fix this?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type: BugThere is a **factual incorrectness** in the spec

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions