Re: getTypeMap() returns null - bug?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Dave Cramer <davecramer(at)postgres(dot)rocks>
Cc: rob stone <floriparob(at)gmail(dot)com>, javadesigner <javadesigner(at)yahoo(dot)com>, List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: getTypeMap() returns null - bug?
Date: 2020-05-11 14:00:39
Message-ID: CAKFQuwYWJadTO+t3h_XLmqzn+VLhCiRjxU1TsR-wBMJaTRMNDw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Monday, May 11, 2020, Dave Cramer <davecramer(at)postgres(dot)rocks> wrote:

>
>
> On Mon, 11 May 2020 at 02:21, rob stone <floriparob(at)gmail(dot)com> wrote:
>
>> Hi,
>>
>> On Mon, 2020-05-11 at 01:03 -0400, javadesigner wrote:
>> > Hi all:
>> >
>> > I'm playing around with customized Type Mappings and have the
>> > following
>> > snipped of code:
>> >
>> > ====
>> > Connection con = getConnection(); /*get connection from driver -
>> > util
>> > method*/
>> > System.out.println("GOT CONNECTION:" + con);
>> > java.util.Map map = con.getTypeMap();
>> > System.out.println("map:"+map);
>> > ====
>> >
>> > When I run this I get:
>> >
>> > GOT CONNECTION:org(dot)postgresql(dot)jdbc(dot)PgConnection(at)3f8f9dd6
>> > map:null
>> >
>> > getTypeMap should return a map but it returns null !
>> >
>> > I don't see any pending issues/bug on the mailing list archives.
>> >
>> > I'm using the following (up-to-date) setup:
>> >
>> > postgres 11.7
>> > driver: postgresql-42.2.12.jar
>> > java: 1.8.x
>> >
>> > Best,
>> > -J
>> >
>> >
>>
>> From the doco:-
>>
>> Map<String,Class<?>> getTypeMap() throws SQLException
>>
>> Retrieves the Map object associated with this Connection object. Unless
>> the application has added an entry, the type map returned will be
>> empty.
>>
>> You must invoke setTypeMap after making changes to the Map object
>> returned from getTypeMap as a JDBC driver may create an internal copy
>> of the Map object passed to setTypeMap:
>>
>> Map<String,Class<?>> myMap = con.getTypeMap();
>> myMap.put("mySchemaName.ATHLETES", Athletes.class);
>> con.setTypeMap(myMap);
>>
>>
>> Returns:
>> the java.util.Map object associated with this Connection object
>> Throws:
>> SQLException - if a database access error occurs or this method is
>> called on a closed connection
>> SQLFeatureNotSupportedException - if the JDBC driver does not
>> support this method
>> Since:
>> 1.2
>>
>>
>>
>> Note this paragraph:- "Retrieves the Map object associated with this
>> Connection object. Unless the application has added an entry, the type
>> map returned will be empty." I.e., null.
>>
>> Yes, it is a bug. It should return an empty typemap
>

Given the code in getObject and lack of use anywhere else I’d say it should
return the unsupported exception. Not reason to delay the error until
later.

David J.

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message David G. Johnston 2020-05-11 14:04:26 Re: getTypeMap() returns null - bug?
Previous Message Dave Cramer 2020-05-11 13:00:33 [pgjdbc/pgjdbc] f3abb4: fix: getTypeMap() returning null (#1781)