Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top level route "" fails with null pointer exception, and you can't use "/" as alternative #170

Closed
apatrida opened this issue Jul 30, 2015 · 2 comments

Comments

@apatrida
Copy link

When your route is "" or "/" you have to call router.route() instead of router.route(myPath) which means if you are generically mounting things you have to constantly have an if statement to check the contents of myPath and call route() instead if empty or "/". instead route(myPath) should allow "/" as a route path.

@pmlopes
Copy link
Member

pmlopes commented Aug 3, 2015

Empty route is not valid according to HTTP spec:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html

A request URI can either be:

  • *
  • an absolute path (therefore "" is not valid)
  • an absolute URI (same as before)
  • an authority

The same document also states that the path MUST not be empty and if not present the root must be "/".

We can however add some checks and at startup fail if myPath is "".

@apatrida
Copy link
Author

apatrida commented Aug 3, 2015

Yes, the case was that we created a Router that is mounted under another router, so the HTTP spec doesn't really apply to configuring the nested router, and the code ended up with empty string which caused an index out of bounds exception. The other case didn't exist, I thought there was another case where route() and route(path) behaved differently for what they allowed, but don't seem to be able to find it again.

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(String.java:646) ~[na:1.8.0_25]
    at io.vertx.ext.web.impl.RouteImpl.checkPath(RouteImpl.java:410) ~[vertx-web-3.0.0.jar:na]
    at io.vertx.ext.web.impl.RouteImpl.<init>(RouteImpl.java:76) ~[vertx-web-3.0.0.jar:na]
    at io.vertx.ext.web.impl.RouterImpl.route(RouterImpl.java:76) ~[vertx-web-3.0.0.jar:na]
    at com.collokia.web.api.ApiVerticle$start$3.invoke(ApiVerticle.kt:77) ~[main/:na]
    at com.collokia.web.api.ApiVerticle$start$3.invoke(ApiVerticle.kt:51) ~[main/:na]
    at nl.komponents.kovenant.AsyncPromise$wrapper$1.invoke(promises-jvm.kt:111) ~[kovenant-core-2.2.1.jar:na]
    at nl.komponents.kovenant.AsyncPromise$wrapper$1.invoke(promises-jvm.kt:103) ~[kovenant-core-2.2.1.jar:na]
    at org.collokia.kommon.vertx.VertxWorkerDispatcher$offer$1.handle(Vertx.kt:288) ~[main/:na]
    at org.collokia.kommon.vertx.VertxWorkerDispatcher$offer$1.handle(Vertx.kt:285) ~[main/:na]
    at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$14(ContextImpl.java:279) ~[vertx-core-3.0.0.jar:na]
    at io.vertx.core.impl.ContextImpl$$Lambda$36/1592969175.run(Unknown Source) ~[na:na]
    at io.vertx.core.impl.OrderedExecutorFactory$OrderedExecutor.lambda$new$161(OrderedExecutorFactory.java:91) ~[vertx-core-3.0.0.jar:na]
    at io.vertx.core.impl.OrderedExecutorFactory$OrderedExecutor$$Lambda$32/827035437.run(Unknown Source) ~[na:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_25]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_25]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants