NPE while creating Import Configuration
Describe the bug Creating a new import configuration can cause a null pointer exception like
java.lang.NullPointerException
at java.base/java.lang.String.contains(String.java:2036)
at org.kitodo.production.helper.Helper.appendUnusedInsertions(Helper.java:493)
at org.kitodo.production.helper.Helper.getTranslation(Helper.java:479)
at org.kitodo.production.forms.validators.ImportConfigurationMappingValidator.validate(ImportConfigurationMappingValidator.java:60)
at org.kitodo.production.forms.validators.ImportConfigurationMappingValidator.validate(ImportConfigurationMappingValidator.java:30)
at javax.faces.component._ComponentUtils.callValidators(_ComponentUtils.java:291)
at javax.faces.component.UIInput.validateValue(UIInput.java:489)
at org.primefaces.component.picklist.PickList.validateValue(PickList.java:116)
at javax.faces.component.UIInput.validate(UIInput.java:746)
at org.primefaces.component.picklist.PickList.validate(PickList.java:182)
at javax.faces.component.UIInput.processValidators(UIInput.java:293)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1458)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1458)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1458)
at org.primefaces.util.ComponentUtils.processValidatorsOfFacetsAndChilds(ComponentUtils.java:247)
at org.primefaces.component.api.UITabPanel.processValidators(UITabPanel.java:1107)
at javax.faces.component.UIForm.processValidators(UIForm.java:210)
To Reproduce Steps to reproduce the behavior:
- Create new Import configuration
- Insert somthing for title and description field
- Select Fileupload as Configuration type
- Click on Save Button
- Get the null pointer exception
Expected behavior In case of a configuration error an error message should appear and not a null pointer exception
Release 3.6.0-SNAPSHOT (master branch from March 1th 2023 commit 5b60965afb8a9512b0021b416ad98291971e66a4)
This happens if nothing is selected for "Metadata format of upload file". Even if it appears like MODS is selected here, the selected value is NULL until one selects a value by hand.
This leads to metadaformat being NULL here:
https://github.com/kitodo/kitodo-production/blob/3f6010fb0a4369570d624bf500d3cd452ea1e204/Kitodo/src/main/java/org/kitodo/production/forms/validators/ImportConfigurationMappingValidator.java#L58
I think this has been resolved in the current master branch. Configuring an ImportConfiguration of type FileUpload without explicitely setting a metadata format still does not correctly set the displayed default value "MODS" in the background, but the exception is handled in the form validation and displays a proper error message (instead of an unhandled stack trace):
(it should save the configuration successfully since MODS appears to be selected, though)
@henning-gerhardt & @BartChris can you confirm this?
@solth I can confirm that the message is now displayed and no stack trace is shown, so the situation is improved in Master. However, the German translation for the message is missing: https://github.com/kitodo/kitodo-production/blob/ca015ec490301b52471d91fd513b891b2ea95950/Kitodo/src/main/resources/messages/messages_de.properties#L639