here is a test case :
open you temp folder X:/Users/~/AppData/Local/Temp (on Vista) and try to run this Applet http://demo.dzzd.net/JarCacheBug/ it will fullfill your disk (no fear it would requiere a very long time…)
this only happen on aborted or unclosed transferts : developpers may not use setUseCache(true) on URLConnection or ensure that stream is always properly closed to solve this but it would be a lot better if the JVM was ALWAYS freing those files when exiting …
EDIT: bug seems to be appear randomly… sometimes it work nice
/**
* JarCacheBug Applet application
*
* Using URLConnection with setUseCache(true) have severals issues :
* - create hundreds of useless (not used as cache) in ~/AppData/Local/Temp/ (for Vista)
* - slow down the network
* - misnamed files (jar_cacheXXXXX files can be any kind of file and are the raw copy of the downloaded ressource ec: png / class / txt / etc.. files )
*
* this Applet will download several times the same file from the server using URLConnection & setUseCache(true) and intentionaly not gracefully end the connection , while running open your XX:/Users/~/AppData/Local/Temp/ directory (or the equivalent on your system)
*
* @author Bruno Augier http://dzzd.net/
* @version 1.00 2010/04/02
*/
import java.awt.*;
import java.applet.*;
import java.net.*;
import java.io.*;
public class JarCacheBug extends Applet implements Runnable
{
public static final long serialVersionUID = 0x01;
private volatile boolean threadMustRun;
private volatile Thread thread;
private volatile int downloadCount;
private volatile int downloadSize;
public void init()
{
this.threadMustRun=true;
this.downloadCount=0;
this.downloadSize=0;
}
public void start()
{
this.thread=new Thread(this);
this.thread.start();
}
public void run()
{
try
{
while(this.threadMustRun)
{
URL url=new URL(this.getCodeBase()+"/JAVA.PNG");
URLConnection uc=url.openConnection();
uc.setUseCaches(true);
int size=uc.getContentLength();
if(size==-1)
throw new Exception(" No source file length ");
byte data[]=new byte[size];
InputStream is=uc.getInputStream();
int nbRead=0;
do
{
int nbToRead=Math.min(size-nbRead,10*1024);
int nb=is.read(data,nbRead,nbToRead);
if(nb==-1)
throw new Exception(" reading error ");
nbRead+=nb;
}
while(nbRead!=size);
//Simulate transfert abort by not closing the stream
//is.close();
this.downloadSize+=size;
this.downloadCount++;
this.repaint();
Thread.sleep(100);
}
}
catch(Exception e)
{
e.printStackTrace();
}
this.threadMustRun=false;
this.thread=null;
}
public void paint(Graphics g)
{
g.drawString( this.downloadCount + " downloads finished (" + this.downloadSize + " total bytes) ", 50, 60 );
}
public void destroy()
{
this.threadMustRun=false;
try
{
this.thread.join();
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}
}