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

Groovy category support is broken in multi-threaded environment

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0, 1.1-beta-1, 1.1-beta-2
    • 1.1-beta-3
    • None
    • None
    • Windows XP, jdk 1.5.0_11

    Description

      We're using Groovy to write controllers in Spring MVC environment. But we often see a "MissingPropertyException" for ModelAndView.viewName property. We investigated it, and found, that org.codehaus.groovy.runtime.GroovyCategorySupport#categoriesInUse counter was not zero, and we were not using any categories in that line! Thus, Groovy tried to fetch a setter from an object, then from a category, and <as we had no active category at the moment, it got null for the setter, and overwrote the valid setter from real ModelAndView. This behaviour (overriding real setter with null setter from category) was fixed in 1.1 beta. But these were only sympthoms - the real problem is the counter. It's incrementing/decrementing methods lack synchronization. There is no synchronization at all!
      The methods in question are org.codehaus.groovy.runtime.GroovyCategorySupport#newScope, org.codehaus.groovy.runtime.GroovyCategorySupport#endScope and org.codehaus.groovy.runtime.GroovyCategorySupport#hasCategoryInAnyThread. Each one uses one static long variable, and it will break almost for sure.

      So, we've written a testcase for that. It's attached to the issue.
      Sometimes we get
      groovy.lang.MissingMethodException: No signature of method: java.lang.String.test() is applicable for argument types: (java.lang.String) values:

      {" bar"}

      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:572)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:450)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:119)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:187)
      at Test$_run_closure1_closure3_closure4.doCall(Test.groovy:12)

      After adding "synchronized" to these three methods signatures, we got no exceptions.
      This bug is similar to http://jira.codehaus.org/browse/GROOVY-1883 , but I have a bit simpler testcase and a patch proposal for that, so I opened one more issue.

      Attachments

        1. Test.groovy
          0.3 kB
          Max Ishchenko

        Activity

          People

            blackdrag Jochen Theodorou
            max.ishchenko Max Ishchenko
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: