Skip to content
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

Add null check for image.getFormat() #9

Merged
merged 1 commit into from
May 20, 2024

Conversation

sbesson
Copy link
Member

@sbesson sbesson commented May 17, 2024

Under some conditions, an Image might have no associated format. This will be the case for ROMIO pixel buffer e.g. created by scripts or OMERO pyramid pixel buffer created by the PixelService for large images without resolutions.

To test this PR, use an OMERO.server with the https://github.com/glencoesoftware/omero-zarr-pixel-buffer extension and create a ROMIO image e.g. using the Images from ROIs script.

Without this PR a call to RenderingSettings.resetDefaults will cause a NPE of type

java.lang.NullPointerException: Cannot invoke "ome.model.enums.Format.getValue()" because the return value of "ome.model.core.Image.getFormat()" is null
	at com.glencoesoftware.omero.zarr.ZarrPixelsService.createOmeNgffPixelBuffer(ZarrPixelsService.java:328)
	at com.glencoesoftware.omero.zarr.ZarrPixelsService.getPixelBuffer(ZarrPixelsService.java:369)
	at ome.logic.RenderingSettingsImpl.resetDefaults(RenderingSettingsImpl.java:520)
	at ome.logic.RenderingSettingsImpl.resetDefaults(RenderingSettingsImpl.java:1439)

and the image will end up in a broken state.

With this PR, the PixelsService.getPixelBuffer should return a RomioPixelBuffer as expected and the server logic should complete the creation of a rendering definition and thumbnail

Under some conditions, an Image might have no associated format. This
will be the case for ROMIO pixel buffer e.g. created by scripts or
OMERO pyramid pixel buffer  created by the PixelService for large
images without resolutions.
@@ -325,7 +325,7 @@ protected ZarrPixelBuffer createOmeNgffPixelBuffer(Pixels pixels) {
String uri = getUri(image);
if (uri == null) {
// Quick exit if we think we're OME-NGFF but there is no URI
if ("OMEXML".equals(image.getFormat().getValue())) {
if (image.getFormat() != null && "OMEXML".equals(image.getFormat().getValue())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably just be:

"OMEXML".equals(unwrap(image.getFormat()))

With a static import of omero.rtypes.unwrap. Similar examples can be see in com.glencoesoftware.omero.ms.image.region.ImageDataRequestHandler.

Copy link
Member Author

@sbesson sbesson May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this does not work out of the box since image.getFormat() returns an ome.model.core.Format object and I get

/Users/sbesson/Documents/GitHub/omero-zarr-pixel-buffer/src/main/java/com/glencoesoftware/omero/zarr/ZarrPixelsService.java:330: error: incompatible types: Format cannot be converted to RType
                if ("OMEXML".equals(unwrap(image.getFormat()))) {

Could look into using the OriginalFileFormatEnumHandler to find the proper enumeration and return the IObject but I wonder if it's overkill.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch what I said. Since it's an instance of ome.model.Image (server side object) what you have currently is all we can really do.

@sbesson sbesson merged commit 6279578 into glencoesoftware:master May 20, 2024
3 checks passed
@sbesson sbesson deleted the image_format_npe branch May 20, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants