Skip to content

Commit d85453d

Browse files
committed
Improve error when no suitable opener found
Rather than throwing NPE when opener is null, report clearly that none was found. And when one *is* found but returns an incompatible data type, report that more clearly as well.
1 parent 85d4bd0 commit d85453d

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/main/java/org/scijava/io/AbstractTypedIOService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ public D open(String source) throws IOException {
6565
@Override
6666
public D open(Location source) throws IOException {
6767
IOPlugin<?> opener = ioService().getOpener(source);
68+
if (opener == null) {
69+
throw new UnsupportedOperationException("No compatible opener found.");
70+
}
6871
try {
69-
Class<D> ignored = (Class<D>) opener.getDataType();
7072
return (D) opener.open(source);
7173
}
72-
catch(ClassCastException e) {
73-
throw new UnsupportedOperationException("No compatible opener found.");
74+
catch (ClassCastException e) {
75+
throw new UnsupportedOperationException(
76+
"Opened data does not conform to requested type.", e);
7477
}
7578
}
7679

0 commit comments

Comments
 (0)