I’ve got two class files that I’m trying to prove were generated from the very same Scala source.
Upon decompiling the class files into Java I got two Java files that are exactly equivalent semantically. However they have different @ScalaSignature annotations inside them. I got the following outputs upon running “javap -verbose” on the class files:
...
SourceFile: "ABC.scala"
ScalaSig: length = 0x3
05 00 00
Signature: #140 // <T:Ljava/lang/Object;>Lcom/xyz/ABC;Lscala/ScalaObject;Lscala/Product;
Lscala/Serializable;
RuntimeVisibleAnnotations:
0: #141(#142=s#143)
minor version: 0
major version: 49
flags: ACC_PUBLIC, ACC_SUPER
---
from one file, and from the other:
...
SourceFile: "ABC.scala"
ScalaSig: length = 0x3
05 00 00
Signature: #140 // <T:Ljava/lang/Object;>Lcom/xyz/ABC;Lscala/ScalaObject;Lscala/Product;
Lscala/Serializable;
RuntimeVisibleAnnotations:
0: #141(#142=s#143)
minor version: 0
major version: 49
flags: ACC_PUBLIC, ACC_SUPER
...
Is it possible for the two class files to have been obtained from the same Scala source, be annotated with the same ScalaSig, Signature, etc., and yet have different @ScalaSignature annotations?
Thanks.
It is possible for two scala source files to end up with the same byte code (except for the sig). Indeed, it’s the sig that tells you that the original source files were different. So no, it’s not possible to prove that two class files came from the same scala source.
For instance, if two classes have the same methods but with different type parameters, then you’d get the same bytecode, but different sigs.
As a trivial example, look at the following class:
These two methods have exactly the same byte code generated, but the sigs will be different: