Groovy
  1. Groovy
  2. GROOVY-4944

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

    Details

    • Type: Bug Bug
    • Status: 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

      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

        David Tonhofer created issue -
        Guillaume Delcroix 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)
        Jochen Theodorou made changes -
        Fix Version/s 1.8.2 [ 17495 ]
        Fix Version/s 1.7.11 [ 17244 ]
        Status Open [ 1 ] Closed [ 6 ]
        Fix Version/s 1.9-beta-2 [ 17494 ]
        Resolution Fixed [ 1 ]
        Assignee Jochen Theodorou [ blackdrag ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733870 ] Default workflow, editable Closed status [ 12745689 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12974125 ] Default workflow, editable Closed status [ 12981282 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development