Bug 48040 [JFace] FileImageDescriptor.getImageData() improperly returning null
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; }
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FileImageDescriptor.java
* Method declared on ImageDesciptor.
 * Returns null if the image data cannot be read.
 */
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;
	}
}
/**
 * Returns a stream on the image contents.  Returns
 * null if a stream could not be opened.
 */
private InputStream getStream() {
	InputStream is = null;
	if (location != null) {
		is = location.getResourceAsStream(name);
	} else {