Skip to content
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

"bad constant pool tag 17" when using a library compiled using Java 21 #12936

Closed
SethTisue opened this issue Jan 25, 2024 · 5 comments
Closed
Assignees
Milestone

Comments

@SethTisue
Copy link
Member

SethTisue commented Jan 25, 2024

this is the Scala 2 equivalent of scala/scala3#19527, reported against Scala 3 by @adamw yesterday

the original report has some information about what kind of bytecode is involved — it’s switch on certain types, e.g. Java enums

Scala 2 reproducer:

//> using scala 2.nightly
//> using dep com.softwaremill.jox:core:0.0.5

import com.softwaremill.jox.Channel

object Test {
  def main(argv: Array[String]): Unit =
    new Channel(0)
}

result:

Error: 
  bad constant pool tag 17 at byte 10172
     while compiling: /Users/tisue/tmp/dotty-19527/S.scala
        during phase: globalPhase=typer, enteringPhase=namer
    ...
	at scala.tools.nsc.symtab.classfile.ClassfileParser$ConstantPool.errorBadTag(ClassfileParser.scala:411)
	at scala.tools.nsc.symtab.classfile.ClassfileParser$ConstantPool.<init>(ClassfileParser.scala:230)
	at scala.tools.nsc.symtab.classfile.ClassfileParser.$anonfun$parse$2(ClassfileParser.scala:173)
	at scala.tools.nsc.symtab.classfile.ClassfileParser.$anonfun$parse$1(ClassfileParser.scala:159)
	at scala.tools.nsc.symtab.classfile.ClassfileParser.parse(ClassfileParser.scala:142)
	at scala.tools.nsc.symtab.SymbolLoaders$ClassfileLoader.doComplete(SymbolLoaders.scala:342)
	at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.$anonfun$complete$2(SymbolLoaders.scala:249)
	...
@lrytz
Copy link
Member

lrytz commented Jan 25, 2024

Reproducer

public class A {
  int f(Object s) {
    switch(s) {
      case Res.R -> {
        return 1;
      }
      default -> {
        return 3;
      }
    }
  }
  static enum Res {
    R
  }
}

@lrytz
Copy link
Member

lrytz commented Jan 25, 2024

➜ sandbox javap -v A.class
...
  #30 = Dynamic            #1:#31         // #1:invoke:Ljava/lang/Enum$EnumDesc;
...

Dynamic?

https://github.com/scala/scala/blob/v2.13.12/src/reflect/scala/reflect/internal/ClassfileConstants.scala#L83-L84

Where's 17?

Oh it was added in Java 11. https://docs.oracle.com/javase/specs/jvms/se21/html/jvms-4.html#jvms-4.4-210.

Why did nobody tell us? 🙃

@He-Pin
Copy link
Contributor

He-Pin commented Jan 25, 2024

Seems like Scala missed the tag 17 and has a tag 2.
Added in
https://openjdk.org/jeps/309

@lrytz
Copy link
Member

lrytz commented Jan 25, 2024

That's entertaining; trivia on https://stackoverflow.com/a/63314177

@som-snytt
Copy link

@SethTisue SethTisue changed the title "bad constant pool tag" when using a library compiled using Java 21 "bad constant pool tag 17" when using a library compiled using Java 21 Jan 25, 2024
@lrytz lrytz closed this as completed Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants