Right now, the com.sun.net.httpserver.SimpleFileServer#createFileServer states this:

"

     * Creates a <i>file server</i> the serves files from a given path.
     *
     * <p> The server is configured with an initial context that maps the
     * URI {@code path} to a <i>file handler</i>. The <i>file handler</i> is
     * created as if by an invocation of
     * {@link #createFileHandler(Path) createFileHandler(rootDirectory)}, and is
     * associated to a context created as if by an invocation of
     * {@link HttpServer#createContext(String) createContext("/")}.

...

"

The returned HttpServer isn't actually started and is expected to be started explicitly by a call to HttpServer.start(), but the javadoc doesn't make a mention of it. Should the javadoc be updated to add this note? I see that the class level javadoc has an example which does show that the returned server has to be explicitly started:

 * <p> Example of a simple file server:
 * <pre>{@code
 *    var addr = new InetSocketAddress(8080);
 *    var server = SimpleFileServer.createFileServer(addr, Path.of("/some/path"), OutputLevel.INFO);
 *    server.start();
 * }</pre>


In one of my tests, I ended up creating a file server using this API but didn't call start() on the returned server which lead to a hung HTTP request from clients (a different topic/investigation). So, I think, if the javadoc of this API would have an explicit note about the returned server not being started, that would be helpful.

-Jaikiran

Reply via email to