JDK-6247985 : ImageIO.write fails with IllegalArgumentException instead of IOException
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 5.0,6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-03-30
  • Updated: 2014-05-07
  • Resolved: 2014-05-07
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)

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

A DESCRIPTION OF THE PROBLEM :
If you try to write a image to a folder for which you don't have write access ImageIO.write() fails with an IllegalArugmentException instead of an IOException.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Create a folder named "iiotest" in your home directory.
2) Deny yourself read/write access to the folder (Properties > Security; select your user name and select the Deny checkboxes in the Read and Write columns).
3) Execute the attached program

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The application should fail with an IOException.
ACTUAL -
The application fails with an IllegalArgumentException. If you execute the application you will see the IOException printed to stdout but it is not delivered to the caller.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.FileNotFoundException: C:\Documents and Settings\user\iiotest\test.png (Access is denied)
        at java.io.RandomAccessFile.open(Native Method)
        at java.io.RandomAccessFile.<init>(Unknown Source)
        at javax.imageio.stream.FileImageOutputStream.<init>(Unknown Source)
        at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstan
ce(Unknown Source)
        at javax.imageio.ImageIO.createImageOutputStream(Unknown Source)
        at javax.imageio.ImageIO.write(Unknown Source)
        at ImageIOTest.main(ImageIOTest.java:24)
Write Exception
java.lang.IllegalArgumentException: output == null!
        at javax.imageio.ImageIO.write(Unknown Source)
        at javax.imageio.ImageIO.write(Unknown Source)
        at ImageIOTest.main(ImageIOTest.java:24)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;

public class ImageIOTest
{
    public static void main(String[] args)
    {
        try {
            final File folder = new File(System.getProperty("user.home"), "iiotest");
            folder.mkdirs();

            final File file = new File(folder, "test.png");

            final BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);

            final Graphics2D g2d = (Graphics2D)image.getGraphics();

            g2d.setColor(Color.red);
            g2d.fillRect(0, 0, 1, 1);
            g2d.dispose();

            ImageIO.write(image, "png", file);
        }
        catch(Exception ex) {
            System.out.println("Write Exception");
            ex.printStackTrace();
        }
    }
}

---------- END SOURCE ----------
###@###.### 2005-03-30 13:55:17 GMT

Comments
Please re-open if - if fix is in progress or on the plan to fix soon - if this is a P3 (file as P3, not P4)
18-03-2014

EVALUATION Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=18797
26-02-2007

EVALUATION Probably can be closed as a duplicate of 5034864 once that one is fixed.
25-10-2005