metaschema-framework / metaschema-java

https://metaschema-java.metaschema.dev/
Other
0 stars 3 forks source link

Improve exception reporting for null values on optional field values #205

Open aj-stein-gsa opened 1 month ago

aj-stein-gsa commented 1 month ago

User Story

As a developer using this library and related tooling, when encountering an optional field value, I would like a more precise error message and controlled error behavior when such a null value is visited. I do not want a null pointer exception.

NOTE: This is a fix in the core library that is the root cause of the bug reported in https://github.com/GSA/fedramp-automation/issues/787.

Goals

Dependencies

N/A

Acceptance Criteria

Revisions

No response

aj-stein-gsa commented 1 month ago

@david-waltermire do we need to wrap this into the upcoming release? I do not know if we are planning that for the next day or two or we have some wiggle room. Let me know, thanks.

david-waltermire commented 1 month ago

I can include this in the 2.0.0 release.

There are two ways to handle this.

  1. Turn this into an error when parsing, since this is caused by missing expected information in the instance. This would keep the non-null requirement on the field value. This might have a minor impact to parsing performance. (low effort)
  2. Relax the non-null requirement on field values and add checks where this value is accessed. This will still result in Metapath processing errors, but will make the API a bit more robust, potentially at the expense of performance, since additional null checks will need to be added to the code paths. (moderate effort)

I am leaning towards option 1, but would like to consider other thoughts.

aj-stein-gsa commented 1 month ago

I can include this in the 2.0.0 release.

There are two ways to handle this.

I am leaning towards option 1, but would like to consider other thoughts.

I guess it depends on what is more accessible to developers or engineers extending tools on top of it. I guess it depends on what you want to present to the user with either option 1. Can it give relevant information to the developer/engineer sufficient context to know where in the document the issue occurs without more work and surfacing it specifically as a Metapath processing error? Can such context be given without Metapath processing and presumably Metapath location?

Generally, I am fine with Option 1, but wanted to understand a little more detail on that.

david-waltermire commented 1 month ago

To handle this at parse time null checking needs to be handled in the following locations:

david-waltermire commented 1 month ago

I created a feature branch with a test for this.

david-waltermire commented 1 month ago

227 summarizes why this is not possible to completely fix right now. Adding to backlog.