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

Throwing Exceptions in Builders confuses groovy

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.0-beta-10
    • None
    • None

    Description

      package groovy.util;

      import java.util.Map;

      /**

      • @author Thomas Heller
        */
        public class BadBuilder extends BuilderSupport
        {
        protected void setParent(Object parent, Object child)
        {
        }

      protected Object createNode(Object name)

      { if (name.equals("blowItUp")) throw new IllegalArgumentException("I didn't like that"); return name; }

      protected Object createNode(Object name, Object value)

      { return name; }

      protected Object createNode(Object name, Map attributes)

      { return name; }

      }

      package groovy.util

      class BadBuilderTestCase extends GroovyTestCase {

      void testBadBuilder() {
      doc = new BadBuilder();
      doc.html {
      body

      { blowItUp(); }

      }
      }
      }

      result:

      groovy.lang.MissingMethodException: No such method: body for class: groovy.util.BadBuilderTestCase$1 with arguments: [groovy.util.BadBuilderTestCase$1$3@472d48]
      at groovy.lang.MetaClass.invokeMethod(MetaClass.java:271)
      at groovy.lang.MetaClass.invokeMethod(MetaClass.java:245)
      at groovy.lang.Closure.doInvokeMethod(Closure.java:89)
      at groovy.lang.Closure.invokeMethod(Closure.java:74)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:117)
      ...

      On another builder I get this exception:

      groovy.lang.IncorrectClosureArgumentsException: Incorrect arguments to closure: groovy.util.BadBuilderTestCase$2@3b8b49. Expected: [class java.lang.Object], actual: null
      at groovy.lang.Closure.call(Closure.java:195)
      at groovy.lang.Closure.call(Closure.java:177)
      at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:129)
      at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:85)

      ...

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            maniax Thomas Heller
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: