Uncaught runtime exception when Mapped attribute generates null value
Description
Environment
Activity
Rod Widdowson January 12, 2019 at 2:12 PM
Fix in the easy way (do nothing but log - Occam rules!) in 7e8436c57
Scott Cantor January 11, 2019 at 5:35 PM
I really have never understood this plugin all that well so I imagine the best thing is just to fix the bug and skip them if that's how it's always worked. Changing a weird plugin with even more subtle behavior seems like a bad idea.
If it was "leaking" empty strings through as StringAttributeValues, I guess that's the real risk but that seems like the right thing to do.
Rod Widdowson January 11, 2019 at 4:00 PM
Built a test to reproduce this. We end up with a ConstraintException
in StringAttributeValue
value = Constraint.isNotEmpty(attributeValue, "Attribute value cannot be null or empty");
which I could easily see turning into an uncaught exception.
This code all predates out special casing of null and empty so its not a surprising result.
My question here (really for @Scott Cantor is "what to do about this?". We could just warn and do notbhing (as OP asked in the list), but is seems to me that the correct answer is to replace this
if (newValue != null) {
mappedValues.add(new StringAttributeValue(newValue));
}
With this
if (newValue == null) {
log.debug("something")
mappedValue.add(new EmptyAttributeValue(EmptyType.NULL_VALUE));
} else if (mappedValue =="") {
log.debug("something else")
mappedValue.add(new EmptyAttributeValue(EmptyType.ZERO_LENGTH_VALUE));
} else {
mappedValues.add(new StringAttributeValue(newValue));
}
This has two problems
It is a change of behavior for the null case so this cannot be retrofitted
It requires a complete change in types in the (api) code because to the depths of it soul this attribute only believes in Strings so all the APIs are either in terms of
AttributeValue<String>
or the (related but far from identical)StringAttributeValue
There is the side issue that the whole AttributeValue<Type> thing is a complete nightmare in that it is almost impossible to get the types to convert easily, but that's a story for another week.
Stephen C. Losen January 8, 2019 at 11:21 AM
OK, Jira doesn't like asterisk. The example regex is: dot star leftparen dot star rightparen
Stephen C. Losen January 8, 2019 at 11:19 AM
Looks like Jira messed up my example: <SourceValue>.(.)</SourceValue>
If a xsi:type="Mapped" attribute generates a null value then the result is an uncaught runtime exception. Perhaps the IDP could skip or ignore the null value and log a warning.
Easy to reproduce:
<ValueMap>
<ReturnValue>$1</ReturnValue>
<SourceValue>.(.)</SourceValue>
</ValueMap>