Skip to content

Commit 22b88f9

Browse files
Wrong SWT Error in Image(Device, InputStream) for IOException
As per contract of org.eclipse.swt.graphics.Image.Image(Device, InputStream), SWT Error - ERROR_IO should be thrown if IOException is caught while reading the inputStream.
1 parent ddac0aa commit 22b88f9

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ public Image(Device device, InputStream stream) {
696696
zoom -> ImageDataLoader.loadByZoom(new ByteArrayInputStream(input), FileFormat.DEFAULT_ZOOM, zoom).element());
697697
init();
698698
} catch (IOException e) {
699-
SWT.error(SWT.ERROR_INVALID_ARGUMENT, e);
699+
SWT.error(SWT.ERROR_IO, e);
700700
} finally {
701701
if (pool != null) pool.release();
702702
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,7 @@ private class ImageDataLoaderStreamProviderWrapper extends ImageFromImageDataPro
22472247
this.inputStreamData = inputStream.readAllBytes();
22482248
initImage();
22492249
} catch (IOException e) {
2250-
SWT.error(SWT.ERROR_INVALID_ARGUMENT, e);
2250+
SWT.error(SWT.ERROR_IO, e);
22512251
}
22522252
}
22532253

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_io_InputStream
288288
}
289289
assertSWTProblem("Incorrect exception thrown for invalid InputStream", SWT.ERROR_UNSUPPORTED_FORMAT, e);
290290

291+
InputStream failingStream = new InputStream() {
292+
@Override
293+
public int read() throws IOException {
294+
throw new IOException("bad input stream");
295+
}
296+
};
297+
e = assertThrows(SWTException.class, () -> new Image(display, failingStream));
298+
assertSWTProblem("Incorrect exception thrown for invalid InputStream", SWT.ERROR_IO, e);
299+
291300
String firstFile = SwtTestUtil.invalidImageFilenames[0];
292301
Display[] displays = { display, null };
293302
for (Display display : displays) {

0 commit comments

Comments
 (0)