Skip to content

Allow "null" values, when setting the claim. #866

@skku-daniilkim

Description

@skku-daniilkim

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions