Duplicate :
|
|
Duplicate :
|
|
Relates :
|
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
|