Open tonvanbart opened 6 years ago
the signature of the halt()
methods are very old and the forcing of return
is purely from limitations in Java. I'm not on a device with an IDE but wouldn't:
`return halt(404, "not found"); work?
Probably not, since that method still has a return type of HaltException
where to me it seems it should be void
(the halt()
methods are one-liners which throw an exception, so they're guaranteed to never return anything).
For clarification see this commit, after this the project build still completes without errors:
https://github.com/tonvanbart/spark/commit/7218618d823882151acbcdd55898647c86642409
@perwendel Hi, any update on this, or is there no time/priority?
I usually throw halt
instead of return halt
Maybe more of a question; in the project I'm working on I noticed several handler methods that returned
Object
while actually they should returnString
(JSON payloads). On closer inspection this is because internally they were callinghalt()
to signal a server error or 404 Not Found in certain situations. Since the methods called halt instead of doingthrow halt()
the compiler forces a return statement, and since it's either returning a String or an exception (which is thrown but never returned anyway) the return type had to beObject
. I've made a fork and changed the return tovoid
, and the build still works with all tests passing. Is there any particular reason for the signature of the static halt() methods?