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

Script returns "interface groovy.lang.Category" when evaluating "Category"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.6
    • None
    • class generator
    • None
    • XP or linux. Reproduces with a simple java program using embeddable groovy.

    Description

      If a script is simply "Category" where the binding has capability to resolve a variable of that name, Groovy returns "interface groovy.lang.Category" instead of the value of the variable "Category" from the given binding object. Here's a java code that reproduces this issue:

      import groovy.lang.Binding;
      import groovy.lang.GroovyShell;
      import groovy.lang.Script;
      
      public class testCategory {
      
          public static void main(String[] args) {
              Binding binding = new Binding() {
                  public Object getVariable(String key) {
                      if (key.equals("Category")) {
                          return new Long(210);
                      }
                      return super.getVariable(key);
                  }
              };
              GroovyShell shell =
                  new GroovyShell(Thread.currentThread().getContextClassLoader());
              String expr = "Category";
              Script scr = shell.parse(expr);
              System.out.println(expr);
              scr.setBinding(binding);
              Object value = scr.run();
              System.out.println(value);
          }
      }
      

      The output of the above code is expected to be:
      Category
      210

      instead, what we get is:
      Category
      interface groovy.lang.Category

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            svinayak S Vinayaka
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: