From f2cb2c379113355db26866a9e21959922888e355 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 27 Jan 2020 10:03:42 +0100 Subject: [PATCH] :sparkles: Fix many reflection warnings. --- backend/src/uxbox/core.clj | 2 +- backend/src/uxbox/http/errors.clj | 6 ++-- backend/src/uxbox/tasks/impl.clj | 2 +- backend/src/uxbox/util/blob.clj | 2 +- backend/src/uxbox/util/dispatcher.clj | 3 +- backend/src/uxbox/util/pgsql.clj | 34 ++++++++++++------- backend/src/uxbox/util/storage.clj | 4 +-- backend/src/uxbox/util/template.clj | 8 ++--- backend/src/uxbox/util/time.clj | 17 +++++++--- backend/vendor/sodi/src/sodi/prng.clj | 6 ++-- backend/vendor/sodi/src/sodi/pwhash.clj | 2 +- backend/vendor/vertx/src/vertx/core.clj | 12 ++++--- backend/vendor/vertx/src/vertx/http.clj | 9 ++--- backend/vendor/vertx/src/vertx/timers.clj | 2 +- backend/vendor/vertx/src/vertx/util.clj | 19 ++++++----- backend/vendor/vertx/src/vertx/web.clj | 4 +-- backend/vendor/vertx/src/vertx/web/client.clj | 2 +- .../vertx/src/vertx/web/interceptors.clj | 2 +- 18 files changed, 79 insertions(+), 57 deletions(-) diff --git a/backend/src/uxbox/core.clj b/backend/src/uxbox/core.clj index c259375ec7..44290af85b 100644 --- a/backend/src/uxbox/core.clj +++ b/backend/src/uxbox/core.clj @@ -15,4 +15,4 @@ (defstate system :start (vc/system) - :stop (.close system)) + :stop (vc/stop system)) diff --git a/backend/src/uxbox/http/errors.clj b/backend/src/uxbox/http/errors.clj index 0b190dad17..23593eef4e 100644 --- a/backend/src/uxbox/http/errors.clj +++ b/backend/src/uxbox/http/errors.clj @@ -44,7 +44,7 @@ (defmethod handle-exception :service-error [err req] - (handle-exception (.getCause err) req)) + (handle-exception (.getCause ^Throwable err) req)) (defmethod handle-exception :parse [err req] @@ -56,7 +56,7 @@ [err req] (log/error "Unhandled exception on request:" (:path req) "\n" (with-out-str - (.printStackTrace err (java.io.PrintWriter. *out*)))) + (.printStackTrace ^Throwable err (java.io.PrintWriter. *out*)))) {:status 500 :body {:type :exception :message (ex-message err) @@ -66,5 +66,5 @@ [error req] (if (or (instance? java.util.concurrent.CompletionException error) (instance? java.util.concurrent.ExecutionException error)) - (handle-exception (.getCause error) req) + (handle-exception (.getCause ^Throwable error) req) (handle-exception error req))) diff --git a/backend/src/uxbox/tasks/impl.clj b/backend/src/uxbox/tasks/impl.clj index 8ac6ef23f6..9de5eec2b7 100644 --- a/backend/src/uxbox/tasks/impl.clj +++ b/backend/src/uxbox/tasks/impl.clj @@ -34,7 +34,7 @@ ;; --- Task Execution (defn- string-strack-trace - [err] + [^Throwable err] (with-out-str (.printStackTrace err (java.io.PrintWriter. *out*)))) diff --git a/backend/src/uxbox/util/blob.clj b/backend/src/uxbox/util/blob.clj index 1fcb0f0232..e32dcfb9bd 100644 --- a/backend/src/uxbox/util/blob.clj +++ b/backend/src/uxbox/util/blob.clj @@ -58,7 +58,7 @@ (decode-v1 data udata-len))))) (defn- decode-v1 - [data udata-len] + [^bytes data udata-len] (let [^bytes output-ba (byte-array udata-len)] (Snappy/uncompress data 6 (- (alength data) 6) output-ba 0) (t/decode output-ba {:type :json}))) diff --git a/backend/src/uxbox/util/dispatcher.clj b/backend/src/uxbox/util/dispatcher.clj index 4d304e109a..80468c02bc 100644 --- a/backend/src/uxbox/util/dispatcher.clj +++ b/backend/src/uxbox/util/dispatcher.clj @@ -100,7 +100,8 @@ f `(fn ~args ~@body)] `(do (s/assert dispatcher? ~sym) - (.add ~sym ~key ~f ~meta) + (.add ~(with-meta sym {:tag 'uxbox.util.dispatcher.IDispatcher}) + ~key ~f ~meta) ~sym))) (def spec-interceptor diff --git a/backend/src/uxbox/util/pgsql.clj b/backend/src/uxbox/util/pgsql.clj index eb6a30804b..15919f89cf 100644 --- a/backend/src/uxbox/util/pgsql.clj +++ b/backend/src/uxbox/util/pgsql.clj @@ -17,8 +17,13 @@ io.vertx.core.AsyncResult io.vertx.core.buffer.Buffer io.vertx.pgclient.PgPool + io.vertx.pgclient.PgConnection io.vertx.sqlclient.impl.ArrayTuple + io.vertx.sqlclient.SqlClient io.vertx.sqlclient.RowSet + io.vertx.sqlclient.Row + io.vertx.sqlclient.Tuple + io.vertx.sqlclient.Transaction io.vertx.sqlclient.PoolOptions)) (declare impl-execute) @@ -79,10 +84,10 @@ (p/map first (apply query args))) (defn row->map - [row] + [^Row row] (reduce (fn [acc index] (let [cname (.getColumnName row index)] - (assoc acc cname (.getValue row index)))) + (assoc acc cname (.getValue row ^int index)))) {} (range (.size row)))) @@ -102,18 +107,21 @@ [resolve reject] (reify Handler (handle [_ ar] - (if (.failed ar) - (reject (.cause ar)) - (resolve (.result ar)))))) + (if (.failed ^AsyncResult ar) + (reject (.cause ^AsyncResult ar)) + (resolve (.result ^AsyncResult ar)))))) (defn- impl-execute - [conn sql params] + [^SqlClient conn ^String sql params] (if (seq params) - (p/create #(.preparedQuery conn sql (seqable->tuple params) (impl-handler %1 %2))) - (p/create #(.query conn sql (impl-handler %1 %2))))) + (p/create #(.preparedQuery conn sql + ^Tuple (seqable->tuple params) + ^Handler (impl-handler %1 %2))) + (p/create #(.query conn sql + ^Handler (impl-handler %1 %2))))) (defn- impl-query - [conn sql params {:keys [xfm] :as opts}] + [^SqlClient conn ^String sql params {:keys [xfm] :as opts}] (let [conn (if (instance? IDeref conn) @conn conn)] (-> (impl-execute conn sql params) (p/catch (fn [err] @@ -126,11 +134,11 @@ (defn impl-transact [pool f] (let [pool (if (instance? IDeref pool) @pool pool)] - (letfn [(commit [tx] + (letfn [(commit [^Transaction tx] (p/create #(.commit tx (impl-handler %1 %2)))) - (rollback [tx] + (rollback [^Transaction tx] (p/create #(.rollback tx (impl-handler %1 %2)))) - (on-connect [conn] + (on-connect [^PgConnection conn] (let [tx (.begin conn) df (p/deferred)] (-> (f conn) @@ -147,6 +155,6 @@ (p/reject! df e') (p/resolve! df v))))))))) df))] - (-> (p/create #(.getConnection pool (impl-handler %1 %2))) + (-> (p/create #(.getConnection ^PgPool pool (impl-handler %1 %2))) (p/bind on-connect))))) diff --git a/backend/src/uxbox/util/storage.clj b/backend/src/uxbox/util/storage.clj index efc5ac9db4..97e3164fc1 100644 --- a/backend/src/uxbox/util/storage.clj +++ b/backend/src/uxbox/util/storage.clj @@ -58,7 +58,7 @@ path)) (defn blob - [v] + [^String v] (let [data (.getBytes v "UTF-8")] (ByteArrayInputStream. ^bytes data))) @@ -162,7 +162,7 @@ (def ^:private prng (delay (doto (java.security.SecureRandom/getInstance "SHA1PRNG") - (.setSeed (sodi.prng/random-bytes 64))))) + (.setSeed ^bytes (sodi.prng/random-bytes 64))))) (defn random-path [^Path path] diff --git a/backend/src/uxbox/util/template.clj b/backend/src/uxbox/util/template.clj index a48ef1ea13..36b4de1195 100644 --- a/backend/src/uxbox/util/template.clj +++ b/backend/src/uxbox/util/template.clj @@ -41,13 +41,13 @@ "")))) (or (vector? x) (list? x)) - (java.util.ArrayList. x) + (java.util.ArrayList. ^java.util.List x) (map? x) - (java.util.HashMap. x) + (java.util.HashMap. ^java.util.Map x) (set? x) - (java.util.HashSet. x) + (java.util.HashSet. ^java.util.Set x) :else x)) @@ -60,7 +60,7 @@ (let [context (adapt-context context) template (.compile +mustache-factory+ path)] (with-out-str - (let [scope (HashMap. (walk/stringify-keys context))] + (let [scope (HashMap. ^java.util.Map (walk/stringify-keys context))] (.execute ^Mustache template *out* scope)))) (catch Exception cause (ex/raise :type :internal diff --git a/backend/src/uxbox/util/time.clj b/backend/src/uxbox/util/time.clj index 749e97059d..4d5ff33a9b 100644 --- a/backend/src/uxbox/util/time.clj +++ b/backend/src/uxbox/util/time.clj @@ -6,12 +6,14 @@ (ns uxbox.util.time (:require + [clojure.spec.alpha :as s] [uxbox.common.exceptions :as ex] [cognitect.transit :as t]) (:import java.time.Instant java.time.OffsetDateTime java.time.Duration + java.util.Date org.apache.logging.log4j.core.util.CronExpression)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -161,13 +163,18 @@ [v] (instance? CronExpression v)) +(defn next-valid-instant-from + [^CronExpression cron ^Instant now] + (s/assert cron? cron) + (.toInstant (.getNextValidTimeAfter cron (Date/from now)))) + (defmethod print-method CronExpression [mv ^java.io.Writer writer] - (.write writer (str "#uxbox/cron \"" (.toString mv) "\""))) + (.write writer (str "#uxbox/cron \"" (.toString ^CronExpression mv) "\""))) (defmethod print-dup CronExpression [o w] - (print-ctor o (fn [o w] (print-dup (.toString o) w)) w)) + (print-ctor o (fn [o w] (print-dup (.toString ^CronExpression o) w)) w)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Serialization @@ -178,12 +185,12 @@ (def ^:private instant-write-handler (t/write-handler (constantly "m") - (fn [v] (str (.toEpochMilli v))))) + (fn [v] (str (.toEpochMilli ^Instant v))))) (def ^:private offset-datetime-write-handler (t/write-handler (constantly "m") - (fn [v] (str (.toEpochMilli (.toInstant v)))))) + (fn [v] (str (.toEpochMilli (.toInstant ^OffsetDateTime v)))))) (def ^:private read-handler (t/read-handler @@ -199,7 +206,7 @@ (defmethod print-method Instant [mv ^java.io.Writer writer] - (.write writer (str "#instant \"" (.toString mv) "\""))) + (.write writer (str "#instant \"" (.toString ^Instant mv) "\""))) (defmethod print-dup Instant [o w] (print-method o w)) diff --git a/backend/vendor/sodi/src/sodi/prng.clj b/backend/vendor/sodi/src/sodi/prng.clj index 6c0fb9d514..039e02c60f 100644 --- a/backend/vendor/sodi/src/sodi/prng.clj +++ b/backend/vendor/sodi/src/sodi/prng.clj @@ -23,7 +23,7 @@ iv/salt or arbitrary length." ([^long numbytes] (let [buffer (byte-array numbytes)] - (.nextBytes rng buffer) + (.nextBytes ^SecureRandom rng buffer) buffer)) ([^SecureRandom rng ^long numbytes] (let [buffer (byte-array numbytes)] @@ -36,7 +36,7 @@ generator. The minimum value is 8 bytes, and recommended minimum value is 32." [^long numbytes] - (let [buffer (ByteBuffer/allocate numbytes)] + (let [^ByteBuffer buffer (ByteBuffer/allocate numbytes)] (.putLong buffer (System/currentTimeMillis)) - (.put buffer (random-bytes (.remaining buffer))) + (.put buffer ^bytes (random-bytes (.remaining buffer))) (.array buffer))) diff --git a/backend/vendor/sodi/src/sodi/pwhash.clj b/backend/vendor/sodi/src/sodi/pwhash.clj index ef09a7281b..6bebfd5391 100644 --- a/backend/vendor/sodi/src/sodi/pwhash.clj +++ b/backend/vendor/sodi/src/sodi/pwhash.clj @@ -51,7 +51,7 @@ [{:keys [alg password salt cpucost] :as options}] (let [salt (or salt (rng/random-bytes 16)) cpucost (or cpucost 50000) - pwd (.toCharArray password) + pwd (.toCharArray ^String password) spec (PBEKeySpec. pwd salt cpucost 512) skf (SecretKeyFactory/getInstance "PBKDF2WithHmacSHA256") hash (.getEncoded (.generateSecret skf spec))] diff --git a/backend/vendor/vertx/src/vertx/core.clj b/backend/vendor/vertx/src/vertx/core.clj index 92e6ecaf08..029adef99f 100644 --- a/backend/vendor/vertx/src/vertx/core.clj +++ b/backend/vendor/vertx/src/vertx/core.clj @@ -45,6 +45,10 @@ (vxe/configure! vsm opts) vsm))) +(defn stop + [^Vertx o] + (.close o)) + (defn get-or-create-context [vsm] (.getOrCreateContext ^Vertx (vu/resolve-system vsm))) @@ -64,7 +68,7 @@ (reify Handler (handle [_ prm] (try - (.resolve ^Promise prm (apply f args)) + (.complete ^Promise prm (apply f args)) (catch Throwable e (.fail ^Promise prm e))))) false @@ -191,7 +195,7 @@ (p/handle (fn [state error] (if error (do - (.fail o error) + (.fail o ^Throwable error) (on-error @ctx error)) (do (when (map? state) @@ -202,7 +206,7 @@ (fn [_ err] (if err (do (on-error err) - (.fail o err)) + (.fail o ^Throwable err)) (.complete o)))))))) (defn- build-actor @@ -244,7 +248,7 @@ (let [opts (VertxOptions.)] (when threads (.setEventLoopPoolSize opts (int threads))) (when worker-threads (.setWorkerPoolSize opts (int worker-threads))) - (when on-error (.exceptionHandler (vu/fn->handler on-error))) + #_(when on-error (.exceptionHandler opts (vu/fn->handler on-error))) opts)) diff --git a/backend/vendor/vertx/src/vertx/http.clj b/backend/vendor/vertx/src/vertx/http.clj index 1f29efb6f2..3f9800afc6 100644 --- a/backend/vendor/vertx/src/vertx/http.clj +++ b/backend/vendor/vertx/src/vertx/http.clj @@ -40,7 +40,7 @@ (loop [m (transient {})] (if (.hasNext it) (let [^Map$Entry me (.next it) - key (.toLowerCase (.getKey me)) + key (.toLowerCase ^String (.getKey me)) val (.getValue me)] (recur (assoc! m key val))) (persistent! m))))) @@ -91,8 +91,8 @@ (.setReusePort opts true) (.setTcpNoDelay opts true) (.setTcpFastOpen opts true) - (when host (.setHost opts host)) - (when port (.setPort opts port)) + (when host (.setHost opts ^String host)) + (when port (.setPort opts ^int port)) opts)) (defn- resolve-handler @@ -135,7 +135,8 @@ (extend-protocol IAsyncBody (Class/forName "[B") (-handle-body [data res] - (.end ^HttpServerResponse res (Buffer/buffer data))) + (.end ^HttpServerResponse res (Buffer/buffer ^bytes data))) + Buffer (-handle-body [data res] (.end ^HttpServerResponse res ^Buffer data)) diff --git a/backend/vendor/vertx/src/vertx/timers.clj b/backend/vendor/vertx/src/vertx/timers.clj index c7519074ed..2bdd389cf3 100644 --- a/backend/vendor/vertx/src/vertx/timers.clj +++ b/backend/vendor/vertx/src/vertx/timers.clj @@ -72,5 +72,5 @@ java.lang.AutoCloseable (close [this] (when (compare-and-set! state tid nil) - (.cancelTimer system tid)))))) + (.cancelTimer ^Vertx system tid)))))) diff --git a/backend/vendor/vertx/src/vertx/util.clj b/backend/vendor/vertx/src/vertx/util.clj index 7e7f091137..8c25357829 100644 --- a/backend/vendor/vertx/src/vertx/util.clj +++ b/backend/vendor/vertx/src/vertx/util.clj @@ -35,17 +35,18 @@ [d] (reify Handler (handle [_ ar] - (if (.failed ar) - (p/reject! d (.cause ar)) - (p/resolve! d (.result ar)))))) + (if (.failed ^AsyncResult ar) + (p/reject! d (.cause ^AsyncResult ar)) + (p/resolve! d (.result ^AsyncResult ar)))))) (defmacro doseq "A faster version of doseq." [[bsym csym] & body] - `(let [it# (.iterator ~csym)] - (loop [] - (when (.hasNext it#) - (let [~bsym (.next it#)] - ~@body - (recur)))))) + (let [itsym (gensym "iterator")] + `(let [~itsym (.iterator ~(with-meta csym {:tag 'java.lang.Iterable}))] + (loop [] + (when (.hasNext ~(with-meta itsym {:tag 'java.util.Iterator})) + (let [~bsym (.next ~itsym)] + ~@body + (recur))))))) diff --git a/backend/vendor/vertx/src/vertx/web.clj b/backend/vendor/vertx/src/vertx/web.clj index 4172ddb267..d1dc5ecfb0 100644 --- a/backend/vendor/vertx/src/vertx/web.clj +++ b/backend/vendor/vertx/src/vertx/web.clj @@ -52,7 +52,7 @@ :method (-> request .rawMethod .toLowerCase keyword) ::vh/request request ::vh/response response - ::execution-context (.getContext system) + ;; ::execution-context (.getContext system) ::routing-context routing-context})) (defn handler @@ -147,7 +147,7 @@ (let [req (->request rc) efn (fn [err] (.put ^RoutingContext rc "vertx$clj$req" req) - (.fail ^RoutingContext rc err))] + (.fail ^RoutingContext rc ^Throwable err))] (try (-> (vh/-handle-response (f req) req) (p/catch' efn)) diff --git a/backend/vendor/vertx/src/vertx/web/client.clj b/backend/vendor/vertx/src/vertx/web/client.clj index 8765bb5865..aff725e7fa 100644 --- a/backend/vendor/vertx/src/vertx/web/client.clj +++ b/backend/vendor/vertx/src/vertx/web/client.clj @@ -43,7 +43,7 @@ (defn get ([session url] (get session url {})) ([session url opts] - (let [^HttpRequest req (.getAbs session url) + (let [^HttpRequest req (.getAbs ^WebClientSession session url) d (p/deferred)] (.send req (vu/deferred->handler d)) (p/then d (fn [^HttpResponse res] diff --git a/backend/vendor/vertx/src/vertx/web/interceptors.clj b/backend/vendor/vertx/src/vertx/web/interceptors.clj index eaad85d366..cd4d289c88 100644 --- a/backend/vendor/vertx/src/vertx/web/interceptors.clj +++ b/backend/vendor/vertx/src/vertx/web/interceptors.clj @@ -69,7 +69,7 @@ (loop [m (transient {})] (if (.hasNext it) (let [^Map$Entry o (.next it) - key (keyword (.toLowerCase (.getKey o))) + key (keyword (.toLowerCase ^String (.getKey o))) prv (get m key ::default) val (.getValue o)] (cond