Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1228

Scoping/variable resolving problem when static final field with same name declared in class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.0-JSR-5
    • class generator
    • None

    Description

      The code below gets a ClassCastException:java.lang.Integer in the first line of goAhead() method. The reason is that the 'res' has already been reserved for static field of the class, and 1 is casted to this field instead of the variable 'res'.
      class StaticTest {
      private static final Date res = new Date()

      def goAhead ()

      { def res = 1}

      public static void main (args)

      { new StaticTest().goAhead() }

      }

      For goAhead the bytecode of following java code is created:
      public Object goAhead() {
      Date date = (Date)ScriptBytecodeAdapter.asType(new Integer(1), java.util.Date.class);
      date;
      res = (Date) date;
      return res;
      }

      instead of:
      public Object goAhead() {
      Integer integer = new Integer(1);
      return integer;
      }

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            lipinski Pawel Lipinski
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: