juxt / bidi

Bidirectional URI routing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reflection warning on java.net.URLDecoder/decode

harold opened this issue · comments

First, thanks for bidi - it's great, we have used it for frontend and backend routing for years and it has greatly simplified swaths of code around urls. If it didn't exist, we'd need to start by making something just like it (but ours would be worse).

Low-priority note:

I get a reflection warning while compiling bidi:

$ lein check
Compiling namespace bidi.bidi
Reflection warning, bidi/bidi.cljc:20:31 - call to static method decode on java.net.URLDecoder can't be resolved (argument types: java.lang.String, unknown).
Compiling namespace bidi.ring
Compiling namespace bidi.schema
Compiling namespace bidi.verbose
Compiling namespace bidi.vhosts

It's right here:

I experimented with this:

diff --git a/src/bidi/bidi.cljc b/src/bidi/bidi.cljc
index 9fca662..645122b 100644
--- a/src/bidi/bidi.cljc
+++ b/src/bidi/bidi.cljc
@@ -16,7 +16,7 @@
 (defn url-decode
   ([string] #?(:clj (url-decode string "UTF-8")
                :cljs (some-> string str (js/decodeURIComponent))))
-  #?(:clj ([string encoding]
+  #?(:clj ([string ^String encoding]
            (some-> string str (java.net.URLDecoder/decode encoding)))))

And it's cleaned up:

$ lein check
Compiling namespace bidi.bidi
Compiling namespace bidi.ring
Compiling namespace bidi.schema
Compiling namespace bidi.verbose
Compiling namespace bidi.vhosts

iiuc, this should be a safe change, because the two-argument arity of static /decode always takes two strings. Maybe this would be a nice improvement to include in a future release.

Thanks again for your time and consideration.