mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 05:22:06 +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:
parent
bd70d6abc5
commit
8b9a9e0f3e
1 changed files with 7 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2020 Florian Schmaus
|
* Copyright 2020-2024 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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<>();
|
Set<String> requiredFields = new HashSet<>();
|
||||||
|
List<FormField> requiredFieldsWithDefaultValue = new ArrayList<>();
|
||||||
for (FormField formField : dataForm.getFields()) {
|
for (FormField formField : dataForm.getFields()) {
|
||||||
if (formField.isRequired()) {
|
if (formField.isRequired()) {
|
||||||
String fieldName = formField.getFieldName();
|
String fieldName = formField.getFieldName();
|
||||||
|
@ -62,13 +63,17 @@ public class FillableForm extends FilledForm {
|
||||||
|
|
||||||
if (formField.hasValueSet()) {
|
if (formField.hasValueSet()) {
|
||||||
// This is a form field with a default value.
|
// This is a form field with a default value.
|
||||||
write(formField);
|
requiredFieldsWithDefaultValue.add(formField);
|
||||||
} else {
|
} else {
|
||||||
missingRequiredFields.add(fieldName);
|
missingRequiredFields.add(fieldName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.requiredFields = Collections.unmodifiableSet(requiredFields);
|
this.requiredFields = Collections.unmodifiableSet(requiredFields);
|
||||||
|
|
||||||
|
for (FormField field : requiredFieldsWithDefaultValue) {
|
||||||
|
write(field);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeListMulti(String fieldName, List<? extends CharSequence> values) {
|
protected void writeListMulti(String fieldName, List<? extends CharSequence> values) {
|
||||||
|
|
Loading…
Reference in a new issue