1. Groovy
  2. GROOVY-2105

Groovy category support is broken in multi-threaded environment


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0, 1.1-beta-1, 1.1-beta-2
    • Fix Version/s: 1.1-beta-3
    • Component/s: None
    • Labels:
    • Environment:
      Windows XP, jdk 1.5.0_11


      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(
      at groovy.lang.MetaClassImpl.invokeMethod(
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(
      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 , but I have a bit simpler testcase and a patch proposal for that, so I opened one more issue.

      1. Test.groovy
        0.3 kB
        Max Ishchenko


        Max Ishchenko created issue -
        Guillaume Delcroix made changes -
        Field Original Value New Value
        Assignee Jochen Theodorou [ blackdrag ]
        Fix Version/s 1.1-beta-3 [ 13590 ]
        Jochen Theodorou added a comment -


        Jochen Theodorou added a comment - fixed
        Jochen Theodorou made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12731193 ] Default workflow, editable Closed status [ 12743123 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12972839 ] Default workflow, editable Closed status [ 12974220 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Closed Closed
        6d 7h 47m 1 Jochen Theodorou 13/Sep/07 16:03


          • Assignee:
            Jochen Theodorou
            Max Ishchenko
          • Votes:
            0 Vote for this issue
            1 Start watching this issue


            • Created: