powered by Jive Software

Parsing empty labels in form fields

When receiving and parsing forms, for some fields the response can contains empty string for “label” attributes, particularly for fields of type “hidden”.

   <field var='FORM_TYPE' label='' type='hidden'>

XEP-0004 says label is optional but doesn’t restrict empty values.

Parsing such response fails with the exception as a field builder doesn’t accept empty string:

    java.lang.IllegalArgumentException: label must not be null or empty
        at org.jivesoftware.smack.util.StringUtils.requireNotNullNorEmpty(StringUtils.java:551)
        at org.jivesoftware.smackx.xdata.FormField$Builder.setLabel(FormField.java:603)
        at org.jivesoftware.smackx.xdata.provider.DataFormProvider.parseField(DataFormProvider.java:289)
        at org.jivesoftware.smackx.xdata.provider.DataFormProvider.parseField(DataFormProvider.java:141)
        at org.jivesoftware.smackx.xdata.provider.DataFormProvider.parse(DataFormProvider.java:89)
        at org.jivesoftware.smackx.xdata.provider.DataFormProvider.parse(DataFormProvider.java:58)

I suggest to not pass a value to the builder is it’s empty to comply with the builder restrictions.

Label value was checked for emptiness before this commit Re-work data form API · igniterealtime/Smack@77e26fc (github.com)

PR with fix Set form field label only if value is non-empty by abyss638 · Pull Request #493 · igniterealtime/Smack (github.com)


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.