X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A11DE3A42B5 for ; Wed, 19 Jan 2005 14:57:16 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 96541-05 for ; Wed, 19 Jan 2005 14:57:02 +0000 (GMT) Received: from mx1.redhat.com (mx1.redhat.com [66.187.233.31]) by svr1.postgresql.org (Postfix) with ESMTP id 757863A42B3 for ; Wed, 19 Jan 2005 14:57:00 +0000 (GMT) Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id j0JEuwGu016322 for ; Wed, 19 Jan 2005 09:56:58 -0500 Received: from mail.boston.redhat.com (mail.boston.redhat.com [172.16.76.12]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id j0JEuvO02310 for ; Wed, 19 Jan 2005 09:56:57 -0500 Received: from localhost.localdomain (sebastian-int.corp.redhat.com [172.16.52.221]) by mail.boston.redhat.com (8.12.8/8.12.8) with ESMTP id j0JEusp5018477 for ; Wed, 19 Jan 2005 09:56:57 -0500 From: Vadim Nasardinov Organization: Red Hat / Westford To: pgsql-jdbc@postgresql.org Subject: Re: context classloader Date: Wed, 19 Jan 2005 09:57:26 -0500 User-Agent: KMail/1.7 References: <200501182208.21287@vadim.nasardinov> <41EDDE4B.7030304@opencloud.com> In-Reply-To: <41EDDE4B.7030304@opencloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200501190957.26908@vadim.nasardinov> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200501/191 X-Sequence-Number: 12071 On Tuesday 18 January 2005 23:12, Oliver Jowett wrote: > Ok, but I don't understand why you'd want to jump through all these > hoops in the first place. Because you may want to be a good citizen in the app server world, where defaulting to the system classloader still seems suboptimal to me. This use case has been adequately addressed in your reply though. I don't want to press this line of reasoning any further. > It is even less predictable when the static initializer will be run > (and therefore what the CCL will be set to at that point). What's > the point? The same goes for getClass().getClassLoader(). It's not predictable what this returns. > It's the logical conclusion of using the CCL to find the defaults. I don't see how that follows. > What is special about [...] the first action that happens to cause > class initialization (if you go with magic in the static > initializer)? It's special because it determines the result of getClass().getClassLoader(). In other words, it's special because current code treats as such: Enumeration urls = getClass().getClassLoader(). getResources("/org/postgresql/driverconfig.properties"); For the sake of completeness, what do you think of doing nothing in the case when the driver is loaded by the bootstrap classloader? In other words, wrap the affected chunk of code in the following conditional: if (getClass().getClassLoader() != null) { // load the /org/postgresql/driverconfig.properties files } Thanks, Vadim P.S. > > (BTW, couldn't this be Driver.class.getClassLoader() instead?) > > Yes. getClass() tends to be a bit friendlier to anything that tweaks > the bytecode, though, since a .class reference compiles down to a > call to Class.forName() which breaks if the class is renamed, etc. Out of curiosity, is it a formal policy of the pgsql-jdbc project to be friendly to bytecode mungers? What other guidelines does one need to be mindful of?