Skip to content

Commit 739b59e

Browse files
committed
- fixes a bug where passing null to additional data manager could lead to a null ref excep
1 parent 11397dc commit 739b59e

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/main/java/com/microsoft/graph/serializer/AdditionalDataManager.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// ------------------------------------------------------------------------------
22
// Copyright (c) 2017 Microsoft Corporation
3-
//
3+
//
44
// Permission is hereby granted, free of charge, to any person obtaining a copy
55
// of this software and associated documentation files (the "Software"), to deal
66
// in the Software without restriction, including without limitation the rights
77
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
88
// copies of the Software, and to permit persons to whom the Software is
99
// furnished to do so, subject to the following conditions:
10-
//
10+
//
1111
// The above copyright notice and this permission notice shall be included in
1212
// all copies or substantial portions of the Software.
13-
//
13+
//
1414
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1515
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1616
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -38,12 +38,12 @@
3838
public class AdditionalDataManager extends HashMap<String, JsonElement> {
3939

4040
private static final long serialVersionUID = 8641634955796941429L;
41-
41+
4242
private final transient IJsonBackedObject jsonBackedObject;
4343

4444
/**
4545
* Instanciates a new additional data manager from the json backed object
46-
*
46+
*
4747
* @param jsonBackedObject the object to read values from
4848
*/
4949
public AdditionalDataManager(@Nullable final IJsonBackedObject jsonBackedObject) {
@@ -56,15 +56,15 @@ public AdditionalDataManager(@Nullable final IJsonBackedObject jsonBackedObject)
5656
*
5757
* @param json the raw JSON to set as additionalData
5858
*/
59-
final void setAdditionalData(JsonObject json) {
59+
final void setAdditionalData(final JsonObject json) {
6060
// Get the names of all the fields on this object's hierarchy
61-
Set<String> objectFields = getFields();
61+
final Set<String> objectFields = getFields();
6262

6363
// Get the keys on this JSON
64-
Set<String> jsonKeys = getJsonKeys(json);
64+
final Set<String> jsonKeys = getJsonKeys(json);
6565

6666
// Get all keys present in JSON and *NOT* present in fields
67-
Set<String> additionalDataKeys = new HashSet<>(jsonKeys);
67+
final Set<String> additionalDataKeys = new HashSet<>(jsonKeys);
6868
additionalDataKeys.removeAll(objectFields);
6969

7070
// set the additionalData
@@ -73,23 +73,25 @@ final void setAdditionalData(JsonObject json) {
7373
}
7474
}
7575

76-
private Set<String> getJsonKeys(JsonObject json) {
77-
Set<String> keys = new HashSet<>();
78-
Set<Map.Entry<String, JsonElement>> entries = json.entrySet();
76+
private Set<String> getJsonKeys(final JsonObject json) {
77+
final Set<String> keys = new HashSet<>();
78+
final Set<Map.Entry<String, JsonElement>> entries = json.entrySet();
7979
for (Map.Entry<String, JsonElement> entry : entries) {
8080
keys.add(entry.getKey());
8181
}
8282
return keys;
8383
}
8484

8585
private Set<String> getFields() {
86-
Field[] fields = jsonBackedObject.getClass().getFields();
87-
Set<String> serializingFields = new HashSet<>();
88-
for (Field field : fields) {
89-
SerializedName serializedName;
90-
if (null != (serializedName = field.getAnnotation(SerializedName.class))
91-
&& null != field.getAnnotation(Expose.class)) {
92-
serializingFields.add(serializedName.value());
86+
final Set<String> serializingFields = new HashSet<>();
87+
if(jsonBackedObject != null ) {
88+
final Field[] fields = jsonBackedObject.getClass().getFields();
89+
for (Field field : fields) {
90+
final SerializedName serializedName = field.getAnnotation(SerializedName.class);
91+
if (null != serializedName
92+
&& null != field.getAnnotation(Expose.class)) {
93+
serializingFields.add(serializedName.value());
94+
}
9395
}
9496
}
9597
return serializingFields;

0 commit comments

Comments
 (0)