groovy
  1. groovy
  2. GROOVY-5262

Problem currying null parameters

    Details

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

      Description

      When I apply the spread operator to a List containing a single null and use the result of that as an argument to .curry, an NPE is thrown with 1.8.x but not with 1.7.10.

      script1.groovy
      c = { x ->
          println "X is ${x}"
      }
      
      args = [42]
      
      c = c.curry(*args)
      
      c()
      
      script2.groovy
      c = { x, y ->
          println "X is ${x}"
          println "Y is ${y}"
      }
      
      args = [42, 2112]
      
      c = c.curry(*args)
      
      c()
      
      script3.groovy
      c = { x, y ->
          println "X is ${x}"
          println "Y is ${y}"
      }
      
      args = [null, null]
      
      c = c.curry(*args)
      
      c()
      

      (This next script is the problematic one...)

      script4.groovy
      c = { x ->
          println "X is ${x}"
      }
      
      args = [null]
      
      c = c.curry(*args)
      
      c()
      

      With Groovy 1.7.10:

      curry $ groovy -version
      Groovy Version: 1.7.10 JVM: 1.6.0_29
      curry $ 
      curry $ groovy script1
      X is 42
      curry $ 
      curry $ groovy script2
      X is 42
      Y is 2112
      curry $ 
      curry $ groovy script3
      X is null
      Y is null
      curry $ 
      curry $ groovy script4
      X is null
      curry $
      

      With Groovy 1.8.5:

      curry $ groovy -version
      Groovy Version: 1.8.5 JVM: 1.6.0_29 Vendor: Apple Inc. OS: Mac OS X
      curry $ groovy script1
      X is 42
      curry $ groovy script2
      X is 42
      Y is 2112
      curry $ groovy script3
      X is null
      Y is null
      curry $ groovy script4
      Caught: java.lang.NullPointerException
      java.lang.NullPointerException
      	at script4.run(script4.groovy:7)
      

        Activity

        Hide
        Jeff Brown added a comment -

        A slightly more simple script which demonstrates what I think is the same problem:

        script5.groovy
        c = { x ->
            println "X is ${x}"
        }
        
        
        c = c.curry(null)
        
        c()
        

        With Groovy 1.7.10:

        curry $ groovy -version
        Groovy Version: 1.7.10 JVM: 1.6.0_29
        curry $ 
        curry $ groovy script5
        X is null
        

        With Groovy 1.8.5:

        curry $ groovy -version
        Groovy Version: 1.8.5 JVM: 1.6.0_29 Vendor: Apple Inc. OS: Mac OS X
        curry $ 
        curry $ groovy script5
        Caught: java.lang.NullPointerException
        java.lang.NullPointerException
        	at script5.run(script5.groovy:6)
        
        Show
        Jeff Brown added a comment - A slightly more simple script which demonstrates what I think is the same problem: script5.groovy c = { x -> println "X is ${x}" } c = c.curry( null ) c() With Groovy 1.7.10: curry $ groovy -version Groovy Version: 1.7.10 JVM: 1.6.0_29 curry $ curry $ groovy script5 X is null With Groovy 1.8.5: curry $ groovy -version Groovy Version: 1.8.5 JVM: 1.6.0_29 Vendor: Apple Inc. OS: Mac OS X curry $ curry $ groovy script5 Caught: java.lang.NullPointerException java.lang.NullPointerException at script5.run(script5.groovy:6)
        Hide
        CÚdric Champeau added a comment -

        Paul, if you read this: I was working on GROOVY-5262. Using git bisect, I found that the fix on master is from GROOVY-4954 (be7e76536e8aec62e08a527143fe8a1998dc1dfb) but it wasn't on groovy 1.8.x branch. cherry picking lead me to a merge problem, where I found this comment in ClosureCurryTestCase: "/* reverted for the sake of Grails". Does it mean the fix introduces a bug in Grails ?

        Show
        CÚdric Champeau added a comment - Paul, if you read this: I was working on GROOVY-5262 . Using git bisect, I found that the fix on master is from GROOVY-4954 (be7e76536e8aec62e08a527143fe8a1998dc1dfb) but it wasn't on groovy 1.8.x branch. cherry picking lead me to a merge problem, where I found this comment in ClosureCurryTestCase: "/* reverted for the sake of Grails" . Does it mean the fix introduces a bug in Grails ?
        Hide
        CÚdric Champeau added a comment -

        I backported the change (https://github.com/groovy/groovy-core/commit/6344429b8db756caf4f036e2d84dceb8337becb5). I'll keep this ticket open until we make sure that this doesn't trigger any problem in Grails anymore. If it does, please comment on that ticket to give us more hints about the problem.

        Show
        CÚdric Champeau added a comment - I backported the change ( https://github.com/groovy/groovy-core/commit/6344429b8db756caf4f036e2d84dceb8337becb5 ). I'll keep this ticket open until we make sure that this doesn't trigger any problem in Grails anymore. If it does, please comment on that ticket to give us more hints about the problem.
        Hide
        Paul King added a comment -

        Hi CÚdric, yes as per GROOVY-4954 there was apparently some problem at the time wrt Grails. I didn't have visibility to what the problem was or whether it has been subsequently fixed.

        Show
        Paul King added a comment - Hi CÚdric, yes as per GROOVY-4954 there was apparently some problem at the time wrt Grails. I didn't have visibility to what the problem was or whether it has been subsequently fixed.
        Hide
        blackdrag blackdrag added a comment -

        since the fix is now in 1.8 and 2.0 I am closing the issue now. I put in Paul as assignee, since it was his commit.

        Anyway, if there are problems we can reopen the issue of course

        Show
        blackdrag blackdrag added a comment - since the fix is now in 1.8 and 2.0 I am closing the issue now. I put in Paul as assignee, since it was his commit. Anyway, if there are problems we can reopen the issue of course

          People

          • Assignee:
            Paul King
            Reporter:
            Jeff Brown
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: