groovy
  1. groovy
  2. GROOVY-5260

Groovyc stub generation doesn't handle all primitive types properly

    Details

    • Number of attachments :
      0

      Description

      The problem manifests when a long value is effectively being changed to an 'int' and results in an exception during compilation.

      Example class:

      class AnObject {
          public static final long serialVersionUID = -5239748510188117876L
      }
      

      Using groovy 1.8.5, the generated stub (during joint compilation using the 'Groovyc' ant taskdef) looks like (sans imports):

      public class AnObject implements
          groovy.lang.GroovyObject {
      public static final long serialVersionUID = -5239748510188117876;
      }
      

      The problem is that this yields a compilation exception 'integer number too large'.

      If you exclude the 'public' keyword on the member definition and re-compile, the stub instead looks like:

      public class AnObject implements
          groovy.lang.GroovyObject {
      public static final  long getSerialVersionUID() { return (long)0;}
      }
      

      This can then compile successfully.

        Activity

        Hide
        blackdrag blackdrag added a comment -

        So the difference between the two is, that the first one is a field, the second one a property (no public modifier given) and that we give in the value for the field directly, because Java wants that sometimes. It is imho not wrong to do so, but what is missing is the L at the end of the number to identify it as a long, since Java does not do autopromotion for literal numbers.

        Show
        blackdrag blackdrag added a comment - So the difference between the two is, that the first one is a field, the second one a property (no public modifier given) and that we give in the value for the field directly, because Java wants that sometimes. It is imho not wrong to do so, but what is missing is the L at the end of the number to identify it as a long, since Java does not do autopromotion for literal numbers.

          People

          • Assignee:
            CÚdric Champeau
            Reporter:
            Jay Ashworth
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: