Unidata / netcdf-java

The Unidata netcdf-java library
https://docs.unidata.ucar.edu/netcdf-java/current/userguide/index.html
BSD 3-Clause "New" or "Revised" License
146 stars 71 forks source link

Change MFiles.create to be Nonnull #1172

Closed tdrwenski closed 1 year ago

tdrwenski commented 1 year ago

Description of Changes

Currently, MFiles.create claims that it both creates an MFile using the MFileProviders or by using MFileOS and also checks if the file exists. However, the existence check only applies in the case of the MFileOS and not for instance MFileS3 or MFileZip. Note that we now have a separate method for checking existence (MFile::exists).

This PR would remove checking for existence in the create function. I think this change makes the code nicer since the create wasn't really checking existence for all types of MFiles. It also avoids null checks when using create. It makes testing simpler, for instance, I want to make tests that use MFile.create to test something that doesn't necessarily require files to exist.

I do not believe this counts as a breaking change, though it does change the documented behavior of this function. I added a second variant createIfExisting that returns null if exists is false (old behavior for create when its a MFileOS). Can change the names if you prefer!

PR Checklist