Skip to content

Commit 2ceeb63

Browse files
BerndSchullergolbi
authored andcommitted
fix nullpointer exception when profile contains 'null' string values
1 parent 42557be commit 2ceeb63

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

oauth/src/main/java/pl/edu/icm/unity/oauth/client/profile/ProfileFetcherUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public static Map<String, List<String>> convertToAttributes(JSONObject profile)
4242
if (entry.getValue() == null)
4343
continue;
4444
Object value = JSONValue.parse(entry.getValue().toString());
45+
if (value==null)
46+
continue;
47+
4548
if (value instanceof JSONObject)
4649
{
4750
ret.put(entry.getKey(), Arrays.asList(value.toString()));

oauth/src/test/java/pl/edu/icm/unity/oauth/client/profile/ProfileFetcherTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.nio.file.Files;
1313
import java.nio.file.Paths;
1414
import java.text.ParseException;
15+
import java.util.List;
16+
import java.util.Map;
1517
import java.util.Map.Entry;
1618

1719
import org.junit.Test;
@@ -20,9 +22,20 @@
2022

2123
import net.minidev.json.JSONArray;
2224
import net.minidev.json.JSONObject;
25+
import net.minidev.json.parser.JSONParser;
2326

2427
public class ProfileFetcherTest
2528
{
29+
30+
@Test
31+
public void testHandleNullValues() throws Exception {
32+
String s = "{\"test-field\": \"null\"}";
33+
JSONParser p = new JSONParser(JSONParser.MODE_RFC4627);
34+
JSONObject o = (JSONObject)p.parse(s);
35+
Map<String,List<String>> m = ProfileFetcherUtils.convertToAttributes(o);
36+
assertThat(m.size(), is(0));
37+
}
38+
2639

2740
@Test
2841
public void shouldResolveToJsonObjects() throws ParseException, IOException

0 commit comments

Comments
 (0)