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

@CompileStatic + @Canonical + integer property == null pointer in hashcode

    Details

      Description

      Using the @CompileStatic annotation with @Canonical, and having an integer property creates a null pointer opportunity in the generated hashCode method -

      it decompiles to this:

      public int hashCode()
      {
      int _result = HashCodeHelper.initHash();
      int _tmp = _result;
      if(!DefaultGroovyMethods.is(getName(), this))

      { int i = HashCodeHelper.updateHash(_result, getName()); _result = i; int _tmp1 = i; }

      if(!DefaultGroovyMethods.is(getSomeNum(), this))

      { int j = HashCodeHelper.updateHash(_result, getSomeNum().intValue()); _result = j; int _tmp2 = j; }

      return _result;
      }

      Note the intValue being called without checking to see if the getter returns null.

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              jon.barksdale Jon Barksdale
            • Votes:
              6 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: