Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-1891

Replace Class.forName uses by ClassLoader.loadClass

    XMLWordPrintableJSON

Details

    Description

      Class.forName has a nasty problem in that it caches returned classes in the class load first asked (the initiator) in addition to the class loader actually defining the class. The ClassLoader.loadClass methods do not have this problem and only caches the loaded class in the defining class loader.

      Looking for uses in the Sling code base (using find . -name "*.java" -exec fgrep -l Class.forName {} ;) I found the following nice occurrences:

      launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
      bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/JCRHelper.java
      bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java
      bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspUtil.java
      bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagPluginManager.java
      bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java
      bundles/scripting/api/src/main/java/sun/misc/Service.java
      bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
      contrib/explorers/gwt/src/main/java/org/apache/sling/explorer/client/widgets/tree/resource/ResourceTree.java

      For more information on this problem, I suggest reading the blog series by BJ Hargrave, probably starting with http://blog.bjhargrave.com/2007/09/classforname-caches-defined-class-in.html.

      Attachments

        Activity

          People

            cziegeler Carsten Ziegeler
            fmeschbe Felix Meschberger
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: