You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Robert Priest <Ro...@bentley.com> on 2003/05/02 19:34:28 UTC

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


Re: FileUpload, bug?

Posted by Martin Cooper <ma...@apache.org>.
Yes, this is definitely a bug. The contract for thresholdReached() is
intended to be that it will only ever be called once, at the point the
configured threshold is actually reached. I'll fix this, and add a unit
test for it, tonight, so it should be in the next nightly build.

--
Martin Cooper


On Fri, 2 May 2003, Robert Priest wrote:

> 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