msgraph-sdk-java icon indicating copy to clipboard operation
msgraph-sdk-java copied to clipboard

NullPointerException due to different capitalization

Open feucht opened this issue 1 year ago • 2 comments

Actual behavior

CoreHttpProvider.java

final Map<String, String> headers = CoreHttpProvider.getResponseHeadersAsMapStringString(response);
//{content-type=application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8}

final String contentType = headers.get(Constants.CONTENT_TYPE_HEADER_NAME); //value of constant is "Content-Type"
//looking for key "Content-Type", although is actually "content-type"
if (contentType.contains(Constants.JSON_CONTENT_TYPE)) { //NullPointerException because contentType is null

Expected behavior

CoreHttpProvider.java

final Map<String, String> headers = CoreHttpProvider.getResponseHeadersAsMapStringString(response);
//{content-type=application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8}

final String contentType = headers.get(Constants.CONTENT_TYPE_HEADER_NAME); //value of constant should be "content-type"

if (contentType.contains(Constants.JSON_CONTENT_TYPE)) { //results in true

Steps to reproduce the behavior

Doing any API requests starting from version 1.5.0 until 2.10.0.

feucht avatar Mar 12 '24 15:03 feucht

Hi @feucht Thank you for using the Java SDK and for reaching out. The change in casing is due to the deployment of http/2 on the service side. These versions of the SDK are old, out of support and we recommend everyone to upgrade to v6.X if they can. In the meantime, version 2.10 should be an intermediate stop that doesn't have the issue. Let us know if you have any further questions.

baywet avatar Mar 12 '24 16:03 baywet

Thank you very much for your help! That solved our problem. I appreciate your time and effort in assisting me.

feucht avatar Mar 13 '24 13:03 feucht

This issue has been marked as duplicate and has not had any activity for 1 day. It will be closed for housekeeping purposes.