1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 03:52:06 +01:00

Merge pull request #575 from Flowdalic/fix-npe-in-fillableform

[xdata] Fix NPE in FillableForm
This commit is contained in:
Dan Caseley 2024-01-10 09:55:56 +00:00 committed by GitHub
commit b117d8c3d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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"); * 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.
@ -54,6 +54,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();
@ -61,13 +62,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) {