JDK-4894964 : If ImageOutputStream.close() is not explicitly called, temp file is not deleted
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-07-23
  • Updated: 2003-09-05
  • Resolved: 2003-09-05
Related Reports
Duplicate :  
Description

Name: gm110360			Date: 07/23/2003


FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
Using ImageIO.write() to write to an ImageOutputStream
results in a temporary file being created and never
deleted. The temp file is typically something like:
C:\Documents and Settings\<username>\Local
Settings\Temp\imageio8733.tmp

Explicitly calling ImageOutputStream.close() deletes the
temp file.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the attached sample program with an input image file
and an output image file name
2. Monitor your temp file directory and observe the new
imageioXXX.tmp file that remains after the program exits.

EXPECTED VERSUS ACTUAL BEHAVIOR :
The temp file should be cleaned up when the VM exits if
close() was not explicitly called.

REPRODUCIBILITY :
This bug can be reproduced always.

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

// ImageIO leaves a temp file around after exiting unless
ImageOutputStream.close() is called
// e.g. under W2K the file is something like C:\Documents and
Settings\<username>\Local Settings\Temp\imageio8733.tmp

public class ImageWriteCache {
	public static void main(String args[]) throws Exception {
		if (args.length != 2) {
			System.err.println("Usage: ImageWriteCache
<inputimagefile> <outputimagefile>");
			System.exit(1);
		}
		BufferedImage image = ImageIO.read(new File(args[0]));
		if (image == null) {
			System.err.println("Failed to load image " + args[0]);
			System.exit(1);
		}

		ImageOutputStream ios = ImageIO.createImageOutputStream(new
FileOutputStream(args[1]));
		if (ios == null || !ImageIO.write(image, "JPEG", ios)) {
			System.err.println("Failed to write image " + args[1]);
			System.exit(1);
		}

		// Uncomment this line and the temp file will be deleted
		//ios.close();
	}
}
---------- END SOURCE ----------
(Incident Review ID: 163578) 
======================================================================

Comments
EVALUATION Name: abR10136 Date: 09/05/2003 The temporary file is created by the instance of javax.imageio.steram.FileCacheImageOutputStream. This file is marked as "deleted on exit" as soon as it is created. If we do not close corresponding instance of FileCacheImageOutputStream the the temporary file is not closed and so it is not deleted on VM exit due to bug 4171239. ======================================================================
21-08-2004