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
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jface.resource;
import java.io.*;
import org.eclipse.swt.graphics.ImageData;
/**
 * An image descriptor that loads its image information
 * from a file.
 */
class FileImageDescriptor extends ImageDescriptor {