metaborg / mb-rep

Apache License 2.0
2 stars 4 forks source link

Fix obscure equality bug after deserialization #24

Closed Gohla closed 3 years ago

Gohla commented 3 years ago

See comment in the method. I tested this locally and the build succeeds (and it fixes the term equality bug that I encountered)

Apanatshka commented 3 years ago

That's definitely an obscure bug. Also, isn't Java great? A transient field with a default value doesn't get its default value when deserializing, makes total sense...

Gohla commented 3 years ago

Well, defaults values are not part of the JVM bytecode, they get translated to code in a constructor, which doesn't get called when deserialized 😁

protected <init>(Lorg/spoofax/interpreter/terms/IStrategoList;)V
 L0
  LINENUMBER 31 L0
  ALOAD 0
  INVOKESPECIAL org/spoofax/terms/AbstractSimpleTerm.<init> ()V
 L1
  LINENUMBER 27 L1
  ALOAD 0
  ICONST_M1
  PUTFIELD org/spoofax/terms/StrategoTerm.hashCode : I
Apanatshka commented 3 years ago

Well, defaults values are not part of the JVM bytecode, they get translated to code in a constructor, which doesn't get called when deserialized 😁

Sounds like a leaky abstraction to me then 😉