RFR: 8269692: sun.net.httpserver.ServerImpl::createContext should throw IAE
Daniel Fuchs
dfuchs at openjdk.java.net
Fri Jul 2 13:42:00 UTC 2021
On Fri, 2 Jul 2021 11:56:04 GMT, Julia Boes <jboes at openjdk.org> wrote:
> `com.sun.net.httpserver.HttpServer::createContext` specifies `IllegalArgumentException` to be thrown if a context already exists for the path provided. The implementation class`sun.net.httpserver.ServerImpl` does not comply with this, which is fixed by this change.
>
> Testing: Tier 1-3 all clear.
Changes requested by dfuchs (Reviewer).
src/jdk.httpserver/share/classes/sun/net/httpserver/ContextList.java line 44:
> 42: }
> 43:
> 44: synchronized boolean contains(HttpContextImpl ctx) {
You can remove synchronized here since you're calling a synchronized method.
test/jdk/com/sun/net/httpserver/HttpContextTest.java line 67:
> 65: assertThrows(IAE, () -> server.createContext(path, new Handler()));
> 66: server.removeContext(path);
> 67: assertThrows(IAE, () -> server.removeContext(path));
Can you add some test to double check that having a context named "/foo/" doesn't prevent you from adding a subcontext "/foo/bar/"?
Same for "/foo" and "/foobar".
-------------
PR: https://git.openjdk.java.net/jdk/pull/4665
More information about the net-dev
mailing list