Skip to content

Class annotated with @throws produces invalid Bytecode (invalid class type signature in classfile) #12324

@jbracker

Description

@jbracker

reproduction steps

Using Scala 2.13.3 and Java 11.

Compile the following class into a class-file:

@throws(classOf[IllegalArgumentException])
class ScalaClass[T](someList: List[T]) {
   throw new IllegalArgumentException("Boom!")
}

problem

The generated classfile/bytecode contains a type signature for ScalaClass. This type signature contains a ThrowsSignature although these are only permitted as part of MethodSignature:
https://docs.oracle.com/javase/specs/jvms/se15/html/jvms-4.html#jvms-4.7.9.1

This issue was discovered while working with ClassGraph to do bytecode analysis:
classgraph/classgraph#495 (comment)
You can read up on the details from the linked comment onwards.

At first we thought the type signature parser of ClassGraph was missing something, but we're confident that the bytecode generated by Scala is invalid. Later on in that issue you can see that javac even rejects the classfile generated by Scala due to it being invalid:
classgraph/classgraph#495 (comment)

Attached is a minimal Scala/Maven project that produces the said invalid classfile for the class mentioned above:
ClassGraphMinimalExample.zip

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions