Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
Scripting JSP 2.0.10, Scripting JavaScript 2.0.8, Scripting API 2.1.0, Launchpad Base 2.2.0, JCR Resource 2.0.6, Event 2.4.2
-
None
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.