Hello Christian, thansk for your report, I've entered an issue for this point http://restlet.tigris.org/issues/show_bug.cgi?id=1157
Best regards, Thierry Boileau 2010/7/27 Christian Bauer <[email protected]> > I'm trying to figure out how to test a Component and I've encountered this > piece of code in HostRoute that will most likely always throw an NPE: > > > ... > int resourcePortValue = request.getResourceRef().getHostPort(); > if (resourcePortValue == -1) { > resourcePortValue = request.getResourceRef() > .getSchemeProtocol().getDefaultPort(); > } > > > All of the checks before and afterwards test for null but the > getSchemePort() might be null as well, so getDefaultPort() will throw the > NPE. > > Just create a request in a unit test: > > > Request req = new Request(Method.GET, "/foo"); > component.handle(req, res); > > > with a relative URL and you'll get: > > > java.lang.NullPointerException > at org.restlet.engine.component.HostRoute.score(HostRoute.java:159) > at org.restlet.util.RouteList.getFirst(RouteList.java:121) > at org.restlet.routing.Router.getNext(Router.java:639) > at org.restlet.routing.Router.handle(Router.java:733) > at org.restlet.routing.Filter.doHandle(Filter.java:156) > at > org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:154) > at org.restlet.routing.Filter.handle(Filter.java:203) > at org.restlet.engine.ChainHelper.handle(ChainHelper.java:111) > at org.restlet.Component.handle(Component.java:390) > > > So it seems this has to be an absolute URL, which seems wrong to me. If my > Component only has a default host, I'm not using name-based virtual hosts > at > all. Don't make me supply a value that has no function. In fact, the rest > of > the code in HostRoute.score() looks like it should work well with a > relative > URI and (default) host matching. > > > > -- > View this message in context: > http://restlet-discuss.1400322.n2.nabble.com/NPE-in-HostRoute-tp5342978p5342978.html > Sent from the Restlet Discuss mailing list archive at Nabble.com. > > ------------------------------------------------------ > > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2638885 > ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2639884

