Skip to content

NullPointerException in GraphErrorResponse#copy  #697

@celcius112

Description

@celcius112

Expected behavior

Using microsoft-graph 5.42.0 I would not expect to have an NPE when calling GraphServiceException#getError

Actual behavior

An NPE is thrown when retrieving the error returned by the service

Calling GraphServiceException#getError will do a deep copy of the underlying GraphErrorResponse:

   public GraphErrorResponse getError() {
        return this.error.copy();
    }

The copy() method does not take into account that two of its instance variables are nullable, namely rawObject and error

    public GraphErrorResponse copy() {
        GraphErrorResponse responseCopy = new GraphErrorResponse();
        responseCopy.additionalDataManager = this.additionalDataManager;
        responseCopy.rawObject = this.rawObject.deepCopy();
        responseCopy.error = this.error.copy();
        return responseCopy;
    }

Here's the stacktrace:

java.lang.NullPointerException: null
	at com.microsoft.graph.http.GraphErrorResponse.copy(GraphErrorResponse.java:83)
	at com.microsoft.graph.http.GraphServiceException.getError(GraphServiceException.java:215)

With the raw message being:

com.microsoft.graph.http.GraphServiceException: Error code: Unable to parse error response message
Error message: Raw error: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid URL</h2>
<hr><p>HTTP Error 400. The request URL is invalid.</p>
</BODY></HTML>

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions