commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Priest <Robert.Pri...@bentley.com>
Subject RE: FileUpload, bug?
Date Fri, 02 May 2003 18:37:46 GMT
adding the follwing would suffice, right?
The idea is just that if the memoryOutputStream has already been "switched
over", the "currentOutputStream" would have been set also.

 protected void thresholdReached() throws IOException
    {
        if(memoryOutputStream == null) <== ADDED
            return;			   <== ADDED

        byte[] data = memoryOutputStream.toByteArray();
        FileOutputStream fos = new FileOutputStream(outputFile);
        fos.write(data);
        diskOutputStream = fos;
        currentOutputStream = fos;
        memoryOutputStream = null;
    }

-----Original Message-----
From: Robert Priest [mailto:Robert.Priest@bentley.com]
Sent: Friday, May 02, 2003 1:34 PM
To: 'commons-dev@jakarta.apache.org'
Subject: FileUpload, bug?


hello,

I am recent cvs repository build of  commons-fileupload-1.0-dev.jar
with 
tomcat 4.1.7 
 jdk 1.4.1_01

I think this is a bug, what do you think:

in DeferredFileOutputStream.thresholdReache   (used when the file is stored
in memory), I keep getting a null pointer exception:

java.lang.NullPointerException
	at
org.apache.commons.fileupload.DeferredFileOutputStream.thresholdReached(Defe
rredFileOutputStream.java:163)
	at
org.apache.commons.fileupload.ThresholdingOutputStream.checkThreshold(Thresh
oldingOutputStream.java:260)
	at
org.apache.commons.fileupload.ThresholdingOutputStream.write(ThresholdingOut
putStream.java:167)
	at
org.apache.commons.fileupload.MultipartStream.readBodyData(MultipartStream.j
ava:513)


The method is as follows: 

 protected void thresholdReached() throws IOException
    {
        byte[] data = memoryOutputStream.toByteArray();       <== OFFENDING
LINE; 163
        FileOutputStream fos = new FileOutputStream(outputFile);
        fos.write(data);
        diskOutputStream = fos;
        currentOutputStream = fos;
        memoryOutputStream = null;
    }

Here is what is happening:
- I have my threshold set to: 4096.
- I attempt to "upload" a file or say 10 k or so
- thresholdReached gets calls and the output stream is switched from
"memory" to "file".

This is fine, the first time "thresholdReached()" is called. But if
thresholdReached() is called again (in this case it is),  the null pointer
exception occurs. This is because the previous call to thresholdReached()
set  "memoryOutputStream = null;", which makes sense, but the first line of
the method is now a call to that NULL output stream.

We should be using the "currentOutputStream" member on line 163, correct?

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message