Project: Eclipse_Platform_UI
Bug 48040 [JFace] FileImageDescriptor.getImageData() improperly returning null
Reported: 2003-12-03 17:36:17 | Status: verified fixed

The getImageData method of org.eclipse.jface.resource.FileImageData improperly returns null on an IOException during the closing of the image file's io stream. The method currently (file v1.4, 20031203)looks like so: public ImageData getImageData() { InputStream in = getStream(); if (in != null) { try { return new ImageData(in); } finally { try { in.close(); } catch (IOException e) { return null; } } } else { return null; } } Thus, even if the ' new ImageData(in)' code is successful, if there is an unrelated state variance that causes the in.close() to fail, the result that is returned from the method is null. Note - as a general rule, when doing a stream close() in a finally clause, one should not do anything in the IOException trap that modifies the method result. At most, one should merely print a warning. A modification that works correctly is as so: public ImageData getImageData() { InputStream in = getStream(); ImageData result = null; if (in != null) { try { result= new ImageData(in); }finally { try { in.close(); }catch (IOException e) { //System.err.println( // getClass().getName()+".getImageData(): "+ // "Exception while closing InputStream : "+e); } } } return result; }

Files changed in fix:
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FileImageDescriptor.java