diff --git a/CHANGELOG.md b/CHANGELOG.md index f063d289d..8eebeec88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Fixes NullPointerException in GraphErrorResponse#copy + ## [2.0.16] - 2023-01-30 ### Changed diff --git a/src/main/java/com/microsoft/graph/http/GraphErrorResponse.java b/src/main/java/com/microsoft/graph/http/GraphErrorResponse.java index c14944bd6..13fff5e09 100644 --- a/src/main/java/com/microsoft/graph/http/GraphErrorResponse.java +++ b/src/main/java/com/microsoft/graph/http/GraphErrorResponse.java @@ -80,8 +80,8 @@ public final AdditionalDataManager additionalDataManager() { public GraphErrorResponse copy() { GraphErrorResponse responseCopy = new GraphErrorResponse(); responseCopy.additionalDataManager = this.additionalDataManager; - responseCopy.rawObject = this.rawObject.deepCopy(); - responseCopy.error = this.error.copy(); + responseCopy.rawObject = this.rawObject == null ? null : this.rawObject.deepCopy(); + responseCopy.error = this.error == null ? null : this.error.copy(); return responseCopy; } } diff --git a/src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java b/src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java index 8ec8e587b..059c430f8 100644 --- a/src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java +++ b/src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import org.junit.jupiter.api.Test; @@ -59,4 +60,18 @@ public void testGraphErrorResponseCopy() { assertEquals(errorResponse.rawObject, errorResponseCopy.rawObject); } + + @Test + void testGraphErrorResponseCopy2() { + GraphErrorResponse errorResponse = new GraphErrorResponse();; + + //Copy the errorResponse and its subsequent innerErrors + GraphErrorResponse errorResponseCopy = errorResponse.copy(); + + //Ensure default null values are copied without issue. + assertNull(errorResponseCopy.error); + assertNull(errorResponseCopy.rawObject); + + assertEquals(errorResponse.rawObject, errorResponseCopy.rawObject); + } }