JDK-8022580 : sun.net.ftp.impl.FtpClient.nameList(String path) handles "null" incorrectly
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7,7u25,8
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • Submitted: 2013-08-02
  • Updated: 2017-11-29
  • Resolved: 2016-07-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8 JDK 9
7u131Fixed 8u152Fixed 9 b129Fixed
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
This is the original source code of the method sun.net.ftp.impl.FtpClient#nameList():

    /**
     * Issues a NLST path command to server to get the specified directory
     * content. It differs from {@link #list(String)} method by the fact that
     * it will only list the file names which would make the parsing of the
     * somewhat easier.
     *
     * {@link #completePending()} <b>has</b> to be called once the application
     * is finished writing to the stream.
     *
     * @param path a <code>String</code> containing the pathname of the
     *        directory to list or <code>null</code> for the current working
     *        directory.
     * @return the <code>InputStream</code> from the resulting data connection
     * @throws IOException if an error occurs during the transmission.
     */
    public InputStream nameList(String path) throws sun.net.ftp.FtpProtocolException, IOException {
        Socket s;
        s = openDataConnection( " NLST  "  + path);
        if (s != null) {
            return createInputStream(s.getInputStream());
        }
        return null;
    }

As can be seen, there is no handling of a null as the path parameter in this code at all (although documented).
A null as path doesn't lead to the expected result.




REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Passing an empty String instead of a null as the method argument.
Comments
Suggested fix: s = openDataConnection( " NLST " + path == null ? "" : path);
08-08-2013