Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-5088

Empty file upload gives wrong error message

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.5.22
    • Fix Version/s: 2.6
    • Component/s: Core Interceptors
    • Labels:
      None

      Description

      On an empty file upload the storeLocation is null, so adds a file new StrutsUploadedFile(null)

      JakartaMultiPartRequest

      List fileList = new ArrayList<>(items.size());
      for (FileItem fileItem : items) {
      File storeLocation = ((DiskFileItem) fileItem).getStoreLocation();
      if (fileItem.isInMemory() && storeLocation != null && !storeLocation.exists()) {
      try {
      storeLocation.createNewFile();
      } catch (IOException e) {
      LOG.error("Cannot write uploaded empty file to disk: {}", storeLocation.getAbsolutePath(), e);
      }
      }
      fileList.add(new StrutsUploadedFile(storeLocation));
      }
      

      The FileUploadInterceptor checks for a null file but not null content from the new StrutsUploadedFile(null).

      eg for an empty file main.js

      Error message should be:
      Error uploading: main.js
      but gives:
      Error setting expression 'uploadedFiles' with value ['org.apache.struts2.dispatcher.multipart.StrutsUploadedFile@202585bc', ]
      Error setting expression 'uploadedFiles' with value ['org.apache.struts2.dispatcher.multipart.StrutsUploadedFile@49553150', ]

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ghuber Greg Huber
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 2h
                2h