JDK-6733200 : IOException not thrown
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-08-04
  • Updated: 2011-01-19
  • Resolved: 2008-11-24
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Try to write an image with the ImageIO in a folder that is mounted as network folder and someone doen't have write access.

The declared IOException is not thrown, and therefore can not be catched.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Choose a directory, where you don't have write access. Try and save the image with the ImageIO there.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
throws an IOException
ACTUAL -
throws a general Exception

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class SaveTest extends JFrame implements ActionListener {
	private static final String IMAGE_NAME = "seq01.jpg";
	private JLabel lbl;

	SaveTest() throws HeadlessException {
		super("SaveFrame");
		setSize(400, 300);
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		lbl = new JLabel();
		add(lbl, BorderLayout.CENTER);

		JButton btn = new JButton("save");
		btn.addActionListener(this);
		add(btn, BorderLayout.SOUTH);

		loadImage();
	}

	private void loadImage() {
		try {
			Image img = ImageIO.read(new File("images" + File.separator
					+ IMAGE_NAME));
			lbl.setIcon(new ImageIcon(img));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private void doSave() {
		JFileChooser fileChooser = new JFileChooser();
		int retVal = fileChooser.showSaveDialog(this);
		if (retVal == JFileChooser.APPROVE_OPTION) {
			File file = fileChooser.getSelectedFile();
			Icon icon = lbl.getIcon();
			if (icon != null) {
				try {
					ImageIcon imgIcon = (ImageIcon) icon;
					BufferedImage img = (BufferedImage) imgIcon.getImage();
					ImageIO.write(img, "jpg", file);
				} catch (FileNotFoundException e) {
					System.err.println("==== file not found exception" + e);
				} catch (IOException e) {
					System.err.println("==== io exception" + e);
				}
			}
		}
	}

	public static void main(String[] args) {
		new SaveTest();
	}

	public void actionPerformed(ActionEvent e) {
		doSave();
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Catch a general Excepetion.

Comments
EVALUATION CR 6247985 reports exactly same problem, so I close this one as a duplicate.
24-11-2008