Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-225

FTPFileEntryParserImpl.preParse() doesn't remove unparsable entries at the end of the file list

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.4, 2.1
    • 2.0
    • None
    • None
    • commons-net-1.4.1; Windows XP/2003; JRE 1.5.013-b05; Ant 1.7.0; Embedded FTP server UNIX type L8;

    Description

      I am using Ant 1.7.0 task to get files from our Embedded FTP server:
      <ftp server="${xxxximage.master.test.xxxx.ip}"
      port="${xxxximage.master.test.xxxx.port}"
      userid="${xxxximage.master.test.xxxx.user}"
      password="${xxxximage.master.test.xxxx.password}"
      remotedir="${xxxximage.master.test.xxxx.dir}"
      retriesAllowed="3"
      action="get"
      skipFailedTransfers="true"
      systemTypeKey="UNIX"
      >
      <fileset dir="${xxxximage.master.dist.test.nunit.dir}">
      <include name="${xxxximage.master.test.xxxx.results}"/>
      </fileset>
      </ftp>
      Ant task crashes with the following error message:
      java.lang.NullPointerException
      at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
      a:115)
      at org.apache.tools.ant.Task.perform(Task.java:348)
      at org.apache.tools.ant.Target.execute(Target.java:357)
      at org.apache.tools.ant.Target.performTasks(Target.java:385)
      at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
      at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
      cutor.java:41)
      at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
      at org.apache.tools.ant.Main.runBuild(Main.java:698)
      at org.apache.tools.ant.Main.startAnt(Main.java:199)
      at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
      at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
      Caused by: java.lang.NullPointerException
      at org.apache.tools.ant.taskdefs.optional.net.FTP$FTPDirectoryScanner.ch
      eckRemoteSensitivity(FTP.java:583)
      at org.apache.tools.ant.taskdefs.optional.net.FTP$FTPDirectoryScanner.fo
      rceRemoteSensitivityCheck(FTP.java:552)
      at org.apache.tools.ant.taskdefs.optional.net.FTP$FTPDirectoryScanner.sc
      an(FTP.java:231)
      at org.apache.tools.ant.taskdefs.optional.net.FTP.transferFiles(FTP.java
      :1570)
      at org.apache.tools.ant.taskdefs.optional.net.FTP.transferFiles(FTP.java
      :1683)
      at org.apache.tools.ant.taskdefs.optional.net.FTP.execute(FTP.java:2373)

      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
      at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
      a:105)
      ... 11 more
      — Nested Exception —
      java.lang.NullPointerException
      at org.apache.tools.ant.taskdefs.optional.net.FTP$FTPDirectoryScanner.ch
      eckRemoteSensitivity(FTP.java:583)
      at org.apache.tools.ant.taskdefs.optional.net.FTP$FTPDirectoryScanner.fo
      rceRemoteSensitivityCheck(FTP.java:552)
      at org.apache.tools.ant.taskdefs.optional.net.FTP$FTPDirectoryScanner.sc
      an(FTP.java:231)
      at org.apache.tools.ant.taskdefs.optional.net.FTP.transferFiles(FTP.java
      :1570)
      at org.apache.tools.ant.taskdefs.optional.net.FTP.transferFiles(FTP.java
      :1683)
      at org.apache.tools.ant.taskdefs.optional.net.FTP.execute(FTP.java:2373)

      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
      at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
      a:105)
      at org.apache.tools.ant.Task.perform(Task.java:348)
      at org.apache.tools.ant.Target.execute(Target.java:357)
      at org.apache.tools.ant.Target.performTasks(Target.java:385)
      at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
      at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
      cutor.java:41)
      at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
      at org.apache.tools.ant.Main.runBuild(Main.java:698)
      at org.apache.tools.ant.Main.startAnt(Main.java:199)
      at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
      at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

      The problem is in the Commons-Net library used internally by the Ant task.
      Our FTP server returns empty string at the end of the requested folder file list that causes the org.apache.commons.net.ftp.FtpClient.listFiles() method to return FTPFile array with null elements at the end, which in turn causes NullPointer exception in the org.apache.tools.ant.taskdefs.optional.net.FTP.checkRemoteSensivity() method.

      The problem occurs because the org.apache.commons.net.ftp.FTPFileEntryParserImpl.preParse() methods designed to wipe off non-valid lines from the file list response doesn't remove trailing empty lines from response inspite of its Javadoc description: "This default implementation removes entries that do not parse as files."

      The issue can be fixed by removing
      else {
      break;
      }
      clause from the method's implementation.

      I have checked the HEAD version of the FTPFileEntryParserImpl.java file. The else

      { break; }

      clause still remains there and I can reproduce issue with the HEAD version of the commons.net.ftp, thus I am assuming that the issue occurs in the commons-net 1.4.1 as well as in the latest development version.

      Attachments

        Activity

          People

            Unassigned Unassigned
            sshcherbakov Sergey Shcherbakov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: