<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged java</title>
<link>https://ask.clojure.org/index.php/tag/java</link>
<description></description>
<item>
<title>java.lang.NoClassDefFoundError: java/util/SequencedCollection</title>
<link>https://ask.clojure.org/index.php/13748/java-lang-noclassdeffounderror-java-sequencedcollection</link>
<description>&lt;p&gt;Compiling a deftype that implements List on Java 21 will create a class that includes a reference to the (new to Java 21) SequencedCollection type (which introduces a new method &lt;code&gt;reverse&lt;/code&gt;). Loading the compiled class will throw in an older Java runtime as the SequencedCollection type doesn't exist.&lt;/p&gt;
&lt;p&gt;Given repro.clj:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns repro)

(deftype C []
  java.util.List)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Compiling with Java 21 JDK to a class, javap shows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public final class repro.C implements java.util.List,clojure.lang.IType {
  public repro.C();
    Code:
       0: aload_0
       1: invokespecial #13  // Method java/lang/Object.&quot;&amp;lt;init&amp;gt;&quot;:()V
       4: return

  public static clojure.lang.IPersistentVector getBasis();
    Code:
       0: invokestatic  #20  // Method clojure/lang/Tuple.create:()Lclojure/lang/IPersistentVector;
       3: areturn

  public java.util.SequencedCollection reversed();
    Code:
       0: aload_0
       1: invokeinterface #25,  1   // InterfaceMethod java/util/List.reversed:()Ljava/util/List;
       6: areturn

  public static {};
    Code:
       0: return
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Loading this class in Clojure with an older Java version throws:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; (require 'repro)
Execution error (ClassNotFoundException) at jdk.internal.loader.BuiltinClassLoader/loadClass (BuiltinClassLoader.java:641).
java.util.SequencedCollection
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;List includes a default &lt;code&gt;reversed()&lt;/code&gt; method implementation for the &lt;code&gt;SequenceCollection&lt;/code&gt; parent interface. Not sure why this forwarding method is getting created here but it's presumably different than others because it's a parent default method impl that we're forwarding to.&lt;/p&gt;
</description>
<category>Records and Types</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13748/java-lang-noclassdeffounderror-java-sequencedcollection</guid>
<pubDate>Wed, 21 Feb 2024 03:29:09 +0000</pubDate>
</item>
<item>
<title>Seed support in java.util.Random</title>
<link>https://ask.clojure.org/index.php/13237/seed-support-in-java-util-random</link>
<description>&lt;p&gt;Is it possible to add additional arities for functions like &lt;code&gt;rand&lt;/code&gt;, &lt;code&gt;rand-int&lt;/code&gt;, &lt;code&gt;rand-nth&lt;/code&gt; etc. to support seeds passed to the Java methods? It could also be nice to create other functions for more secure variants than &lt;code&gt;java.util.Random&lt;/code&gt;, maybe &lt;code&gt;SecureRandom&lt;/code&gt;? I really don't know what is most widely used so that's just an idea.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13237/seed-support-in-java-util-random</guid>
<pubDate>Wed, 30 Aug 2023 17:01:05 +0000</pubDate>
</item>
<item>
<title>Immutable wrapper around Java arrays?</title>
<link>https://ask.clojure.org/index.php/13224/immutable-wrapper-around-java-arrays</link>
<description>&lt;p&gt;Are there any immutable wrapper around Java arrays in Clojure, similar to &lt;a rel=&quot;nofollow&quot; href=&quot;https://scala-lang.org/api/3.x/scala/collection/immutable/ArraySeq.html&quot;&gt;Scala's ArraySeq&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;What are your thoughts on introducing such a wrapper to Clojure's core?&lt;/p&gt;
</description>
<category>Collections</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13224/immutable-wrapper-around-java-arrays</guid>
<pubDate>Mon, 28 Aug 2023 11:20:27 +0000</pubDate>
</item>
<item>
<title>Why do we need `clojure.java.process/capture` when we have `slurp`?</title>
<link>https://ask.clojure.org/index.php/13118/why-do-we-need-clojure-java-process-capture-when-we-have-slurp</link>
<description>&lt;p&gt;Clojure-1.12 added a &lt;code&gt;clojure.java.process&lt;/code&gt; namespace. I'm confused about why &lt;code&gt;clojure.java.process/capture&lt;/code&gt; is exposed as a public API, since it does basically the same thing as &lt;code&gt;slurp&lt;/code&gt; except for minor differences in options.&lt;/p&gt;
</description>
<category>IO</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13118/why-do-we-need-clojure-java-process-capture-when-we-have-slurp</guid>
<pubDate>Mon, 31 Jul 2023 08:08:12 +0000</pubDate>
</item>
<item>
<title>Feedback on the new clojure.java.process namespace</title>
<link>https://ask.clojure.org/index.php/12942/feedback-on-the-new-clojure-java-process-namespace</link>
<description>&lt;p&gt;The newest Clojure alpha added a clojure.java.process namespace. I had a need for better process spawning handling in a Clojure program I'm working on, so I investigated if it makes sense to update my Clojure dependency to 1.12.0-alpha2, and I want to give you feedback on functionality and bugs I encountered when evaluating this namespace.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Error stream -&amp;gt; stdout redirection does not work&lt;br&gt;
When supplying &lt;code&gt;:err :stdout&lt;/code&gt; opt, the launched process does not redirect the output to stdout, because &lt;code&gt;(.redirectErrorStream pb)&lt;/code&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/4090f405466ea90bbaf3addbe41f0a6acb164dbb/src/clj/clojure/java/process.clj#L89&quot;&gt;on line 89&lt;/a&gt; is a getter. It should be &lt;code&gt;(.redirectErrorStream pb true)&lt;/code&gt; instead. You can test it with &lt;code&gt;(exec {:out :inherit :err :stdout} &quot;bash&quot; &quot;-c&quot; &quot;ls &amp;gt;&amp;amp;2&quot;)&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is no way to remove env vars&lt;br&gt;
Removing env vars is a useful feature when launching the process, and it's even documented in an example in ProcessBuilder's Javadoc. I suggest adding support for the removal of env vars by treating &lt;code&gt;nil&lt;/code&gt; env values as a request to remove the env var from the launched process env.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It's impossible to override exec's &lt;code&gt;:err :inherit&lt;/code&gt; option&lt;br&gt;
Exec documentation states that it's possible to override exec's default options, but on &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/4090f405466ea90bbaf3addbe41f0a6acb164dbb/src/clj/clojure/java/process.clj#L137&quot;&gt;line 137&lt;/a&gt; the default options take precedence over user-supplied options, it should be &lt;code&gt;(merge {:err :inherit} opts)&lt;/code&gt; instead.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Capture kv-opt is &lt;code&gt;:buffer-size&lt;/code&gt;, not &lt;code&gt;:buffer&lt;/code&gt;&lt;br&gt;
On &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/4090f405466ea90bbaf3addbe41f0a6acb164dbb/src/clj/clojure/java/process.clj#L119&quot;&gt;line 119&lt;/a&gt;, &lt;code&gt;capture&lt;/code&gt; docstring says that its kv-opts are the same as in &lt;code&gt;jio/copy&lt;/code&gt; — &lt;code&gt;:buffer&lt;/code&gt; and &lt;code&gt;:encoding&lt;/code&gt;, but &lt;code&gt;jio/copy&lt;/code&gt;'s kv-opts are &lt;code&gt;:buffer-size&lt;/code&gt; and &lt;code&gt;:encoding&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nitpick: checks for the truthiness of in/out/err/dir are unnecessary&lt;br&gt;
Lines &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/4090f405466ea90bbaf3addbe41f0a6acb164dbb/src/clj/clojure/java/process.clj#L85-L90&quot;&gt;85-90&lt;/a&gt; perform checks if the opts exist, which is unnecessary because defaults are provided on line &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/4090f405466ea90bbaf3addbe41f0a6acb164dbb/src/clj/clojure/java/process.clj#L75&quot;&gt;75&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
</description>
<category>IO</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12942/feedback-on-the-new-clojure-java-process-namespace</guid>
<pubDate>Wed, 17 May 2023 07:47:53 +0000</pubDate>
</item>
<item>
<title>Why does the Clojure compiler give different output for the same input?</title>
<link>https://ask.clojure.org/index.php/12925/why-does-clojure-compiler-give-different-output-same-input</link>
<description>&lt;p&gt;I have observed an oddity with the Clojure compiler: that &lt;strong&gt;it can produce different output for the same input.&lt;/strong&gt; i.e. the generated .class files contain different bytes, though otherwise have identical runtime behavior. Why is this? I have created &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/robert-m-johnson/clj-compile-diff-demo&quot;&gt;a Docker container and script which demonstrates the problem&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Though otherwise harmless in terms of the functionality of the resulting Java program, this is an issue for any attempts to cache the compiled classes based on simple byte equality, such as with Docker layer caching. Ideally, it would be possible to compile third-party Clojure libraries and store these in a separate Docker layer in containers for Clojure apps. If such a layer resulted in the same byte output given a particular fixed set of dependencies, then the layer could be recognized as already existing when pushing to a repository. This would avoid the storage &amp;amp; network costs that result from creating a whole new uberjar for every single source change within your application code.&lt;/p&gt;
&lt;p&gt;Such caching is possible when not using AOT compilation, but this comes at the cost of slower application startup.&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12925/why-does-clojure-compiler-give-different-output-same-input</guid>
<pubDate>Mon, 08 May 2023 14:21:57 +0000</pubDate>
</item>
<item>
<title>Java method overloaded</title>
<link>https://ask.clojure.org/index.php/12208/java-method-overloaded</link>
<description>&lt;p&gt;I’m a newbie to Clojure. I want to call a Java method which is overloaded in Java, one has no parameter and the other has one parameter. I want to call the method with no parameter, but Clojure calls the method with one parameter and raise an IllegalArgumentException.&lt;/p&gt;
&lt;p&gt;How can I call the Java method with no parameter from Clojure?&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12208/java-method-overloaded</guid>
<pubDate>Fri, 16 Sep 2022 01:07:57 +0000</pubDate>
</item>
<item>
<title>Calva: Is there an option to add additional parameters when using &quot;jack-in&quot; in Calva</title>
<link>https://ask.clojure.org/index.php/11894/calva-there-option-additional-parameters-when-using-calva</link>
<description>&lt;p&gt;I was playing around with fulcro &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/fulcrologic/fulcro-template#the-api-server&quot;&gt;https://github.com/fulcrologic/fulcro-template#the-api-server&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the readme of the fulcro-template, it said &lt;code&gt;clj -A:dev -J-Dtrace -J-Dguardrails.enabled=true&lt;/code&gt;  to start a backend server. And use any editor that has REPL integration, like Cursive.&lt;/p&gt;
&lt;p&gt;I can start repl using calva jack-in, but how can I add additional parameters like &lt;code&gt;-J-Dtrace -J-Dguardrails.enabled=true&lt;/code&gt;&lt;/p&gt;
</description>
<category>Calva</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11894/calva-there-option-additional-parameters-when-using-calva</guid>
<pubDate>Wed, 18 May 2022 12:04:21 +0000</pubDate>
</item>
<item>
<title>tools.build/javac does not handle modules-info</title>
<link>https://ask.clojure.org/index.php/11428/tools-build-javac-does-not-handle-modules-info</link>
<description>&lt;p&gt;Attempting to compile a modular Java project will fail, reporting that it cannot not find the required modules.&lt;/p&gt;
&lt;p&gt;I fixed it by adding the module paths manually in &lt;code&gt;:javac-opts&lt;/code&gt;. Could tools.build handle this? Either by adding all the modules to the module path, or ignoring module-info.java and module-info.class. &lt;code&gt;tools.build/javac&lt;/code&gt; will also fail if there is a module-info.class in the classes directory and &lt;code&gt;tools.build/javac&lt;/code&gt; does not find the modules.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
</description>
<category>Tools</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11428/tools-build-javac-does-not-handle-modules-info</guid>
<pubDate>Sun, 02 Jan 2022 15:54:15 +0000</pubDate>
</item>
<item>
<title>Pesky loop bug resulting in 0xFFFFFFFF with BufferedReader (java interop)</title>
<link>https://ask.clojure.org/index.php/11415/pesky-loop-resulting-0xffffffff-with-bufferedreader-interop</link>
<description>&lt;p&gt;Hello --&lt;/p&gt;
&lt;p&gt;I'm learning Clojure and its Java interop stuff. I am trying to emulate this function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; public String readAllCharsOneByOne(BufferedReader bufferedReader) throws IOException {
    StringBuilder content = new StringBuilder();
       
    int value;
    while ((value = bufferedReader.read()) != -1) {
        content.append((char) value);
    }
       
    return content.toString();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So far, I've been able to reason that the parts I need are:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def myfile &quot;/path/to/svenska_sample.txt&quot;)
(import java.io.BufferedReader)
(import java.io.FileReader)
(import java.lang.StringBuilder)
(import java.lang.Character)
 
(def a-FileReader (FileReader. myfile))
(def bufferedReader (BufferedReader. a-FileReader))
(def content (StringBuilder.))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which works&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDe&quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen&quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen &quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen t&quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen ty&quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen typ&quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen typi&quot;]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The file is a small text file UTF-8 encoded in Linux with the following content:&lt;/p&gt;
&lt;p&gt;❯ cat svenska_sample.txt&lt;/p&gt;
&lt;p&gt;Den typiska impulsiva olycksfågeln är en ung man som kraschar flera bilar, och ofta skryter lite med det, i varje fall när han är tillsammans med sina vänner._. För dem har otur i det närmaste blivit en livsstil, och de råkar konstant ut för olyckor, stora som små. Olycksfåglar kallar vi dem. Hur många det finns kan ingen med säkerhet säga, för det finns inga konkreta definitioner på denna grupp, och heller ingen given avgränsning av den. Att de finns, råder det emellertid ingen tvekan om, varken på sjukhusens akutmottagningar eller i försäkringsbranschen&lt;/p&gt;
&lt;p&gt;I wrote a function, with my brand new Clojure Java interop chops, that looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;;; COMPILES  - BUT CAN'T GET AROUND THE 0XFFFFFFF BUG
(defn pt%% [file]
   (let [afr (FileReader. file); instances of FileReader, BufferedReader, StringBuffer
         bfr (BufferedReader. afr)
         ct (StringBuilder.)
         val (.read bfr)
         this-list (list afr bfr ct)]
         ; (apply println this-list)
         (loop []
               (when (not (= val -1))
                 (.append ct (Character/toChars (.read bfr))))
               (recur))
                ; when finished...
         (.toString ct)))
     
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but it borks with the following error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (pt%% myfile)
Execution error (IllegalArgumentException) at java.lang.Character/toChars (Character.java:8572).
Not a valid Unicode code point: 0xFFFFFFFF
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What in the world could be causing this (NOTE: I am not a Java programmer)?&lt;br&gt;
Here is the hex dump of the file text file:&lt;/p&gt;
&lt;p&gt;❯ cat svenska_sample.hexdump&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;00000000: 0a44 656e 2074 7970 6973 6b61 2069 6d70  .Den typiska imp
00000010: 756c 7369 7661 206f 6c79 636b 7366 c3a5  ulsiva olycksf..
00000020: 6765 6c6e 20c3 a472 2065 6e20 756e 6720  geln ..r en ung
00000030: 6d61 6e20 736f 6d20 6b72 6173 6368 6172  man som kraschar
00000040: 2066 6c65 7261 2062 696c 6172 2c20 6f63   flera bilar, oc
00000050: 6820 6f66 7461 2073 6b72 7974 6572 206c  h ofta skryter l
00000060: 6974 6520 6d65 6420 6465 742c 2069 2076  ite med det, i v
00000070: 6172 6a65 2066 616c 6c20 6ec3 a472 2068  arje fall n..r h
00000080: 616e 20c3 a472 2074 696c 6c73 616d 6d61  an ..r tillsamma
00000090: 6e73 206d 6564 2073 696e 6120 76c3 a46e  ns med sina v..n
000000a0: 6e65 722e 5f2e 2046 c3b6 7220 6465 6d20  ner._. F..r dem
000000b0: 6861 7220 6f74 7572 2069 2064 6574 206e  har otur i det n
000000c0: c3a4 726d 6173 7465 2062 6c69 7669 7420  ..rmaste blivit
000000d0: 656e 206c 6976 7373 7469 6c2c 206f 6368  en livsstil, och
000000e0: 2064 6520 72c3 a56b 6172 206b 6f6e 7374   de r..kar konst
000000f0: 616e 7420 7574 2066 c3b6 7220 6f6c 7963  ant ut f..r olyc
00000100: 6b6f 722c 2073 746f 7261 2073 6f6d 2073  kor, stora som s
00000110: 6dc3 a52e 204f 6c79 636b 7366 c3a5 676c  m... Olycksf..gl
00000120: 6172 206b 616c 6c61 7220 7669 2064 656d  ar kallar vi dem
00000130: 2e20 4875 7220 6dc3 a56e 6761 2064 6574  . Hur m..nga det
00000140: 2066 696e 6e73 206b 616e 2069 6e67 656e   finns kan ingen
00000150: 206d 6564 2073 c3a4 6b65 7268 6574 2073   med s..kerhet s
00000160: c3a4 6761 2c20 66c3 b672 2064 6574 2066  ..ga, f..r det f
00000170: 696e 6e73 2069 6e67 6120 6b6f 6e6b 7265  inns inga konkre
00000180: 7461 2064 6566 696e 6974 696f 6e65 7220  ta definitioner
00000190: 70c3 a520 6465 6e6e 6120 6772 7570 702c  p.. denna grupp,
000001a0: 206f 6368 2068 656c 6c65 7220 696e 6765   och heller inge
000001b0: 6e20 6769 7665 6e20 6176 6772 c3a4 6e73  n given avgr..ns
000001c0: 6e69 6e67 2061 7620 6465 6e2e 2041 7474  ning av den. Att
000001d0: 2064 6520 6669 6e6e 732c 2072 c3a5 6465   de finns, r..de
000001e0: 7220 6465 7420 656d 656c 6c65 7274 6964  r det emellertid
000001f0: 2069 6e67 656e 2074 7665 6b61 6e20 6f6d   ingen tvekan om
00000200: 2c20 7661 726b 656e 2070 c3a5 2073 6a75  , varken p.. sju
00000210: 6b68 7573 656e 7320 616b 7574 6d6f 7474  khusens akutmott
00000220: 6167 6e69 6e67 6172 2065 6c6c 6572 2069  agningar eller i
00000230: 2066 c3b6 7273 c3a4 6b72 696e 6773 6272   f..rs..kringsbr
00000240: 616e 7363 6865 6e0a                      anschen.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I then changed the code (see below), because of some suggestions that the problem might be my use of recur.&lt;/p&gt;
&lt;p&gt;And now it complains that a previous form that was working '(.append etc..') doesn't and the same error remains. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (pt5 myfile)

Execution error (IllegalArgumentException) at java.lang.Character/toChars (Character.java:8572).
Not a valid Unicode code point: 0xFFFFFFFF

(defn pt5 [file]

   (let [afr (FileReader. file); instances of FileReader, BufferedReader, StringBuffer
         bfr (BufferedReader. afr)
         ct (StringBuilder.)
         this-list (list afr bfr ct)]
         ; (apply println this-list)
         (loop [val (.read bfr)]
               (when (not (= val -1))
                 (.append ct (Character/toChars (.read bfr))))
               (recur val))
                ; when finished...
                (.toString ct)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Harder then it seemed at first sight...&lt;br&gt;
Any help is greatly appreciated.`&lt;br&gt;
-- Hank&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11415/pesky-loop-resulting-0xffffffff-with-bufferedreader-interop</guid>
<pubDate>Sun, 26 Dec 2021 13:20:55 +0000</pubDate>
</item>
<item>
<title>Could not locate clojure/spec__init.class, clojure/spec.clj or clojure/spec.cljc on classpath</title>
<link>https://ask.clojure.org/index.php/11400/could-locate-clojure-specinit-clojure-clojure-classpath</link>
<description>&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;i want to use this &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/setzer22/alignment_model_text&quot;&gt;Git Repo&lt;/a&gt;. Installation worked for me, but when i run &lt;code&gt;mvn -X exec:java&lt;/code&gt; i get the following error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    java.lang.ExceptionInInitializerError
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:293)
    at java.lang.Thread.run (Thread.java:748)
[...]

    Caused by: java.io.FileNotFoundException: Could not locate clojure/spec__init.class, clojure/spec.clj or clojure/spec.cljc on classpath.
    at clojure.lang.RT.load (RT.java:466)
    at clojure.lang.RT.load (RT.java:428)
    at clojure.core$load$fn__6824.invoke (core.clj:6126)
    at clojure.core$load.invokeStatic (core.clj:6125)
    at clojure.core$load.doInvoke (core.clj:6109)
    at clojure.lang.RestFn.invoke (RestFn.java:408)
    at clojure.core$load_one.invokeStatic (core.clj:5908)
    at clojure.core$load_one.invoke (core.clj:5903)
    at clojure.core$load_lib$fn__6765.invoke (core.clj:5948)
    at clojure.core$load_lib.invokeStatic (core.clj:5947)
    at clojure.core$load_lib.doInvoke (core.clj:5928)
    at clojure.lang.RestFn.applyTo (RestFn.java:142)
    at clojure.core$apply.invokeStatic (core.clj:667)
    at clojure.core$load_libs.invokeStatic (core.clj:5985)
    at clojure.core$load_libs.doInvoke (core.clj:5969)
    at clojure.lang.RestFn.applyTo (RestFn.java:137)
    at clojure.core$apply.invokeStatic (core.clj:667)
    at clojure.core$require.invokeStatic (core.clj:6007)
    at clojure.core$require.doInvoke (core.clj:6007)
    at clojure.lang.RestFn.invoke (RestFn.java:408)
    at edu.upc.nlp4bpm_commons.config$eval211$loading__6706__auto____212.invoke (config.clj:1)
    at edu.upc.nlp4bpm_commons.config$eval211.invokeStatic (config.clj:1)
    at edu.upc.nlp4bpm_commons.config$eval211.invoke (config.clj:1)
    at clojure.lang.Compiler.eval (Compiler.java:7176)
    at clojure.lang.Compiler.eval (Compiler.java:7165)
    at clojure.lang.Compiler.load (Compiler.java:7635)
    at clojure.lang.RT.loadResourceScript (RT.java:381)
    at clojure.lang.RT.loadResourceScript (RT.java:372)
    at clojure.lang.RT.load (RT.java:463)
    at clojure.lang.RT.load (RT.java:428)
    at clojure.core$load$fn__6824.invoke (core.clj:6126)
    at clojure.core$load.invokeStatic (core.clj:6125)
    at clojure.core$load.doInvoke (core.clj:6109)
    at clojure.lang.RestFn.invoke (RestFn.java:408)
    at clojure.core$load_one.invokeStatic (core.clj:5908)
    at clojure.core$load_one.invoke (core.clj:5903)
    at clojure.core$load_lib$fn__6765.invoke (core.clj:5948)
    at clojure.core$load_lib.invokeStatic (core.clj:5947)
    at clojure.core$load_lib.doInvoke (core.clj:5928)
    at clojure.lang.RestFn.applyTo (RestFn.java:142)
    at clojure.core$apply.invokeStatic (core.clj:667)
    at clojure.core$load_libs.invokeStatic (core.clj:5985)
    at clojure.core$load_libs.doInvoke (core.clj:5969)
    at clojure.lang.RestFn.applyTo (RestFn.java:137)
    at clojure.core$apply.invokeStatic (core.clj:667)
    at clojure.core$require.invokeStatic (core.clj:6007)
    at clojure.core$require.doInvoke (core.clj:6007)
    at clojure.lang.RestFn.invoke (RestFn.java:482)
    at du.upc.nlp4bpm_commons.freeling_api$eval150$loading__6706__auto____151.invoke (freeling_api.clj:1)
    at edu.upc.nlp4bpm_commons.freeling_api$eval150.invokeStatic (freeling_api.clj:1)
    at edu.upc.nlp4bpm_commons.freeling_api$eval150.invoke (freeling_api.clj:1)
    at clojure.lang.Compiler.eval (Compiler.java:7176)
    at clojure.lang.Compiler.eval (Compiler.java:7165)
    at clojure.lang.Compiler.load (Compiler.java:7635)
    at clojure.lang.RT.loadResourceScript (RT.java:381)
    at clojure.lang.RT.loadResourceScript (RT.java:372)
    at clojure.lang.RT.load (RT.java:463)
    at clojure.lang.RT.load (RT.java:428)
    at clojure.core$load$fn__6824.invoke (core.clj:6126)
    at clojure.core$load.invokeStatic (core.clj:6125)
    at clojure.core$load.doInvoke (core.clj:6109)
    at clojure.lang.RestFn.invoke (RestFn.java:408)
    at clojure.core$load_one.invokeStatic (core.clj:5908)
    at clojure.core$load_one.invoke (core.clj:5903)
    at clojure.core$load_lib$fn__6765.invoke (core.clj:5948)
    at clojure.core$load_lib.invokeStatic (core.clj:5947)
    at clojure.core$load_lib.doInvoke (core.clj:5928)
    at clojure.lang.RestFn.applyTo (RestFn.java:142)
    at clojure.core$apply.invokeStatic (core.clj:667)
    at clojure.core$load_libs.invokeStatic (core.clj:5985)
    at clojure.core$load_libs.doInvoke (core.clj:5969)
    at clojure.lang.RestFn.applyTo (RestFn.java:137)
    at clojure.core$apply.invokeStatic (core.clj:667)
    at clojure.core$require.invokeStatic (core.clj:6007)
    at clojure.core$require.doInvoke (core.clj:6007)
    at clojure.lang.RestFn.invoke (RestFn.java:408)
    at clojure.lang.Var.invoke (Var.java:384)
    at edu.upc.modelvsdocument.StandaloneMain.require (StandaloneMain.java:23)
    at edu.upc.modelvsdocument.StandaloneMain.&amp;lt;clinit&amp;gt; (StandaloneMain.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:293)
    at java.lang.Thread.run (Thread.java:748)
   
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The config.clj File looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    (ns edu.upc.modelvsdocument.config
  (:use [edu.upc.modelvsdocument.utils]
        [com.rpl.specter]
        [edu.upc.modelvsdocument.schemas]
        [edu.upc.modelvsdocument.utils]
        [clojure.pprint])
  (:require [clojure.java.io :as io]
            [clojure.spec :as spec]
            [clojure.spec.test :as stest]
            [edu.upc.modelvsdocument.schemas :as t :refer :all]
            [clojure.walk :as walk]))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I read a lot of stuff about clojure/spec/alpha__init.class, but i don't know if this relates to my problem. Please provide a desperate clojure neewbie some wisdom:)&lt;/p&gt;
&lt;p&gt;mvn &amp;amp; clojure version:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 1.8.0_292, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en, platform encoding: UTF-8
OS name: &quot;linux&quot;, version: &quot;5.10.16.3-microsoft-standard-wsl2&quot;, arch: &quot;amd64&quot;, family: &quot;unix&quot;

Clojure CLI version 1.10.3.1040
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11400/could-locate-clojure-specinit-clojure-clojure-classpath</guid>
<pubDate>Tue, 14 Dec 2021 16:59:14 +0000</pubDate>
</item>
<item>
<title>Recommended workflow to work on Clojure sources</title>
<link>https://ask.clojure.org/index.php/11191/recommended-workflow-to-work-on-clojure-sources</link>
<description>&lt;p&gt;Hello all,&lt;/p&gt;
&lt;p&gt;Is there a recommended way to work on the Clojure sources, both the java and the clj files?&lt;/p&gt;
&lt;p&gt;For example, I'd like to be able to put a breakpoint in my ide (Intellij Idea) to see how certain parts of the compiler or the core libraries work.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11191/recommended-workflow-to-work-on-clojure-sources</guid>
<pubDate>Tue, 26 Oct 2021 02:14:01 +0000</pubDate>
</item>
<item>
<title>Do I have to switch to Java 8 or 11 from 16.0.1?</title>
<link>https://ask.clojure.org/index.php/11052/do-i-have-to-switch-to-java-8-or-11-from-16-0-1</link>
<description>&lt;p&gt;Hi &lt;br&gt;
I saw a comment on Clojure.org stating that it only runs on java 8 or 11. I have 16.0.1 installed. What  is the best solution for me? I really do not want to download Java 11 and in a way downgrade. I am also concerned with my older projects all configured to use newer versions. &lt;/p&gt;
</description>
<category>Tools</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11052/do-i-have-to-switch-to-java-8-or-11-from-16-0-1</guid>
<pubDate>Tue, 14 Sep 2021 20:22:11 +0000</pubDate>
</item>
<item>
<title>The clojure `rand-int` method seems to be 4 times slower than its java counterpart `java.util.Random.nextInt()`</title>
<link>https://ask.clojure.org/index.php/10669/clojure-method-seems-times-slower-counterpart-random-nextint</link>
<description>&lt;p&gt;Check the below &lt;a rel=&quot;nofollow&quot; href=&quot;https://gist.github.com/a30660391c68255e65ff60970e706c22&quot;&gt;gist&lt;/a&gt; to see detailed results.&lt;/p&gt;
&lt;p&gt;Note that using interop is ok for me, &lt;br&gt;
I am in an operations research use case where time consumption of random value is important.&lt;/p&gt;
&lt;p&gt;But I wonder why clojure should not propose a better version of rand-int.&lt;/p&gt;
&lt;p&gt;I suspect (but I will check if needed) that the &lt;code&gt;nextInt&lt;/code&gt; version may be more uniform (statistically closer from the theory).&lt;/p&gt;
&lt;p&gt;PS: Duplicate from a question in slack, channel clojure.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10669/clojure-method-seems-times-slower-counterpart-random-nextint</guid>
<pubDate>Fri, 04 Jun 2021 09:12:42 +0000</pubDate>
</item>
<item>
<title>&quot;file does not contain class clojure.asm.Symbol&quot; warning when clojure-sources is in the classpath</title>
<link>https://ask.clojure.org/index.php/9982/contain-clojure-symbol-warning-clojure-sources-classpath</link>
<description>&lt;p&gt;I have &lt;code&gt;.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1-sources.jar&lt;/code&gt; in the classpath, which I do in order to enable (custom) IDE tooling.&lt;/p&gt;
&lt;p&gt;Doing so causes the following warning when launching &lt;code&gt;lein repl&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/Users/vemv/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1-sources.jar(clojure/asm/SymbolTable.java):49: error: cannot access Symbol
  private static class Entry extends Symbol {
                                     ^
  bad source file: /Users/vemv/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1-sources.jar(clojure/asm/Symbol.java)
    file does not contain class clojure.asm.Symbol
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In contrast, no other &lt;code&gt;&quot;sources&quot;&lt;/code&gt; .jar causes any warning. I can have up to hundreds of such &lt;code&gt;&quot;sources&quot; &lt;/code&gt; jars.&lt;/p&gt;
&lt;p&gt;Perhaps this file has some minor/vestigial issue, such as something related to privacy modifiers, package structure, etc?&lt;/p&gt;
&lt;p&gt;If it was harmless to do, this would seem nice to fix particularly when a single class in a single lib is the only instance of this issue (vs. hundreds of other .jars)&lt;/p&gt;
&lt;p&gt;As a reference, I also found another person encountering the same issue: &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojurians-log.clojureverse.org/clojure/2019-06-23/1561323947.040200&quot;&gt;https://clojurians-log.clojureverse.org/clojure/2019-06-23/1561323947.040200&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;By the way, while this might look as a &lt;code&gt;javac&lt;/code&gt; byproduct, I'm almost positively sure &lt;code&gt;lein repl&lt;/code&gt; is not implicitly invoking &lt;code&gt;javac&lt;/code&gt;. Documentation states so: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/technomancy/leiningen/blob/0f456829a8b21335aa86390f3ee3d0dcc68410d6/doc/MIXED_PROJECTS.md#java-source-compilation&quot;&gt;https://github.com/technomancy/leiningen/blob/0f456829a8b21335aa86390f3ee3d0dcc68410d6/doc/MIXED_PROJECTS.md#java-source-compilation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I'm using JDK8.&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9982/contain-clojure-symbol-warning-clojure-sources-classpath</guid>
<pubDate>Mon, 28 Dec 2020 16:40:24 +0000</pubDate>
</item>
<item>
<title>Why does bit-shift-left rotate bits instead of discarding bits?</title>
<link>https://ask.clojure.org/index.php/9518/why-does-bit-shift-left-rotate-bits-instead-discarding-bits</link>
<description>&lt;p&gt;&lt;code&gt;(bit-shift-left 0xfffffff0 4)&lt;/code&gt; returns &lt;code&gt;0xffffff0f&lt;/code&gt;, while I expect it to be &lt;code&gt;0xffffff00&lt;/code&gt;. Similarly, &lt;code&gt;(bit-shift-left 0xfffffff0 8)&lt;/code&gt; returns &lt;code&gt;0xfffff0ff&lt;/code&gt;, etc.&lt;/p&gt;
&lt;p&gt; I checked the implementation, and &lt;code&gt;bit-shift-left&lt;/code&gt; casts all its arguments to &lt;code&gt;Long&lt;/code&gt;, then invokes Java's &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; operator, which should discard higher bits instead of rotate them.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9518/why-does-bit-shift-left-rotate-bits-instead-discarding-bits</guid>
<pubDate>Mon, 03 Aug 2020 05:35:41 +0000</pubDate>
</item>
<item>
<title>How to call reloadable Clojure from Java?</title>
<link>https://ask.clojure.org/index.php/9431/how-to-call-reloadable-clojure-from-java</link>
<description>&lt;p&gt;Given a Java application already having Clojure's &lt;code&gt;.jar&lt;/code&gt; on classpath. And a file directory &lt;code&gt;/home/me/clojure-extensions/&lt;/code&gt; which contains &lt;code&gt;.clj&lt;/code&gt; files, structured like an usual clojure source directory, which is not on the applications classpath and can not be added to the classpath, because it is configurable and not part of the application.&lt;/p&gt;
&lt;p&gt;How to call the function &lt;code&gt;myns.core/myfn&lt;/code&gt; from Java Code? So that &lt;code&gt;/home/me/clojure/extensions/myns/core.clj&lt;/code&gt; and all dependent files are loaded? So that these files are reloaded if changed when the Java call is invoked again?&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9431/how-to-call-reloadable-clojure-from-java</guid>
<pubDate>Thu, 09 Jul 2020 12:20:51 +0000</pubDate>
</item>
<item>
<title>How to call java method with interface as parameters?</title>
<link>https://ask.clojure.org/index.php/9296/how-to-call-java-method-with-interface-as-parameters</link>
<description>&lt;p&gt;Here's my sample code.&lt;br&gt;
Thanks.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Java code
interface IFace {
  String message();
}
class A implements IFace {
  @Override message () { return &quot;Hello A!&quot;};
}
class B implements IFace {
  @Override message () { return &quot;Hello B!&quot;};
}
class PrintHello {
  static void print (IFace msg) {
    if (msg instanceof A) { ... } else { ... }
  }
}

; Clojure code

(def a (A.))
(. PrintHello (print a))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9296/how-to-call-java-method-with-interface-as-parameters</guid>
<pubDate>Fri, 08 May 2020 04:37:31 +0000</pubDate>
</item>
</channel>
</rss>