resolver script checking no value of attribute; .length vs size()

IAM David Bantz dabantz at alaska.edu
Mon Apr 25 18:31:49 UTC 2022


This little script (inside the EdReadyRole attribute definition) to add a
default value if a dependent attribute did not assign value:

if (typeof EdReadyEntitlement != “undefined” && EdReadyEntitlement !=
null && EdReadyEntitlement.getValues().size !=0)
      {value = EdReadyEntitlement.getValues().get(0);
      EdReadyRole.addValue(value);}
    else
     {EdReadyRole.addValue(“Student”);}


triggers this error if the attribute EdReadyEntitlement is in fact empty:

'EdReadyRole':Script did not run successfully
        at net.shibboleth.idp.attribute.resolver.ad.impl.ScriptedAttributeDefinition$AttributeDefinitionScriptEvaluator.execute(ScriptedAttributeDefinition.java:228)
Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds
for length 0


A colleague smartly told me to replace .size() with .length, which does in
fact work without triggering the error. I do not really understand why,
given the existence of > 20 other instances of precisely parallel tests of
non-existence of dependent attribute in my resolver, accumulated over many
years. e.g.,

if (typeof uakStudentMAU != "undefined" && uakStudentMAU != null &&
uakStudentMAU.getValues().*size()* != 0)

if (typeof mauPrimaryAffiliation != "undefined" && mauPrimaryAffiliation !=
null && mauPrimaryAffiliation.getValues().*size()* != 0)

…


Should I replace all the .size() with .length condition?


*Feel free to administer virtual dope slap if accompanied by good
explanation!*


David St Pierre Bantz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/users/attachments/20220425/26f2be2c/attachment.htm>


More information about the users mailing list