Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 94769 invoked from network); 15 Aug 2008 15:18:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Aug 2008 15:18:29 -0000 Received: (qmail 68027 invoked by uid 500); 15 Aug 2008 15:18:27 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 67937 invoked by uid 500); 15 Aug 2008 15:18:27 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@cocoon.apache.org List-Id: Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 67926 invoked by uid 99); 15 Aug 2008 15:18:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Aug 2008 08:18:27 -0700 X-ASF-Spam-Status: No, hits=-1.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of grek@tuffmail.com designates 216.86.168.178 as permitted sender) Received: from [216.86.168.178] (HELO mxout-03.mxes.net) (216.86.168.178) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Aug 2008 15:17:30 +0000 Received: from [192.168.1.232] (unknown [217.116.183.178]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTP id 8A60C23E529 for ; Fri, 15 Aug 2008 11:17:57 -0400 (EDT) Message-ID: <48A59E0D.8080108@tuffmail.com> Date: Fri, 15 Aug 2008 17:17:33 +0200 From: Grzegorz Kossakowski User-Agent: Thunderbird 2.0.0.12 (X11/20071114) MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: Re: RCL plug-in and different classloaders issues References: <48A58C71.5030207@tuffmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Torsten Curdt pisze: > > Just a quick comment: static + classloader == evil ;-) :-) Yes, I thought the same but is there any other solution in scenario I outlined when it's thirdparty class that creates a new instance of your class, which in turn needs to access some of your resources? >> 3. Then another class (3RDPARTY) is being loaded which is not part of >> my block, it's from third-party jar. It's loaded by parent classloader >> to ResourceStoreClassLoader. As part of configuration of this class I >> pass a name of class which is some kind of extension point and is >> implemented by class coming from my block; let's call this class >> EXTENSION. >> 4. 3RDPARTY creates new instance of EXTENSION class (and this class is >> again not loaded by ResourceStoreClassLoader but by parent), but in >> EXTENSION class one tries to access field set in STATIC. >> 5. While EXTENSION tries to access STATIC, STATIC is being loaded >> again, using parent classloader. The value in STATIC is gone, obviously. >> >> So the basic problem is that, this STATIC class is loaded by two >> different classloaders. >> >> I'm wondering if there is any kind of general solution to such >> problems. The only one I can think of is to enforce loading of >> 3RDPARTY class by ResourceStoreClassLoader so everything stays within >> one classloader and even reflection tricks are not dangerous. > > Well, if you think about it: with this setup there is no other way > around to have the parent classloader know of the static class to have > this problem resolved. As you can't (?) modify the parent classloader > your only chance is to have the EXTENSION loaded by the RSCL as well. But how this can be enforced? I mean, 3RDPARTY is loaded by parent and 3RDPARTY, when tries to create a new instance of EXTENSION uses it's own classloader thus uses parent. The only solution I can see here is that I load 3RDPARTY using classloader coming from JCI so then EXTENSION will be loaded with this classloader as well. Am I missing something? > I would take a step back and re-think the situation. This static stuff > smells like wants to be replaced ;-) If I knew how to do it, I would go with that direction immediately. :-P Basically, the problem is that one wants to access Spring's application context within EXTENSION's constructor. Any suggestion how to do it without using static class? >> However, that would mean that one needs to modify commons-jci project. > > Why? How? I was thinking to enforce ResourceStoreClassLoader to load everything but I know that it's not the best idea... -- Grzegorz Kossakowski