Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TztHJ-0002RQ-Cy for pgsql-jdbc@arkaria.postgresql.org; Mon, 28 Jan 2013 18:17:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TztHI-0006gh-AJ for pgsql-jdbc@arkaria.postgresql.org; Mon, 28 Jan 2013 18:17:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TztHH-0006fU-6D for pgsql-jdbc@postgresql.org; Mon, 28 Jan 2013 18:17:55 +0000 Received: from outbound.vnet-inc.com ([216.146.104.103]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TztHB-0001bH-Rv for pgsql-jdbc@postgresql.org; Mon, 28 Jan 2013 18:17:54 +0000 Received: from [192.168.157.132] (unknown [76.75.27.41]) by outbound.vnet-inc.com (Postfix) with ESMTP id D3BD55A60; Mon, 28 Jan 2013 11:17:48 -0700 (MST) Message-ID: <5106C07B.8020800@ttc-cmc.net> Date: Mon, 28 Jan 2013 11:16:27 -0700 From: dmp User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.13) Gecko/20100914 SeaMonkey/2.0.8 MIME-Version: 1.0 To: Nathaniel Waisbrot , pgsql-jdbc@postgresql.org Subject: Re: Bug report: NullPointerException from Driver.connect when passed a Properties with non-string values References: <74B305A4-D481-4D4C-8E0E-8EBAB50CF584@highfleet.com> In-Reply-To: <74B305A4-D481-4D4C-8E0E-8EBAB50CF584@highfleet.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) 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 Hello Nathaniel, Any very robust program will try to handle anything the user throws at it. In this case you have passed a null value as an argument to the method and it as acted according by giving you a NUllPointerException. Perhaps wrapping this as SQLException may be more easily caught by your app., but would be deceptive in response. Perhaps you could submit a patch for consideration, to the solution you desire. The code may be obtained at GitHub. git clone git://github.com/pgjdbc/pgjdbc.git danap. Nathaniel Waisbrot wrote: > I found this while working with another JDBC driver (Stels XML driver). 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. 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. > > Here is a simple Java program which will reproduce the problem: > > ================== > import java.sql.DriverManager; > import java.util.Properties; > > public class PGTest { > public static void main(String[] args) throws Exception { > Class.forName("org.postgresql.Driver"); > Properties info = new Properties(); > info.put("foo", new Object()); // info.getPropert("foo") will return null > DriverManager.getConnection("foo:bar//baz", info); > } > } > ================== > > and here is the stack trace produced by running that program: > > ================== > Exception in thread "main" java.lang.NullPointerException > at java.util.Hashtable.put(Hashtable.java:542) > at java.util.Properties.setProperty(Properties.java:161) > at org.postgresql.Driver.connect(Driver.java:244) > at java.sql.DriverManager.getConnection(DriverManager.java:579) > at java.sql.DriverManager.getConnection(DriverManager.java:190) > at PGTest.main(PGTest.java:9) > ================== > > I'm using postgresql-9.2-1002.jdbc4.jar, with Java 7, running on Mac OS 10.8.2. Output of java -version: > java version "1.7.0_07" > Java(TM) SE Runtime Environment (build 1.7.0_07-b10) > Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode) > > > -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc