[ome-users] OMERO: No exceptions thrown upon missing images
b.gerritsen at nki.nl
b.gerritsen at nki.nl
Tue Jul 14 13:14:06 BST 2009
Dear omero developers,
OMERO Beta 4.0.3 does not throw an exception when trying to access an image that does exist in the database but does NOT exist in the omero data directory. In fact the missing image will be generated and look like a black canvas.
I traced this behavior back to line 92 in ome.io.nio.RomioPixelBuffer private method "getFileChannel()": "RandomAccessFile file = new RandomAccessFile(getPath(), "rw");". If a file is opened as read-write ("rw") the RandomAccessFile class will not throw a FileNotFoundException. It would have when it is instructed to open a file as "r". The code below will duplicate the omero behavior:
---
try {
RandomAccessFile f = new RandomAccessFile ("myNonExistentFile", "rw"); // This creates the file if it doesn't exist
FileChannel fc = f.getChannel();
fc.map(MapMode.READ_ONLY, 0, 1000); // Map 1000 bytes from a file into memory... in case of a non-existent file there will be 1000 bytes written to the file.
} catch (Exception e) {
e.printStackTrace();
}
---
A solution might be to add the following lines before line 92 in ome.io.nio.RomioPixelBuffer:
---
if (!new File(getPath()).exists()) {
throw new FileNotFoundException(getPath());
}
---
Kind Regards,
Bram Gerritsen
More information about the ome-users
mailing list