dhis2 / dhis2-java-sdk

Java SDK for DHIS2
https://developers.dhis2.org/docs/integration/dhis2-java-sdk
BSD 3-Clause "New" or "Revised" License
7 stars 3 forks source link

Cannot invoke "java.util.List.iterator()" because "collection" is null #209

Open davsclaus opened 3 days ago

davsclaus commented 3 days ago

Caused by: java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because "collection" is null at org.hisp.dhis.integration.sdk.internal.operation.page.PageIterable.(PageIterable.java:73) at org.hisp.dhis.integration.sdk.internal.LazyIterableDhis2Response.returnAs(LazyIterableDhis2Response.java:58) at org.apache.camel.component.dhis2.api.Dhis2Get.collection(Dhis2Get.java:94) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at org.apache.camel.support.component.ApiMethodHelper.invokeMethod(ApiMethodHelper.java:521) ... 9 more

We have an issue with an integration test in Apache Camel for the camel-dhis component. There is a NPE due to collection is null, in the Java SDK. https://github.com/apache/camel/tree/main/components/camel-dhis2

It was claudemamo from your team that added the camel component. With a big of debugging it seems some jackson converter is returning null in your sdk code.

davsclaus commented 3 days ago

The response http body contains the following json structure

{
  "pager" : {
    "page" : 1,
    "total" : 2,
    "pageSize" : 50,
    "pageCount" : 1
  },
  "organisationUnits" : [ {
    "displayName" : "Acme",
    "id" : "bPe00y8Bb4q"
  }, {
    "displayName" : "EvilCorp",
    "id" : "ujFEhJeXDkA"
  } ]
}
davsclaus commented 3 days ago

Okay if I turn off paging, and use

            iteratorDhis2Response = getOperation.withoutPaging().transfer();
        return iteratorDhis2Response.returnAs(Dhis2Resource.class, arrayName).iterator();

Then it works. So it seems to be something in the lazy iterator