Skip to content

Commit fcaeab6

Browse files
committed
ClojureBindings: avoid warnings in map population
Calling the Var.intern method dumps a warning to stderr when an already-existing variable is requested. I did not study the code extremely carefully, but it seems like internally, Clojure discovers an existing variable, decides to overwrite it with a different variable object for some reason, and then warns that it has done so. But this phenomenon apparently occurs only once. In any case, the workaround is simply to avoid calling Var.intern, in favor of Namespace.getMappings().valAt(Symbol) directly.
1 parent 043982b commit fcaeab6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/java/org/scijava/plugins/scripting/clojure/ClojureBindings.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,16 @@ private static Map<String, Object> map() {
172172
for (final Object el : ns.getMappings()) {
173173
final MapEntry entry = (MapEntry) el;
174174
final Symbol key = (Symbol) entry.key();
175-
final Object value = Var.intern(ns, key).get();
176-
if (value instanceof Var.Unbound) continue; // skip weird variables
177-
map.put(key.getName(), value);
175+
// NB: Unfortunately, we cannot simply write:
176+
// final Object value = Var.intern(ns, key).get();
177+
// because it issues a warning for already-existing variables.
178+
// So instead, we replicate some of its internals here.
179+
final Object valAt = ns.getMappings().valAt(key);
180+
final Var valVar = valAt instanceof Var ? ((Var) valAt) : null;
181+
if (valVar == null) continue; // skip non-variables
182+
if (valVar.ns != ns) continue; // skip non-user vars
183+
if (!valVar.isBound()) continue; // skip unbound vars
184+
map.put(key.getName(), valVar.get());
178185
}
179186

180187
return map;

0 commit comments

Comments
 (0)