Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tzuud-0002DQ-SF for pgsql-jdbc@arkaria.postgresql.org; Mon, 28 Jan 2013 20:02:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tzuuc-0000TS-T9 for pgsql-jdbc@arkaria.postgresql.org; Mon, 28 Jan 2013 20:02:38 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TzuuW-0000O6-Bf for pgsql-jdbc@postgresql.org; Mon, 28 Jan 2013 20:02:32 +0000 Received: from nm21-vm0.bullet.mail.bf1.yahoo.com ([98.139.213.137]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TzuuU-0001zj-JT for pgsql-jdbc@postgresql.org; Mon, 28 Jan 2013 20:02:31 +0000 Received: from [98.139.212.152] by nm21.bullet.mail.bf1.yahoo.com with NNFMP; 28 Jan 2013 20:02:29 -0000 Received: from [98.139.212.244] by tm9.bullet.mail.bf1.yahoo.com with NNFMP; 28 Jan 2013 20:02:29 -0000 Received: from [127.0.0.1] by omp1053.mail.bf1.yahoo.com with NNFMP; 28 Jan 2013 20:02:29 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 616887.57753.bm@omp1053.mail.bf1.yahoo.com Received: (qmail 21840 invoked by uid 60001); 28 Jan 2013 20:02:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1359403349; bh=gnC0fD/OulJAoMJhvWrSJq/2ing37gdI2fcf73aAwnw=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=1S2ifhkNRsGNmUD40yf020DKF5+uV3cOGK4mYkZQGuA/t83/dJKZarRe32kk6sFj242Uk1oAIpishbvGJfCXsEtlL2DdJCrjg2o7UlEN4UnKgrkW85DqUu5gr1KKyBEUI+tYTMlUWyKDFIKACPabXVzaShSGUUTRonmsntYCRxE= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=ymail.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=P8ER6cLu/+XYr+w4XhtZlJ5QAD2cuM9eqNKPvBSDjpGnPxWYI9sXUXqrOgsvWX8FKaeZ1avEqvNVHW+xKFhbOS+QEOgtJ1BSSocEQdSaFOGzuWNuX8MoK1rYwsAd1gLB4INZ8VidaJH4zAnz7nSGICy1/u1FQ3h5kM4VrHGBnP4= ; X-YMail-OSG: RTwoYScVM1liLd7DjfC61JdgL6V0rfpLNpR5zW7SXKgLqLy bDjgGVWmHyaSyfJU3P5j9qYEyOOY4.hgTTqg.Y0r7g5ykv83wZ_SxgdvH.ti qVIO4gq4TKutkWCwb5qwowjTcr6q2szcfS_SOpG5xhgKZIeYVMb.h.cQ4wIC 08a6rcFduyavFHlqYMIpBYkqYIJEBUEuudeAA9lbrcT1MQPND9WotS.sGQ6z kHsQMn7ewe7ptiPUG0jwewq9OitO9sgHhwso.khyFO4xi0Jcflr_c4x7sqid rn3ciLE6TJMcvLnqxmLsTKlK71LpbmGIEqevxFSN52gLMy2z.18p4fiOvJFh 5vA.lHFh9ccfAjwtiazlY2UABNmy3N5TlpnzXuh8E8_EwmnycXFATFPQa9hm tyMPYbWyq4US.HJvfkPUA6ZbzMI9vjmj9c.CPD6.rRHPKzYVsqobShvtftbO kUwj4dvoutp4ls1pZYchd_jv.Nmp62m9blfGHbRkYT65q92VNTc.qsjPBw1l 6NStd3DdCz0DwTUE7jrijkRF5aWJd14NKoE2sdo3tKpg6PQTy3HAK9BDY3f_ GLwn8uY.Mc9KTRWA- Received: from [76.255.19.161] by web162902.mail.bf1.yahoo.com via HTTP; Mon, 28 Jan 2013 12:02:28 PST X-Rocket-MIMEInfo: 001.001, TmF0aGFuaWVsIFdhaXNicm90IDx3YWlzYnJvdEBoaWdoZmxlZXQuY29tPiB3cm90ZToKCj4gSSBmb3VuZCB0aGlzIHdoaWxlIHdvcmtpbmcgd2l0aCBhbm90aGVyIEpEQkMgZHJpdmVyIChTdGVscyBYTUwKPiBkcml2ZXIpLsKgIFRoZSBQb3N0Z3Jlc3FsIGRyaXZlcidzIGNvbm5lY3QoKSBtZXRob2QgaXMgZXhwZWN0aW5nCj4gdGhlIHBhc3NlZCBQcm9wZXJ0aWVzIG9iamVjdCB0byBoYXZlIG9ubHkgc3RyaW5nIHZhbHVlcywgYnV0IHRoaXMKPiBpcyBub3QgYWN0dWFsbHkgZ3VhcmFudGVlZCB0byBiZSB0aGUBMAEBAQE- X-Mailer: YahooMailWebService/0.8.131.499 References: <74B305A4-D481-4D4C-8E0E-8EBAB50CF584@highfleet.com> Message-ID: <1359403348.20803.YahooMailNeo@web162902.mail.bf1.yahoo.com> Date: Mon, 28 Jan 2013 12:02:28 -0800 (PST) From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: Bug report: NullPointerException from Driver.connect when passed a Properties with non-string values To: Nathaniel Waisbrot , "pgsql-jdbc@postgresql.org" In-Reply-To: <74B305A4-D481-4D4C-8E0E-8EBAB50CF584@highfleet.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: 0.0 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Nathaniel Waisbrot wrote: > I found this while working with another JDBC driver (Stels XML > driver).=A0 The Postgresql driver's connect() method is expecting > the passed Properties object to have only string values, but this > is not actually guaranteed to be the case. In addition to Dave's perfectly valid point about DriverPropertyInfo, please note the following about the Properties class: http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html This page includes: | Each key and its corresponding value in the property list is a | string. and: | Because Properties inherits from Hashtable, the put and putAll | methods can be applied to a Properties object. Their use is | strongly discouraged as they allow the caller to insert entries | whose keys or values are not Strings. The setProperty method | should be used instead. If the store or save method is called on | a "compromised" Properties object that contains a non-String key | or value, the call will fail. Similarly, the call to the | propertyNames or list method will fail if it is called on a | "compromised" Properties object that contains a non-String key. So, while it is true that the Properties object is not guaranteed to contain only String objects, doing otherwise is "strongly discouraged", a Properties object containing other objects is considered "compromised", and some methods which are part of the Properties class will fail.=A0 I think it is best for a JDBC driver to throw an exception when it encounters such compromised objects. > I think that the PG driver should wrap the NullPointerException > in a SQLException, which would allow the DriverManager to attempt > to use other JDBC drivers to make the connection. Well, it should not normally be the properties which determine which driver can be used for the connection, but the front of the URL.=A0 If it is the wrong driver, it should not throw any exception at all; it should return NULL: http://docs.oracle.com/javase/1.3/docs/api/java/sql/Driver.html#connect%28j= ava.lang.String,%20java.util.Properties%29 | The driver should return "null" if it realizes it is the wrong | kind of driver to connect to the given URL. This will be common, | as when the JDBC driver manager is asked to connect to a given | URL it passes the URL to each loaded driver in turn. | | The driver should raise a SQLException if it is the right driver | to connect to the given URL, but has trouble connecting to the | database. But I do agree that it is bad form to allow a RuntimeException to be thrown by a driver method rather than catching that and wrapping it in a SQLException or returning null. -Kevin --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc