cursive icon indicating copy to clipboard operation
cursive copied to clipboard

"Load File in REPL" gives IndexOutOfBounds

Open MrGung opened this issue 10 months ago • 4 comments

I am running Cursive 1.32.2-eap7 with IntelliJ 2023.3.5 and babashka 1.3.188.

Beginning some version ago loading a namespace stopped, resulting in

java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
	at java.base/java.util.Objects.checkIndex(Objects.java:361)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at cursive.deps.DepsSettings.getDepsCljVersion(DepsSettings.kt:77)
	at cursive.babashka.BabashkaFacetEditorTab$Companion$downloadBabashkaVersions$1$1.run(Babashka.kt:474)
	at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:434)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:132)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$5(CoreProgressManager.java:484)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:248)
	at com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:73)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:192)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:610)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:685)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:641)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:609)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:78)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:179)
	at com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:73)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$5(ProgressRunner.java:248)
	at com.intellij.openapi.progress.impl.ProgressRunner$ProgressRunnable.run(ProgressRunner.java:498)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
	at java.base/java.lang.Thread.run(Thread.java:840)

I am behind a corporate firewall that totally blocks internet traffic.

Any ideas on the cause or a workaround?

MrGung avatar Apr 15 '24 06:04 MrGung

I can't see any reason why this should happen, no. I'll try to reproduce this to see if I can figure it out.

cursive-ide avatar May 09 '24 05:05 cursive-ide

Still - using 1.13.3-2023.3 (after downgrading because of https://github.com/cursive-ide/cursive/issues/2909) with IntelliJ 2023.3.5 with bb 1.3.190 on Windows 11 behind firewall.

MrGung avatar Jun 12 '24 13:06 MrGung

Maybe it is trying to $downloadBabashkaVersions$ by trying to access the internet - which fails because of the firewall I am sitting behind?

May there be a workaround?

MrGung avatar Jun 12 '24 13:06 MrGung

Seems to be related to https://clojurians.slack.com/archives/C0744GXCJ/p1707295741451529?thread_ts=1707156070.708269&cid=C0744GXCJ

MrGung avatar Jun 12 '24 13:06 MrGung

Ok, I've fixed the cause of this in the code. If there was an error downloading the artifact and there are no versions of the relevant artifact in the .m2 cache, then IntelliJ just returns an empty list of available versions. I was not checking for this, and overwrote the list of available versions with the empty list. Now the list will be overwritten only if IntelliJ actually returns some versions.

Unfortunately, I cannot seem to get a useful error out of IntelliJ when this happens, it just fails silently, so I'm not sure how to communicate this to the user. I'll keep investigating to see if I can figure this out.

There is a further problem, however. If your firewall completely blocks internet access, then Cursive will never be able to download deps.clj. Are you able to download a version of it and get it into the Maven cache somehow? Or do you have any sort of internal repository that it could be loaded into?

Edit: One further thing to mention, if you have been bitten by this bug previously, the list of available versions may be empty in your Cursive deps settings, as indicated in that slack thread:

in ~\AppData\Roaming\JetBrains\IntelliJIdea2032.2\options\clojure-deps.settings.xml directly altered file to read:

<application>
  <component name="DepsSettings">
    <option name="availabileDepsCljVersions">
      <list>
        <option value="1.11.1.1435" />
        <option value="1.11.1.1429" />
      </list> 
    </option>
    <option name="depsCljVersionSelected" value="1.11.1.1413" />
  </component>
<application>

Probably the easiest fix to that is just to remove the file, and it should be recreated as required.

cursive-ide avatar Jul 22 '24 06:07 cursive-ide

Fix released in 1.13.4-eap8 on 2024-07-23.

cursive-ide avatar Jul 23 '24 01:07 cursive-ide

Fix released in 1.13.4 on 2024-08-06.

cursive-ide avatar Aug 06 '24 01:08 cursive-ide