clojure-maven-plugin icon indicating copy to clipboard operation
clojure-maven-plugin copied to clipboard

NamespaceDiscovery.findNamespaceInFile String index out of range

Open craigworrall opened this issue 6 years ago • 1 comments

Using version 1.8.3. The stack trace below seems to occur when a file is found in a source dir, and the file name and ns symbol within do not correspond. In my case, the file was not even a ".clj" file, but had clj source.

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -45 at java.lang.String.substring (String.java:1967) at com.theoryinpractise.clojure.NamespaceDiscovery.findNamespaceInFile (NamespaceDiscovery.java:161) at com.theoryinpractise.clojure.NamespaceDiscovery.discoverNamespacesIn (NamespaceDiscovery.java:133) at com.theoryinpractise.clojure.NamespaceDiscovery.discoverNamespacesInPath (NamespaceDiscovery.java:108) at com.theoryinpractise.clojure.NamespaceDiscovery.discoverNamespacesIn (NamespaceDiscovery.java:75)

craigworrall avatar Aug 26 '19 05:08 craigworrall

The plugin doesn't read the ns, it just infers it from the file name, see https://github.com/talios/clojure-maven-plugin/blob/develop/src/main/java/com/theoryinpractise/clojure/NamespaceDiscovery.java#L160

It also assumes the file name has an extension which isn't necessarily the case.

The correct solution is to actually read the ns but doing that right is probably rather heavy. Some heuristics could be added though...

emilianbold avatar Jan 02 '20 19:01 emilianbold