FatalError: bad constant pool index

Hello, start getting strange compilation error once of of dependencies were updated: "com.jcraft" % "jsch" % "0.1.55" to "com.github.mwiede" % "jsch" % "0.2.16"

bad constant pool index: 0 at 50924
while compiling: <some_our_class>
during phase: globalPhase=jvm, enteringPhase=namer
library version: version 2.12.6
compiler version: version 2.12.6
last tree to typer: Ident (_root_)
tree position: line 8 of <some_our_class>
tree tpe: <root>
symbol: final package _root_
symbol definition: final package _root_ (a RootPackage)
symbol package: <none>
symbol owners: package _root_
call site: package sftp in package file in package file

== Source file context for tree position ==

5 import com.jcraft.jsch.Session;
6 import com.jcraft.jsch.SftpATTRS;
7 import com.jcraft.jsch.SftpException;
8 import com.jcraft.jsch.ChannelSftp;

SBT version 0.13.17
scala version 2.12.6
Java 8

The main problem I don’t understand what does it mean. Maybe someone could help to understand the root cause of this issue?

This may be due to the third party library being compiled with a later version of Java > 8, I’ve seen something like this in similar circumstances.

Try bumping up your version of Java, perhaps - 8 is getting a bit old these days.

Unfortunately I couln’d just upgrade java/scala/sbt version, because it is huge project, so it could leads to some issues.

Well, it could. But do you know for sure? Why not give it try without committing your work?

That’s what tests and CI are for, eh! :grinning:

I appreciate that there may be the usual political dynamic involved if you’re working in some corporate environment; I’m a veteran of investment banking, been there. You may end up simply building the third party library yourself as a private build, maybe as a subproject in SBT if you want to stay on Java 8 with shading to hide its package … or cut and paste the code directly into your own project … or fight the battle of persuasion … or try a different third party library … or (please don’t do this), write your own replacement.

Pick your battles, and good luck!

The problem with sbt/scala/java upgrade is other dependencies and closed internal repo and policies (adding new deps to internal repo it is a pain), I tried to update java => it leads to updating some other deps. The same for scala/sbt.
Maybe you could point me out how to get more info about this compiler error? Because of know it says me absolutely nothing.

Issues · scala/bug · GitHub is your bible (maybe more like some heaps of dusty old scrolls in a cave) for problems like this (Scala 2 compiler crashes).

The error message means that there is something in the bytecode of the library you are using that the Scala compiler’s classfile parser doesn’t understand.

It looks like it could be On JDK 21, `ClassfileParser` doesn't handle `MethodParameter` attributes without names · Issue #12783 · scala/bug · GitHub specifically.

Upgrading from Scala 2.12.6 to 2.12.19 is definitely the first thing I would suggest trying. If that’s politically difficult at your job, well, I don’t know what else to suggest — except don’t upgrade the dependency in question.


Thank you for your advises!

Update of scala to 2.12.19 helped, thank you! Just curious is the a way to get from compiler what is exactly confused him?

Great, glad that fixed it. I wish you luck getting permission to push the upgrade into production.

Just curious is the a way to get from compiler what is exactly confused him?

Not really. You would have to study the source code for the compiler and study the bytecode in question.

We do put some effort into improving error messages that commonly arise during ordinary coding. But it’s not really feasible for a completely unexpected edge case like this to result in an actual explanation and not just a brief message and a stack trace.

Got it, Thank you for explanation!