New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix detection of dotted ns alias #87

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
1 participant
@nberger
Copy link
Contributor

nberger commented Jun 3, 2015

Due to http://dev.clojure.org/jira/browse/CLJ-1403, a dotted ns alias like [clojure.java.io :as java.io] or [clj-time.coerce :as time.coerce] throws a ClassNotFoundException with the ns alias as the message. Identifying this special case in the regrow process allows us to keep looking for the correct alias

Fix detection of dotted ns alias
Due to http://dev.clojure.org/jira/browse/CLJ-1403, a dotted ns alias like
[clojure.java.io :as java.io] or [clj-time.coerce :as time.coerce] throws
a ClassNotFoundException with the alias as the message. Identifying this
case allows us to keep looking for the correct alias
@nberger

This comment has been minimized.

Copy link
Contributor Author

nberger commented Aug 20, 2015

I'll show an example to explain a bit more about this, and why I think it's an important issue:

With the current version of slamhound, I get the following:

› cat src/try_lein_slamhound/core.clj 
(ns try-lein-slamhound.core
  "Testing using dot in alias"
  (:require
    [clojure.string :as string]
    [clojure.java.io :as java.io]))

(java.io/resource "some-resource")

› DEBUG=true lein run -m slam.hound src/try_lein_slamhound/core.clj
... # lein debug output omitted
Failed to reconstruct: #object[java.io.File 0xc69ccdb src/try_lein_slamhound/core.clj]
java.lang.ClassNotFoundException: java.io
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        ....

And the file was untouched.

Without DEBUG=true, the output is worse, just the non-found ns:

› lein run -m slam.hound src/try_lein_slamhound/core.clj            
Failed to reconstruct: #object[java.io.File 0x37811d8d src/try_lein_slamhound/core.clj]
java.io

With this PR applied:

› DEBUG=true lein run -m slam.hound src/try_lein_slamhound/core.clj
# no output from slamhound, only lein debug output

› cat src/try_lein_slamhound/core.clj 
(ns try-lein-slamhound.core
  "Testing using dot in alias"
  (:require [clojure.java.io :as java.io]))

(java.io/resource "some-resource")

Summary: java.io was respected, clojure.string alias was removed because it's not being used, and there was no exception :)

Dotted namespaces are not only respected but are inferred to:

› cat > src/try_lein_slamhound/core.clj 
(ns try-lein-slamhound.core
  "Testing using dot in alias"
  (:require
    [clojure.string :as string]))

(java.io/resource "some-resource")

› DEBUG=true lein run -m slam.hound src/try_lein_slamhound/core.clj
.... # lein debug output omitted

› cat src/try_lein_slamhound/core.clj 
(ns try-lein-slamhound.core
  "Testing using dot in alias"
  (:require [clojure.java.io :as java.io]))

(java.io/resource "some-resource")

@guns: I'd like to know your thoughts about this. I can't say that the implementation is elegant, but it seems to work and is in line with the overally strategy.

To me, this is a blocking issue. I like to be able to use slamhound when I use dotted aliases. One could say "Why are you using java.io when you could use just io". I prefer java.io. And anyways, what about the following:

(:require [clojure.data.zip.xml :as zip.xml]
              [clojure.xml :as xml]
              [clojure.data.zip :as data.zip]
              [clojure.zip :as zip])

@nberger nberger closed this Jun 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment