-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.lang.ClassCastException
when PATCH value
is null
#369
Comments
I'm using WSO2 charon version charon/modules/charon-core/src/main/java/org/wso2/charon3/core/utils/PatchOperationUtil.java Line 1856 in 73257cc
This would also cause a {
"Operations": [
{
"op": "replace",
"path": "active",
"value": false
}
],
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:PatchOp"
]
} The exception: Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at org.wso2.charon3.core.attributes.SimpleAttribute.getBooleanValue(SimpleAttribute.java:120) ~[org.wso2.charon3.core-4.0.18.jar:?]
at org.wso2.charon3.core.utils.LambdaExceptionUtils.lambda$rethrowFunction$2(LambdaExceptionUtils.java:84) ~[org.wso2.charon3.core-4.0.18.jar:?]
at org.wso2.charon3.core.objects.User.lambda$getActive$8(User.java:254) ~[org.wso2.charon3.core-4.0.18.jar:?]
at java.util.Optional.map(Optional.java:215) ~[?:1.8.0_362]
at org.wso2.charon3.core.objects.User.getActive(User.java:254) ~[org.wso2.charon3.core-4.0.18.jar:?] I think instead of always casting it to a string, we should check the datatype and convert it and set the value to the |
I've solved this issue temporarily by overriding the public class CharonUser extends User {
public CharonUser(User user) {
for (Attribute attribute : user.getAttributeList().values()) {
setAttribute(attribute);
}
for (String schema : user.getSchemaList()) {
setSchema(schema);
}
}
@Override
public boolean getActive() {
SCIMAttributeSchema attributeDefinition = SCIMSchemaDefinitions.SCIMUserSchemaDefinition.ACTIVE;
return this.getSimpleAttribute(attributeDefinition).map(simpleAttribute -> rethrowSupplier(
() -> {
Object value = simpleAttribute.getValue();
if (value instanceof Boolean) {
return (Boolean) value;
} else if (value instanceof String) {
return Boolean.parseBoolean((String) value);
} else {
throw new CharonException("Datatype doesn't match the datatype of the attribute value");
}
}
).get()
).orElse(false);
}
} Note: This is not a permanent solution and will need to verify if there are any changes in |
Description:
When sending PATCH
/Users/{{userId}}
call with null value:Exception happens:
Suggested Labels:
Type/Bug
Affected Product Version:
3.4.23 but likely in current version
Steps to reproduce:
Send a PATCH operation whose value is null.
In
charon/modules/charon-core/src/main/java/org/wso2/charon3/core/attributes/SimpleAttribute.java
Lines 77 to 85 in 5d5009c
this.value
wasorg.json.JSONObject$Null
so it should returnnull
to avoid doing the casting.Issue may not be limited to just
preferredLanguage
, but let's say it's:It will also hit similar issue:
And those
ClassCastException
happen only for PATCH. With POST (User create) or PUT (Replace), having it asnull
forpreferredLanguage
or""
foractive
did not hit any issue.Related Issues:
#314
The text was updated successfully, but these errors were encountered: