Scala Programming Language
  1. Scala Programming Language
  2. SI-4804

Static forwarders are missing after adding @SerialVersionUID

    Details

      Description

      In the following code, adding @SerialVersionUID to the class results in the static forwarders missing from the byte code.

      object WithoutUID {
       val instance = new WithoutUID
      }
      class WithoutUID extends scala.Serializable
      
      object WithUID {
       val instance = new WithUID
      }
      @SerialVersionUID(0) 
      class WithUID extends scala.Serializable

      Here is the relevant decompiled byte code:

      public class WithoutUID implements Serializable, ScalaObject {
        public static final WithoutUID instance(){
          return WithoutUID.MODULE$.instance();
        }
      }
      
      public class WithUID implements Serializable, ScalaObject {
        public static final long serialVersionUID = 0L;
      }

        Activity

        Hide
        Iulian Dragos added a comment -

        I think you're after the `ConstantValue` classfile attribute. There's some code in fjbg, but it looks incomplete:

        https://github.com/scala/scala/blob/master/src/fjbg/ch/epfl/lamp/fjbg/JConstantValueAttribute.java

        (there seems to be no way to initialize the initial value). I think it's straight forward to fix, but I don't know how much work you want to invest in fjbg, if it's EOL'ed. Maybe it's simple to disentangle the control-flow.

        Show
        Iulian Dragos added a comment - I think you're after the `ConstantValue` classfile attribute. There's some code in fjbg, but it looks incomplete: https://github.com/scala/scala/blob/master/src/fjbg/ch/epfl/lamp/fjbg/JConstantValueAttribute.java (there seems to be no way to initialize the initial value). I think it's straight forward to fix, but I don't know how much work you want to invest in fjbg, if it's EOL'ed. Maybe it's simple to disentangle the control-flow.
        Hide
        Miguel Garcia added a comment -

        The ASM way to emit a field optionally expects a value as shown below.

            public FieldVisitor visitField(
                int access,
                String name,
                String desc,
                String signature,
                Object value)
        

        GenASM does just that (well, in https://github.com/scala/scala/pull/654 ) for serialVersionUID fields, thus no instructions are required for that in clinit.

        First time I hear about fjbg's JConstantValueAttribute, thanks for the pointer.

        Show
        Miguel Garcia added a comment - The ASM way to emit a field optionally expects a value as shown below. public FieldVisitor visitField( int access, String name, String desc, String signature, Object value) GenASM does just that (well, in https://github.com/scala/scala/pull/654 ) for serialVersionUID fields, thus no instructions are required for that in clinit . First time I hear about fjbg's JConstantValueAttribute , thanks for the pointer.
        Hide
        Miguel Garcia added a comment -

        This bug has been fixed for GenASM in 5cd82554069508af769d59f9e41af36f6524b4cc , leaving open for the eventual fix for GenJVM.

        Show
        Miguel Garcia added a comment - This bug has been fixed for GenASM in 5cd82554069508af769d59f9e41af36f6524b4cc , leaving open for the eventual fix for GenJVM.
        Hide
        Seth Tisue added a comment -

        should this be marked critical for 2.10?

        Show
        Seth Tisue added a comment - should this be marked critical for 2.10?
        Hide
        Miguel Garcia added a comment -

        Given that this has been fixed in GenASM (which is now the default backend) this bug won't bite anymore.

        Show
        Miguel Garcia added a comment - Given that this has been fixed in GenASM (which is now the default backend) this bug won't bite anymore.

          People

          • Assignee:
            Miguel Garcia
            Reporter:
            Josh Cough
          • Votes:
            2 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development