From c2f25962f119b494e35975b179ba7de3247d469f Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Wed, 15 Mar 2023 11:59:40 +0300 Subject: [PATCH 1/3] Fixes null pointer exception --- CHANGELOG.md | 2 ++ .../microsoft/graph/http/GraphErrorResponse.java | 4 ++-- .../graph/http/GraphErrorResponseTests.java | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) 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..41359d361 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) ? this.rawObject.deepCopy() : null; + responseCopy.error = (this.error != null) ? this.error.copy() : null; 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..452505572 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 + public 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); + } } From 13218d69cec2a739c90cb0b70a20bd6fee1bac2e Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 15 Mar 2023 10:35:07 -0400 Subject: [PATCH 2/3] Update src/main/java/com/microsoft/graph/http/GraphErrorResponse.java --- .../java/com/microsoft/graph/http/GraphErrorResponse.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/microsoft/graph/http/GraphErrorResponse.java b/src/main/java/com/microsoft/graph/http/GraphErrorResponse.java index 41359d361..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 != null) ? this.rawObject.deepCopy() : null; - responseCopy.error = (this.error != null) ? this.error.copy() : null; + responseCopy.rawObject = this.rawObject == null ? null : this.rawObject.deepCopy(); + responseCopy.error = this.error == null ? null : this.error.copy(); return responseCopy; } } From ae3e30bc603a638ce4e28fa3928beeeb772c732a Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 15 Mar 2023 10:38:00 -0400 Subject: [PATCH 3/3] Update src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java --- .../java/com/microsoft/graph/http/GraphErrorResponseTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java b/src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java index 452505572..059c430f8 100644 --- a/src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java +++ b/src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java @@ -62,7 +62,7 @@ public void testGraphErrorResponseCopy() { } @Test - public void testGraphErrorResponseCopy2() { + void testGraphErrorResponseCopy2() { GraphErrorResponse errorResponse = new GraphErrorResponse();; //Copy the errorResponse and its subsequent innerErrors