Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-244

Webapp classloader memory leaks

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1
    • 3.2
    • None
    • Inside J2EE container when Jexl library is included in the deployed .war file

    Description

      I have spotted that the following constructions, like for example in JexlEngine.java

          public static final Object TRY_FAILED = new Object() {
              @Override
              public String toString() {
                  return "tryExecute failed";
              }
          };
      

      are not garbage collected when web-app is reloaded and its classloader is released. This is because circular references are created when static class members are initialized with non-static inner/anonymous classes, which are holding implicit references to its enclosing class and thus to its static class type. There are other such examples in JexlEngine.java like

          protected static final java.lang.ThreadLocal<JexlContext.ThreadLocal> CONTEXT =             new java.lang.ThreadLocal<JexlContext.ThreadLocal>() {..
      
          protected static final java.lang.ThreadLocal<JexlEngine> ENGINE =
                  new java.lang.ThreadLocal<JexlEngine>() {...
      
      

      The issue is easily resolved if for example the following pattern is followed

          public static class FailObject extends Object {
              @Override
              public String toString() {
                  return "tryExecute failed";
              }
          }
      
          public static final Object TRY_FAILED = new FailObject();
      

      Attachments

        Activity

          People

            henrib Henri Biestro
            dmitri_blinov Dmitri Blinov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: