Skip to content

Commit

Permalink
SCIFIOITKBridge: improve null reader handling
Browse files Browse the repository at this point in the history
Updated null reader and null id handling.

* executeCommand: was checking if the reader was null before calling
  getSeries, but wasn't checking if the reader had a valid ID. Now
  both are checked.
* createReader: the current file name was being cached.. if that value
  was null, then the reader was created fresh and returned. However, the
  cached file name wasn't updated at this point.. furthermore, the
  cached path starts off non-null. To simplify things, the check for a
  null cached path is consolidated with checking if the reader's current
  id matches the passed path. If not, just go through the standard
  process for reader creation.

These changes should limit the opportunities for null values to pop up
when unexpected.
  • Loading branch information
hinerm committed Apr 10, 2014
1 parent e9044e6 commit 8ffccf4
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/main/java/loci/scifio/itk/SCIFIOITKBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ private boolean executeCommand(String[] args) throws FormatException,
{
boolean success = false;

String series = reader == null ? "0" : Integer.toString(reader.getSeries());
String series =
reader == null || reader.getCurrentFile() == null ? "0" : Integer
.toString(reader.getSeries());
String id = "";
String[] idTokens = null;

Expand Down Expand Up @@ -587,14 +589,7 @@ public boolean canWrite(String filePath) throws FormatException, IOException {
private IFormatReader createReader(final String filePath)
throws FormatException, IOException
{
if (readerPath == null) {
// use the not yet used reader
reader.setId(filePath);
reader.setSeries(0);
return reader;
}

if (readerPath.equals(filePath)) {
if (readerPath != null && readerPath.equals(filePath)) {
// just use the existing reader
return reader;
}
Expand Down

0 comments on commit 8ffccf4

Please sign in to comment.