title: Spring List<MultipartFile> returns one even though no files have been selected
body: <p>I have a form that allows a user to select multiple images to upload to the server. The problem is that in my controller <code>files.size()</code> returns <code>one</code> even though I have not selected any file to upload. So the line <code>if(files != null &amp;&amp; files.size() &gt; 0)</code> always gets executed.</p>
  
  <pre><code>@RequestMapping(value="/advert/add", method=POST)
  public void insertAdverts(HttpServletRequest request,
          HttpServletResponse response, 
          @ModelAttribute("fileUpload") FileUpload fileUpload)
                  throws NumberFormatException, IOException, IllegalStateException, 
                  ServletException, FileUploadException{
  
      //Get uploaded files and store them
      List&lt;MultipartFile&gt; files = fileUpload.getFiles();
      List&lt;String&gt; fileNames = new ArrayList&lt;String&gt;();
  
      try{
          if(files != null &amp;&amp; files.size() &gt; 0){
              for(MultipartFile image:files){
                  String fileName = image.getOriginalFilename();
                  String[] fileSplit = fileName.split("\\.");
                  fileNames.add(fileName);
  
                  File uploadedFile = new File(uploadDirectory+"\\"+fileName);
                  uploadedFile.createNewFile();
                  image.transferTo(uploadedFile);
              }
          }
  </code></pre>
  
  <p>Here is FileUpload Class</p>
  
  <pre><code>public class FileUpload implements Serializable{
  
  private static final long serialVersionUID = 1L;
  
  private int menuId;
  private int subMenuId;
  private String adLocation;
  private String adSubject;
  private String adBody;
  private String contactNo;
  private String contactEmail;
  private String fileName;
  private List&lt;MultipartFile&gt; files = null;
  .....
  </code></pre>
  
  <p>and the jsp form</p>
  
  <pre><code>&lt;form:form id = "add-advert-form" method="post" action="/AdPost/advert/add" 
      enctype="multipart/form-data" modelAttribute="fileUpload"&gt;
          ...
      &lt;form:input type="file" id="adPictures" accept="image/*" 
                 name="files[]" multiple="multiple" path="files"/&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>Can someone please tell me why <code>List.size()</code> is returning <code>one</code> instead of <code>zero</code> and how to get the correct list size. </p>
  
  <p>This is what files looks like in debug window:</p>
  
  <p><img src="https://i.stack.imgur.com/UrEKW.png" alt="This is what files looks like in debug window"></p>
  
  <p><a href="https://i.stack.imgur.com/YBUdC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YBUdC.png" alt="fileItem"></a></p>