groovy
  1. groovy
  2. GROOVY-4944

Presence of "assert" unexpectedly changes program semantics (in Groovlet)

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.0
    • Fix Version/s: 1.8.2, 1.9-beta-3, 1.7.11
    • Component/s: Groovlet / GSP
    • Labels:
      None
    • Environment:
      Red Hat Enterprise Linux Server release 5.6, Sun JDK build 1.6.0_26-b03
    • Number of attachments :
      0

      Description

      In a Groovlet:

      We have a function to map "stuff" to a boolean:

      boolean mapBoolean(def datum, boolean defaultValue) {
         ......
         return res
      }
      

      Immediately after the above in the Groovlet source, the function is tested:

      assert mapBoolean(null, false) == false
      assert mapBoolean(null, null)  == false
      

      One would expect the compiler to generate an error as 'null' cannot be passed as second parameter.

      But the asserts above are accepted and pass!

      If one removes the first assert and changes to solely

      assert mapBoolean(null, null)  == false
      

      THEN the compiler generates an error:

      message GroovyServlet Error: script: 'foo': Script processing failed.No signature of method: com.mplify.interact.InspectMsg.mapBoolean() is applicable for argument types: (null, null) values: [null, null] Possible solutions: mapBoolean(java.lang.Object, boolean), asBoolean()org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)
      

      A totally bared-down test "Simple.groovy" would be:

      boolean mapBoolean(def datum, boolean defaultValue) {
         return false
      }
      
      if (params['run']) {
         assert mapBoolean(null, false)  == false
      }
      
      assert mapBoolean(null, null) == false
      
      html.html {
          head { title "Testing" }
          body { div "PASSED" }
      }
      

      Called with Simple.groovy?run=true ---> PASSED
      Called with Simple.groovy ---> Script processing failed.No signature of method: Simple.mapBoolean() is applicable for argument types: (null, null)

        Activity

        Guillaume Laforge made changes -
        Field Original Value New Value
        Description In a Groovlet:

        We have a function to map "stuff" to a boolean:

        boolean mapBoolean(def datum, boolean defaultValue) {
           ......
           return res
        }

        Immediately after the above in the Groovlet source, the function is tested:

        assert mapBoolean(null, false) == false
        assert mapBoolean(null, null) == false

        One would expect the compiler to generate an error as 'null' cannot be passed as second parameter.

        But the asserts above are accepted and pass!

        If one removes the first assert and changes to solely

        assert mapBoolean(null, null) == false

        THEN the compiler generates an error:

        message GroovyServlet Error: script: 'foo': Script processing failed.No signature of method: com.mplify.interact.InspectMsg.mapBoolean() is applicable for argument types: (null, null) values: [null, null] Possible solutions: mapBoolean(java.lang.Object, boolean), asBoolean()org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)


        A totally bared-down test "Simple.groovy" would be:


        boolean mapBoolean(def datum, boolean defaultValue) {
           return false
        }

        if (params['run']) {
           assert mapBoolean(null, false) == false
        }

        assert mapBoolean(null, null) == false

        html.html {
            head { title "Testing" }
            body { div "PASSED" }
        }


        Called with Simple.groovy?run=true ---> PASSED
        Called with Simple.groovy ---> Script processing failed.No signature of method: Simple.mapBoolean() is applicable for argument types: (null, null)
        In a Groovlet:

        We have a function to map "stuff" to a boolean:
        {code}
        boolean mapBoolean(def datum, boolean defaultValue) {
           ......
           return res
        }
        {code}
        Immediately after the above in the Groovlet source, the function is tested:
        {code}
        assert mapBoolean(null, false) == false
        assert mapBoolean(null, null) == false
        {code}
        One would expect the compiler to generate an error as 'null' cannot be passed as second parameter.

        But the asserts above are accepted and pass!

        If one removes the first assert and changes to solely
        {code}
        assert mapBoolean(null, null) == false
        {code}
        THEN the compiler generates an error:
        {code}
        message GroovyServlet Error: script: 'foo': Script processing failed.No signature of method: com.mplify.interact.InspectMsg.mapBoolean() is applicable for argument types: (null, null) values: [null, null] Possible solutions: mapBoolean(java.lang.Object, boolean), asBoolean()org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)
        {code}

        A totally bared-down test "Simple.groovy" would be:

        {code}
        boolean mapBoolean(def datum, boolean defaultValue) {
           return false
        }

        if (params['run']) {
           assert mapBoolean(null, false) == false
        }

        assert mapBoolean(null, null) == false

        html.html {
            head { title "Testing" }
            body { div "PASSED" }
        }
        {code}

        Called with Simple.groovy?run=true ---> PASSED
        Called with Simple.groovy ---> Script processing failed.No signature of method: Simple.mapBoolean() is applicable for argument types: (null, null)
        blackdrag blackdrag made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Jochen Theodorou [ blackdrag ]
        Fix Version/s 1.7.11 [ 17244 ]
        Fix Version/s 1.8.2 [ 17495 ]
        Fix Version/s 1.9-beta-2 [ 17494 ]
        Resolution Fixed [ 1 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: