Uploaded image for project: 'Commons OGNL'
  1. Commons OGNL
  2. OGNL-181

OgnlRuntime.getCompiler and thread-safety.

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • 4.0.x
    • None

    Description

      As you can see, getCompiler is not thread safe.
      I recently added a new performance benchmark to test its 3d-safety and performance: during my tests I have experienced a fast execution on unsafe version vs the safe one (though every concurrent test instantiated a new compiler).
      I have not yet investigated and I still don't know what can cause running more than one instance of the compiler in the same jvm. If necessary we can consider to make compiler a singleton in order to enforce this concept.

      What do you think guys?

      public static OgnlExpressionCompiler getCompiler( OgnlContext ognlContext )                     
      {                                                                                               
          if ( _compiler == null )                                                                    
          {                                                                                           
              try                                                                                     
              {                                                                                       
                  OgnlRuntime.classForName( ognlContext, "javassist.ClassPool" );                     
                  _compiler = new ExpressionCompiler();                                               
              }                                                                                       
              catch ( ClassNotFoundException e )                                                      
              {                                                                                       
                  throw new IllegalArgumentException(                                                 
                      "Javassist library is missing in classpath! Please add missed dependency!", e );
              }                                                                                       
          }                                                                                           
          return _compiler;                                                                           
      }   
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            maurizio.cucchiara Maurizio Cucchiara

            Dates

              Created:
              Updated:

              Slack

                Issue deployment