pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vadim Nasardinov <vadimn@redhat.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: context classloader
Date: Wed, 19 Jan 2005 09:57:26 -0500
Message-ID: <200501190957.26908@vadim.nasardinov> (raw)
In-Reply-To: <41EDDE4B.7030304@opencloud.com>
References: <Pine.BSO.4.56.0501170706010.29112@leary.csoft.net>
	<200501182208.21287@vadim.nasardinov>
	<41EDDE4B.7030304@opencloud.com>

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?



view thread (12+ messages)  latest in thread

Message-ID: <200501190957.26908@vadim.nasardinov>
Permalink:  ../200501190957.26908@vadim.nasardinov/
Also on:    postgresql.org/message-id/200501190957.26908@vadim.nasardinov

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: vadimn@redhat.com
  Subject: Re: context classloader
  In-Reply-To: <200501190957.26908@vadim.nasardinov>
  References: <Pine.BSO.4.56.0501170706010.29112@leary.csoft.net> <200501182208.21287@vadim.nasardinov> <41EDDE4B.7030304@opencloud.com> <200501190957.26908@vadim.nasardinov>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox