groovy
  1. groovy
  2. GROOVY-5248

call site caching missing null check

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.8.6, 2.0-beta-3, 1.7.11
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Luke brought GRADLE-2045 to my attention and I was able to reproduce the problem using this program:

      class Cat {
        public static findAll(Integer x, Closure cl) {1}   
      }
      
       def foo(x) {
           x.findAll {}
       }
       
       use (Cat) {
           println foo(1)
           println foo(null)
       }
      

      It should actually not matter what method or base class the category uses, important is more that a PojoMetaClassSite will be produced. The code here does this because the receiver in foo is the Pojo integer and since categories are active, the normal way of getting a MetaMethod and using that will not be applied. Instead the fallback action with the long path through the MetaClassImpl will be chosen. PojoMetaClassSite has, as all of those, a check for invalidation which includes meta class changes and a check for the receiver being still of the same class. But the class check requires a non-null receiver, which is not the case anymore at the time that foo is called the second time.

        Activity

        Hide
        blackdrag blackdrag added a comment -

        Using

        --- a/src/main/org/codehaus/groovy/runtime/callsite/PojoMetaClassSite.java
        +++ b/src/main/org/codehaus/groovy/runtime/callsite/PojoMetaClassSite.java
        @@ -51,7 +51,8 @@ public class PojoMetaClassSite extends MetaClassSite{
             }
         
             protected final boolean checkCall(Object receiver) {
        -        return receiver.getClass() == metaClass.getTheClass()
        -            && version == classInfo.getVersion(); // metaClass is still valid
        +        return  receiver!=null &&
        +                receiver.getClass() == metaClass.getTheClass() &&
        +                version == classInfo.getVersion(); // metaClass is still valid
             }
         }
        

        seems to fix the issue

        Show
        blackdrag blackdrag added a comment - Using --- a/src/main/org/codehaus/groovy/runtime/callsite/PojoMetaClassSite.java +++ b/src/main/org/codehaus/groovy/runtime/callsite/PojoMetaClassSite.java @@ -51,7 +51,8 @@ public class PojoMetaClassSite extends MetaClassSite{ } protected final boolean checkCall( Object receiver) { - return receiver.getClass() == metaClass.getTheClass() - && version == classInfo.getVersion(); // metaClass is still valid + return receiver!= null && + receiver.getClass() == metaClass.getTheClass() && + version == classInfo.getVersion(); // metaClass is still valid } } seems to fix the issue
        Hide
        blackdrag blackdrag added a comment -

        fix applied

        Show
        blackdrag blackdrag added a comment - fix applied
        blackdrag blackdrag made changes -
        Field Original Value New Value
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Jochen Theodorou [ blackdrag ]
        Fix Version/s 2.0-beta-3 [ 18244 ]
        Fix Version/s 1.8.6 [ 18245 ]
        Fix Version/s 1.7.11 [ 17244 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            blackdrag blackdrag
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: