Skip to content

Commit bebc1dc

Browse files
authored
Merge pull request #773 from microsoftgraph/andrueastman/fixCopyError
Fixes null pointer exception
2 parents 3911b58 + ae3e30b commit bebc1dc

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14+
- Fixes NullPointerException in GraphErrorResponse#copy
15+
1416
## [2.0.16] - 2023-01-30
1517

1618
### Changed

src/main/java/com/microsoft/graph/http/GraphErrorResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public final AdditionalDataManager additionalDataManager() {
8080
public GraphErrorResponse copy() {
8181
GraphErrorResponse responseCopy = new GraphErrorResponse();
8282
responseCopy.additionalDataManager = this.additionalDataManager;
83-
responseCopy.rawObject = this.rawObject.deepCopy();
84-
responseCopy.error = this.error.copy();
83+
responseCopy.rawObject = this.rawObject == null ? null : this.rawObject.deepCopy();
84+
responseCopy.error = this.error == null ? null : this.error.copy();
8585
return responseCopy;
8686
}
8787
}

src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
import static org.junit.jupiter.api.Assertions.assertNull;
56
import static org.mockito.Mockito.mock;
67

78
import org.junit.jupiter.api.Test;
@@ -59,4 +60,18 @@ public void testGraphErrorResponseCopy() {
5960

6061
assertEquals(errorResponse.rawObject, errorResponseCopy.rawObject);
6162
}
63+
64+
@Test
65+
void testGraphErrorResponseCopy2() {
66+
GraphErrorResponse errorResponse = new GraphErrorResponse();;
67+
68+
//Copy the errorResponse and its subsequent innerErrors
69+
GraphErrorResponse errorResponseCopy = errorResponse.copy();
70+
71+
//Ensure default null values are copied without issue.
72+
assertNull(errorResponseCopy.error);
73+
assertNull(errorResponseCopy.rawObject);
74+
75+
assertEquals(errorResponse.rawObject, errorResponseCopy.rawObject);
76+
}
6277
}

0 commit comments

Comments
 (0)