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

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

    XMLWordPrintableJSON

    Details

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

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: