-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent NPE when creating unknown metadata group and metadata #5603
base: main
Are you sure you want to change the base?
Conversation
This might be about a special scenario but nevertheless: I tried the changes with the scenario described in the linked issue (importing an entry from K10 plus without having all keys defined in the ruleset). The first NPE does not happen anymore. I still get an NPE in this specific scenario because "Person" was not defined in my ruleset and the construction of the ATS does fail, since it identifies a java.lang.NullPointerException Edit: This seem to stem from the specific functionality attached to keys named as "Person", it does not happen if if define a "Person" key in the ruleset, even with different subkeys than the one coming from K10-plus. I have not tested it yet with other datasets yet where the ATS related NPE does not happen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems neither wrong nor right, see comments.
@@ -43,7 +43,7 @@ public ProcessTextMetadata(ProcessTextMetadata template) { | |||
} | |||
|
|||
private String addLeadingZeros(String value) { | |||
if (Objects.equals(super.settings.getInputType(), InputType.INTEGER)) { | |||
if (Objects.nonNull(super.settings) && InputType.INTEGER.equals(super.settings.getInputType())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like better:
Objects.nonNull(super.settings) && Objects.equals(super.settings.getInputType(), InputType.INTEGER)
Not a requirement, but I think it is better readable. And, Objects.equals()
does null
-checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this particular case I disagree. The additional Objects.equals
is not required and unnecessarily complicates this check, since InputType.INTEGER
is not null and therefor we do not need a null check here (calling the equals
method on constants or enums when comparing with variables is an encouraged way for avoiding null pointer exceptions). So if you do not mind I would leave this part unchanged.
keyView instanceof SimpleMetadataViewInterface | ||
? ((SimpleMetadataViewInterface) keyView).getInputType().toString() | ||
: "dataTable")); | ||
if (Objects.nonNull(metadataView)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering why metadataView
can be null
. This looks like a bug elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think you are correct. This pull request is not meant to fix the underlying problem of the metadata handling but is just intended to better deal with the resulting null pointer exception.
0afcdba
to
1f7b068
Compare
@BartChris thanks for this clarification. I think "Person" is a special case and separate from the issue I tried to fix with this pull request. Do you think the linked issue is sufficiently resolved with these proposed changes or are there other suggestions or change requests you would like to see? (e.g. as @matthias-ronge mentioned there seem to be other issues in the metadata handling which are not addressed by this pull request. It is merely meant to handle the exception that can occur when ruleset and xml transformation script do not match a little more gracefully. It does not fix the underlying problem.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not work for me because I still get an NPE.
What have I done?
- Created a process with metadata group
- Check if the group is available in metadata editor
- Change the group name in
meta.xml
on filesystem - Open the metadata editor again -> NPE
java.lang.NullPointerException
at org.kitodo.production.forms.createprocess.ProcessSimpleMetadata.isRequired(ProcessSimpleMetadata.java:96)
at org.kitodo.production.forms.createprocess.ProcessTextMetadata.isRequired(ProcessTextMetadata.java:30)
...
@markusweigelt thanks for testing the changes. Yes, I think the same problem exists in the metadata editor. I just tried to handle the issue described in the linked issue, which occurs during import, though. Since the whole topic is quite complex I would suggest to handle the problem in the metadata editor separately, if you think that's ok. |
Ok I have read over that. I will check this only for the import again. |
Not existing top level fields working
but I am not able to import without NPE with non-existent top-level groups.
or
producing following NPE
|
We could also provide a general error message here, indicating that most likely the Kitodo XML generated after the XSL transformation is faulty. The errors I have noticed include, for example, empty groups when fields imported from K10Plus are empty, and there is a condition for checking them in XSL but no condition for the group. |
That would be the optimal solution, in my opinion - show a warning dialog that something went wrong with the import, likeley related to the ruleset and the mapping file not being compatible, and that additional information can be found in the logs, where the exact error message (and perhaps stack trace) should be logged. |
1f7b068
to
a56d6fc
Compare
This PR fixes #5217 by preventing the NullPointerException that is currently being displayed to the user when the import mapping xslt file creates a metadata group that is undefined in the used ruleset.