Skip to content

Commit 10089ca

Browse files
plexusexpez
authored andcommitted
Handle NoClassDefFoundError when determining class type
When `resolve-missing` gets a number of candidate classes, it will load them to determine the type (Clojure type/record vs regular Java class). However a class on the classpath may be compiled with dependencies that are not currently present, causing the loading to fail. This would cause the whole operation to fail, instead this change handles the exception, takes it as a sign that it's a regular Java class, and continues. For example, I do a `resolve-missing` on the symbol URL, this yields two candidates: `java.net.URL`, and `com.gargoylesoftware.htmlunit.javascript.host.URL`. The latter depends on `org.w3c.dom.ElementTraversal`, which is not currently present, causing a `NoClassDefFoundError`.
1 parent df24f30 commit 10089ca

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
### Bugs fixed
66

7-
*
87
* [#185](https://github.com/clojure-emacs/refactor-nrepl/issues/185) Report throwables of type `Error` instead of swallowing them.
8+
* [#186](https://github.com/clojure-emacs/refactor-nrepl/issues/186) Make sure `resolve-missing` still works, even if a candidate class has missing dependencies.
99
* [clojure-emacs/clj-refactor.el#330](https://github.com/clojure-emacs/clj-refactor.el/issues/332) `clean-ns` removes imported inner inner classes.
1010
* [clojure-emacs/clj-refactor.el#330](https://github.com/clojure-emacs/clj-refactor.el/issues/330) `clean-ns` ignores namespaced keywords.
1111
* [#160](https://github.com/clojure-emacs/refactor-nrepl/issues/160) Make `resolve-missing` find newly defined vars and types (clj). Because of a stale cache, newly added vars or types would not be found. This fix takes into account vars/types added by eval-ing code (rescan affected namespace), and by hotloading dependencies (reset the cache).

src/refactor_nrepl/ns/resolve_missing.clj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@
2525

2626
(defn- collate-type-info
2727
[candidates]
28-
(map (fn [candidate] {:name candidate :type (get-type candidate)}) candidates))
28+
(map (fn [candidate]
29+
(try
30+
{:name candidate :type (get-type candidate)}
31+
32+
;; This happends when class `candidate` depends on a class that is
33+
;; not available on the classpath.
34+
(catch NoClassDefFoundError e
35+
{:name candidate :type :class})))
36+
candidates))
37+
2938

3039
(defn- inlined-dependency? [candidate]
3140
(or (-> candidate str (.startsWith "deps."))

0 commit comments

Comments
 (0)