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

Add ability to dynamically modify classes blocked by StackTraceUtils during a sanitize operation.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1-rc-2
    • 1.6-rc-1, 1.7-beta-1
    • None
    • None
    • Patch

    Description

      There is currently no way to modify the classes that are removed during the sanitization of a stack trace. The mechanism is hard-coded into StackTraceUtils.

      This code will let various packages add tests in the form of a closure (can be done during static initialization). An example of a test, or filter:

      //Removes stack trace elements where the class is part of the com.lilypepper.groovy package, or any subpackages.
      static final Closure filter =

      {className -> if(className.startsWith('com.lilypepper.groovy')) return false; else return null; }

      If the closure returns true, the classname is definitely included in the stack trace. If it returns false, the classname is definitely omitted from the stack trace. If it returns null, processing continues (defaults are set by StackTraceUtils).

      Add the following code to org.codehaus.groovy.runtime.StackTraceUtils:

      private static List<Closure> classFilters = new ArrayList<Closure>();

      public static void addClassTest(Closure classFilter)

      { classFilters.add(classFilter); }

      Also, modify method to look like this:

      public static boolean isApplicationClass(String className) {
      for(Closure classFilter : classFilters)
      {
      Boolean result = (Boolean)classFilter.call(className);
      if(result != null)

      { return result.booleanValue(); }

      }

      for (int i = 0; i < GROOVY_PACKAGES.length; i++) {
      String groovyPackage = GROOVY_PACKAGES[i];
      if (className.startsWith(groovyPackage))

      { return false; }

      }
      return true;
      }

      Attachments

        1. StackTraceUtils2.java
          6 kB
          Jason Smith

        Activity

          People

            blackdrag Jochen Theodorou
            jasonsmith Jason Smith
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: