Commons FileUpload
  1. Commons FileUpload
  2. FILEUPLOAD-193

FileNotFoundException thrown by DiskFileItem.write

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 1.2.2
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Ubuntu 10.10

      java version "1.6.0_24"
      Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
      Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)

      Description

      Under certain conditions the DiskFileItem.write throws a FileNotFound exception. It seems to be when outputFile.renameTo(file) fails.

      java.io.FileNotFoundException: /tmp/UploadController/uploading/upload_69651d04_13000a31964__8000_00001651.tmp (No such file or directory)
              at java.io.FileInputStream.open(Native Method)
              at java.io.FileInputStream.<init>(FileInputStream.java:106)
              at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:447)
              at upload.UploadController.handle(UploadController.java:90)
              ...

      I can't see any obvious reason why the source file (outputFile) wouldn't exist...

        Activity

        Hide
        Dan Washusen added a comment -

        Updated description to remove incorrect description of issue.

        Show
        Dan Washusen added a comment - Updated description to remove incorrect description of issue.
        Hide
        jagub zhang added a comment -

        did you use DiskFileItem#write twice?
        or you register a FileCleaningTracker in your DiskFileItemFactory.

        Show
        jagub zhang added a comment - did you use DiskFileItem#write twice? or you register a FileCleaningTracker in your DiskFileItemFactory.
        Hide
        Julien Vey added a comment - - edited

        I have the same issue under some undetermined conditions.

        Have you found any workaround to avoid this issue ?

        (with version 1.2.1)

        Show
        Julien Vey added a comment - - edited I have the same issue under some undetermined conditions. Have you found any workaround to avoid this issue ? (with version 1.2.1)
        Hide
        Dan Washusen added a comment -

        I haven't noticed this issue since reporting it (no changes to my code).

        Jagub, to answer your questions...

        No I'm not calling DiskFileItem#write twice. I call this method while iterating over the list of FileItems returned from ServletFileUpload#parseRequest. Each request contains several form fields and a single file.

        Yes, I have a FileCleaningTracker registered with the DiskFileItemFactory. However, I call the write method almost immediately after calling ServletFileUpload#parseRequest (so I wouldn't have thought the FileCleaningTracker would have had a chance to do anything yet).

        Show
        Dan Washusen added a comment - I haven't noticed this issue since reporting it (no changes to my code). Jagub, to answer your questions... No I'm not calling DiskFileItem#write twice. I call this method while iterating over the list of FileItems returned from ServletFileUpload#parseRequest. Each request contains several form fields and a single file. Yes, I have a FileCleaningTracker registered with the DiskFileItemFactory. However, I call the write method almost immediately after calling ServletFileUpload#parseRequest (so I wouldn't have thought the FileCleaningTracker would have had a chance to do anything yet).
        Hide
        jagub zhang added a comment -

        Try remove your FileCleaningTracker. in fact, uploaded file always be removed by DiskFileItem#finalize

        Show
        jagub zhang added a comment - Try remove your FileCleaningTracker. in fact, uploaded file always be removed by DiskFileItem#finalize
        Hide
        Eli Segev added a comment -

        I can reproduce this problem when the file name has 50 multi-byte characters, like あいうえおかきくけこはひふへほなにぬねのぁりるれろあいうえおかきくけこはひふへほなにぬねのぁりるれろあいうえおかきくけこはひふへほなにぬねのぁりるれろあいうえおかきくけこはひふへほなにぬねのぁりるれろ.docx. If the file name is shortened, no exception takes place. The stack trace is:
        java.io.FileNotFoundException: D:\staging%E3%81%82%E3%81%84%E3%
        81%86%E3%81%88%E3%81%8A%E3%81%8B%E3%81%8D%E3%81%8F%E3%81%91%E3%81%93%E3%81%AF%E3%81%B2%E3%81%B5%E3%81%B8%E3%81%BB%E3%81%AA%E
        3%81%AB%E3%81%AC%E3%81%AD%E3%81%AE%E3%81%81%E3%82%8A%E3%82%8B%E3%82%8C%E3%82%8D%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A
        %E3%81%8B%E3%81%8D%E3%81%8F%E3%81%91%E3%81%93%E3%81%AF%E3%81%B2%E3%81%B5%E3%81%B8%E3%81%BB%E3%81%AA%E3%81%AB%E3%81%AC%E3%81%
        AD%E3%81%AE%E3%81%81%E3%82%8A%E3%82%8B%E3%82%8C%E3%82%8D%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A%E3%81%8B%E3%81%8D%E3%8
        1%8F%E3%81%91%E3%81%93%E3%81%AF%E3%81%B2%E3%81%B5%E3%81%B8%E3%81%BB%E3%81%AA%E3%81%AB%E3%81%AC%E3%81%AD%E3%81%AE%E3%81%81%E3
        %82%8A%E3%82%8B%E3%82%8C%E3%82%8D%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A%E3%81%8B%E3%81%8D%E3%81%8F%E3%81%91%E3%81%93%
        E3%81%AF%E3%81%B2%E3%81%B5%E3%81%B8%E3%81%BB%E3%81%AA%E3%81%AB%E3%81%AC%E3%81%AD%E3%81%AE%E3%81%81%E3%82%8A%E3%82%8B%E3%82%8
        C%E3%82%8D.docx (The filename, directory name, or volume label syntax is incorrect)
        at java.io.FileOutputStream.open(Native Method)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:145)
        at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:449)

        There is no issue with write permission or anything like this, since no other file has this issue. The OS is Windows 7.

        Show
        Eli Segev added a comment - I can reproduce this problem when the file name has 50 multi-byte characters, like あいうえおかきくけこはひふへほなにぬねのぁりるれろあいうえおかきくけこはひふへほなにぬねのぁりるれろあいうえおかきくけこはひふへほなにぬねのぁりるれろあいうえおかきくけこはひふへほなにぬねのぁりるれろ.docx. If the file name is shortened, no exception takes place. The stack trace is: java.io.FileNotFoundException: D:\staging%E3%81%82%E3%81%84%E3% 81%86%E3%81%88%E3%81%8A%E3%81%8B%E3%81%8D%E3%81%8F%E3%81%91%E3%81%93%E3%81%AF%E3%81%B2%E3%81%B5%E3%81%B8%E3%81%BB%E3%81%AA%E 3%81%AB%E3%81%AC%E3%81%AD%E3%81%AE%E3%81%81%E3%82%8A%E3%82%8B%E3%82%8C%E3%82%8D%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A %E3%81%8B%E3%81%8D%E3%81%8F%E3%81%91%E3%81%93%E3%81%AF%E3%81%B2%E3%81%B5%E3%81%B8%E3%81%BB%E3%81%AA%E3%81%AB%E3%81%AC%E3%81% AD%E3%81%AE%E3%81%81%E3%82%8A%E3%82%8B%E3%82%8C%E3%82%8D%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A%E3%81%8B%E3%81%8D%E3%8 1%8F%E3%81%91%E3%81%93%E3%81%AF%E3%81%B2%E3%81%B5%E3%81%B8%E3%81%BB%E3%81%AA%E3%81%AB%E3%81%AC%E3%81%AD%E3%81%AE%E3%81%81%E3 %82%8A%E3%82%8B%E3%82%8C%E3%82%8D%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A%E3%81%8B%E3%81%8D%E3%81%8F%E3%81%91%E3%81%93% E3%81%AF%E3%81%B2%E3%81%B5%E3%81%B8%E3%81%BB%E3%81%AA%E3%81%AB%E3%81%AC%E3%81%AD%E3%81%AE%E3%81%81%E3%82%8A%E3%82%8B%E3%82%8 C%E3%82%8D.docx (The filename, directory name, or volume label syntax is incorrect) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:194) at java.io.FileOutputStream.<init>(FileOutputStream.java:145) at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:449) There is no issue with write permission or anything like this, since no other file has this issue. The OS is Windows 7.
        Hide
        Sebb added a comment -

        What is the total length of the file name, including parent directories?

        There is a hard limit in windows, so you'll likely find the same issue with plain ascii file names too.

        Show
        Sebb added a comment - What is the total length of the file name, including parent directories? There is a hard limit in windows, so you'll likely find the same issue with plain ascii file names too.
        Hide
        Jochen Wiedmann added a comment -

        Most likely caused by an invalid file name. It is the fileupload users task to choose valid file name.

        Show
        Jochen Wiedmann added a comment - Most likely caused by an invalid file name. It is the fileupload users task to choose valid file name.
        Hide
        Eli Segev added a comment -

        The issue is in the length of the file name. The hard limit in Windows is 255 characters and this is what happens here. See here: http://windows.microsoft.com/en-us/windows-vista/file-names-and-file-name-extensions-frequently-asked-questions. Encoding a Chinese file name increases the file name's size 9 fold and it goes above the hard limit. Thanks to Sebb for pointing me at the right direction.

        Show
        Eli Segev added a comment - The issue is in the length of the file name. The hard limit in Windows is 255 characters and this is what happens here. See here: http://windows.microsoft.com/en-us/windows-vista/file-names-and-file-name-extensions-frequently-asked-questions . Encoding a Chinese file name increases the file name's size 9 fold and it goes above the hard limit. Thanks to Sebb for pointing me at the right direction.
        Hide
        Sebb added a comment -

        I think the clue is in this part of the trace (I should have noted it earlier):

        (The filename, directory name, or volume label syntax is incorrect)

        The reference to a syntax error presumably refers to the excess length.

        BTW, I'm not sure why this is treated as FileNotFoundException rather than some other IOException.
        [The same happens if the file exists but cannot be written, e.g. is read-only]
        The use of FNFE is confusing.

        Show
        Sebb added a comment - I think the clue is in this part of the trace (I should have noted it earlier): (The filename, directory name, or volume label syntax is incorrect) The reference to a syntax error presumably refers to the excess length. BTW, I'm not sure why this is treated as FileNotFoundException rather than some other IOException. [The same happens if the file exists but cannot be written, e.g. is read-only] The use of FNFE is confusing.
        Hide
        Eli Segev added a comment -

        If you notice, the issue happens in a native method and not in a pure Java code. I guess the Java code in FileOutputStream could have chosen a different exception.

        Show
        Eli Segev added a comment - If you notice, the issue happens in a native method and not in a pure Java code. I guess the Java code in FileOutputStream could have chosen a different exception.
        Hide
        jagub zhang added a comment -

        Another possibility.
        If you upload a 0 byte file, FileNotFoundException will be occurred.

        Show
        jagub zhang added a comment - Another possibility. If you upload a 0 byte file, FileNotFoundException will be occurred.

          People

          • Assignee:
            Unassigned
            Reporter:
            Dan Washusen
          • Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:

              Development