Item#unwrap should be @Nonnull

Description

In Item, one of our foundational interfaces, Item#unwrap is specified as @Nullable.

There doesn't seem to me to be a good reason for that. It's possible that it came about as a consequence of the current implementation of DOMDocumentItem and its use of a parent class method to set the data value, rather than calling the parent class constructor.

I think it would be better to:

  • Implement AbstractItem with a constructor taking the value to be wrapped,

  • At least for now, making the corresponding field final,

  • Dump the setData method entirely (again, at least for now)

  • Impose a @Nonnull constraint where possible.

I think it's fairly easy to achieve this with a little rejigging of the way DOMDocumentItem's constructors work, to include a helper method to return the processed data for the hard case.

Environment

None

Activity

Ian Young July 9, 2020 at 5:18 PM

This also involved adding a couple of test classes for the two implementations, although all I do for now is test that they throw constraint violations as appropriate.

I also, on the fly, made the two getters in the abstract class final to let the compiler do inlining.

Ian Young July 9, 2020 at 5:14 PM

Done, commit 832a60e8ca626c0513897757832a6dc2cdb7fd59.

Fixed

Details

Assignee

Reporter

Fix versions

Affects versions

Created July 9, 2020 at 4:04 PM
Updated May 16, 2024 at 12:37 PM
Resolved July 10, 2020 at 11:35 AM