The prepareValue method that gets internally called, when setting the claims in JwtClaimsBuilder:
|
@SuppressWarnings({ "rawtypes", "unchecked" }) |
|
private static Object prepareValue(Object value) { |
|
if (value instanceof Collection) { |
|
return ((Collection) value).stream().map(o -> prepareValue(o)).collect(Collectors.toList()); |
|
} |
|
|
|
if (value instanceof Map) { |
|
Map<String, Object> map = (Map) value; |
|
Map<String, Object> newMap = new LinkedHashMap<>(); |
|
for (Map.Entry<String, Object> entry : map.entrySet()) { |
|
newMap.put(entry.getKey(), prepareValue(entry.getValue())); |
|
} |
|
return newMap; |
|
} |
|
|
|
if (value instanceof JsonValue) { |
|
return convertJsonValue((JsonValue) value); |
|
} |
|
|
can return null as a result of convertJsonValue if you provide JsonValue.NULL as the claim value, whereas when you directly provide the null value to the claim method, it will fallthrough all the checks, and eventually call value.toString() on it, resulting in an NPE. Maybe we can add an additional check:
private static Object prepareValue(Object value) {
if (value == null) return null;
if (value instanceof Collection) {
return ((Collection) value).stream().map(o -> prepareValue(o)).collect(Collectors.toList());
}
// ....
}
to make the behaviour more consistent?
The
prepareValuemethod that gets internally called, when setting the claims inJwtClaimsBuilder:smallrye-jwt/implementation/jwt-build/src/main/java/io/smallrye/jwt/build/impl/JwtClaimsBuilderImpl.java
Lines 325 to 343 in b8302a1
can return
nullas a result ofconvertJsonValueif you provideJsonValue.NULLas the claim value, whereas when you directly provide thenullvalue to theclaimmethod, it will fallthrough all the checks, and eventually callvalue.toString()on it, resulting in an NPE. Maybe we can add an additional check:to make the behaviour more consistent?