1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-25 20:18:00 +01:00

[xdata] Fix NPE in FillableForm

Calling write() in FillableForm's constructor causes a NPE because
write() makes use of requiredFields which has not been set at this
time. Furthermore, write() makes use of missingRequiredFields, which
is also populated in that loop. Therefore, we have to delay the
invocation of write() until requiredFields got set.

Thanks to Dan Caseley for reporting this.

Reported-by: Dan Caseley <dan@caseley.me.uk>
This commit is contained in:
Florian Schmaus 2024-01-10 10:41:22 +01:00
parent bd70d6abc5
commit 8b9a9e0f3e

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2020 Florian Schmaus
* Copyright 2020-2024 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -55,6 +55,7 @@ public class FillableForm extends FilledForm {
}
Set<String> requiredFields = new HashSet<>();
List<FormField> requiredFieldsWithDefaultValue = new ArrayList<>();
for (FormField formField : dataForm.getFields()) {
if (formField.isRequired()) {
String fieldName = formField.getFieldName();
@ -62,13 +63,17 @@ public class FillableForm extends FilledForm {
if (formField.hasValueSet()) {
// This is a form field with a default value.
write(formField);
requiredFieldsWithDefaultValue.add(formField);
} else {
missingRequiredFields.add(fieldName);
}
}
}
this.requiredFields = Collections.unmodifiableSet(requiredFields);
for (FormField field : requiredFieldsWithDefaultValue) {
write(field);
}
}
protected void writeListMulti(String fieldName, List<? extends CharSequence> values) {