Обсуждение: getTypeMap() returns null - bug?

Поиск
Список
Период
Сортировка

getTypeMap() returns null - bug?

От
javadesigner
Дата:
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.postgresql.jdbc.PgConnection@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



Re: getTypeMap() returns null - bug?

От
rob stone
Дата:
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.postgresql.jdbc.PgConnection@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.








Re: getTypeMap() returns null - bug?

От
javadesigner
Дата:
empty is not the same as null in java. this is a java specific 
discussion btw.

rob stone wrote on 5/11/20 2:20 AM:
> Hi,
>
> On Mon, 2020-05-11 at 01:03 -0400, javadesigner wrote:
>> Hi all:
>>
>>
>>  From the doco:-
>> [..]
>>
>> 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.
>>
>>
>>
>>
>>




Re: getTypeMap() returns null - bug?

От
"David G. Johnston"
Дата:
On Sunday, May 10, 2020, javadesigner <javadesigner@yahoo.com> 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.postgresql.jdbc.PgConnection@3f8f9dd6
map:null

getTypeMap should return a map but it returns null !

While I agree, the feature is effectively not supported.


I can’t see changing it to throw a runtime exception and returning an empty map doesn’t make it any more usable so I don’t see the point there either.  The documentation could better reflect reality though.

David J.

Re: getTypeMap() returns null - bug?

От
Mark Rotteveel
Дата:
On 2020-05-11 08:20, rob stone wrote:
> 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.

No, empty does not mean null, it means returning an empty map (eg 
Collections.emptyMap()) or an empty instance of a Map implementation). 
If the PostgreSQL JDBC driver doesn't support type maps, then it should 
throw a SQLFeatureNotSupportedException instead.

Mark



Re: getTypeMap() returns null - bug?

От
Dave Cramer
Дата:


On Mon, 11 May 2020 at 02:21, rob stone <floriparob@gmail.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.postgresql.jdbc.PgConnection@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


Dave Cramer
www.postgres.rocks 

Re: getTypeMap() returns null - bug?

От
"David G. Johnston"
Дата:
On Monday, May 11, 2020, Dave Cramer <davecramer@postgres.rocks> wrote:


On Mon, 11 May 2020 at 02:21, rob stone <floriparob@gmail.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.postgresql.jdbc.PgConnection@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. 

Re: getTypeMap() returns null - bug?

От
"David G. Johnston"
Дата:
On Monday, May 11, 2020, David G. Johnston <david.g.johnston@gmail.com> wrote:

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.

Actually...I’ll srick with my original thought that making it an exception now is not desirable as it could break working code (though not likely...) for no real gain.

David J. 

Re: getTypeMap() returns null - bug?

От
Dave Cramer
Дата:


On Mon, 11 May 2020 at 10:04, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Monday, May 11, 2020, David G. Johnston <david.g.johnston@gmail.com> wrote:

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.

Actually...I’ll srick with my original thought that making it an exception now is not desirable as it could break working code (though not likely...) for no real gain.

David J. 

Using it will throw an exception later in getObject() 
Dave Cramer
www.postgres.rocks 

Re: getTypeMap() returns null - bug?

От
"David G. Johnston"
Дата:
On Monday, May 11, 2020, Dave Cramer <davecramer@postgres.rocks> wrote:


On Mon, 11 May 2020 at 10:04, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Monday, May 11, 2020, David G. Johnston <david.g.johnston@gmail.com> wrote:

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.

Actually...I’ll srick with my original thought that making it an exception now is not desirable as it could break working code (though not likely...) for no real gain.

David J. 

Using it will throw an exception later in getObject() 

I know...IMO that whole block in getObject should be tossed, the protected variable removed, and the getter and setter made to throw exceptions.  Having the exception happen in getObject is what i’m opposed to but accept as a matter of backward compatibility.

David J.

Re: getTypeMap() returns null - bug?

От
rob stone
Дата:

On Mon, 2020-05-11 at 02:28 -0400, javadesigner wrote:
> empty is not the same as null in java. this is a java specific 
> discussion btw.
> 

Vraimente.

java.util.Map map = con.getTypeMap();

So, the variable "map" is now an empty map object. Highly likely it
contains hex zeroes. It could contain the string "empty" but that does
not sound reasonable. Maybe there is no memory address and memory is
only allocated with the first "put".

System.out.println("map:"+map);

So, println accesses the memory occupied by the object and assuming it
contains unprintable hex zeroes, it can either display "null", or
convert to printable zeroes or ignore it and display nothing.

What output did you expect from  "System.out.println("map:"+map);"??
That is the question.






Re: getTypeMap() returns null - bug?

От
"David G. Johnston"
Дата:
On Monday, May 11, 2020, rob stone <floriparob@gmail.com> wrote:


On Mon, 2020-05-11 at 02:28 -0400, javadesigner wrote:
> empty is not the same as null in java. this is a java specific
> discussion btw.
>

Vraimente.

java.util.Map map = con.getTypeMap();

So, the variable "map" is now an empty map object.


No, it wasn’t (its since been modified in between your two posts - you should skim the whole thread). Feel free to read the source code if you don’t believe the OP.
 
Highly likely it
contains hex zeroes. It could contain the string "empty" but that does
not sound reasonable


This would be the English idiom “speaking out of one’s a**” :)
 
Maybe there is no memory address and memory is
only allocated with the first "put".

System.out.println("map:"+map);

So, println accesses the memory occupied by the object and assuming it
contains unprintable hex zeroes, it can either display "null", or
convert to printable zeroes or ignore it and display nothing.

What output did you expect from  "System.out.println("map:"+map);"??
That is the question.

Create an empty HashMap in Java and then print it out - that’s what we expected.  Not “null” which only prints if the variable being printed is null.

David J.

 

Re: getTypeMap() returns null - bug?

От
Dave Cramer
Дата:


On Tue, 12 May 2020 at 00:26, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Monday, May 11, 2020, rob stone <floriparob@gmail.com> wrote:


On Mon, 2020-05-11 at 02:28 -0400, javadesigner wrote:
> empty is not the same as null in java. this is a java specific
> discussion btw.
>

Vraimente.

java.util.Map map = con.getTypeMap();

So, the variable "map" is now an empty map object.


No, it wasn’t (its since been modified in between your two posts - you should skim the whole thread). Feel free to read the source code if you don’t believe the OP.
 
Highly likely it
contains hex zeroes. It could contain the string "empty" but that does
not sound reasonable


This would be the English idiom “speaking out of one’s a**” :)
 
Maybe there is no memory address and memory is
only allocated with the first "put".

System.out.println("map:"+map);

So, println accesses the memory occupied by the object and assuming it
contains unprintable hex zeroes, it can either display "null", or
convert to printable zeroes or ignore it and display nothing.

What output did you expect from  "System.out.println("map:"+map);"??
That is the question.

Create an empty HashMap in Java and then print it out - that’s what we expected.  Not “null” which only prints if the variable being printed is null.

David J.

David,

Apparently you were correct. Throwing a notImplemented exception would be better as this whole discussion is moot until being able to actually do something with the typemap is implemented.


Dave Cramer
www.postgres.rocks 

 

Re: getTypeMap() returns null - bug?

От
Mark Rotteveel
Дата:
On 2020-05-12 06:10, rob stone wrote:
> On Mon, 2020-05-11 at 02:28 -0400, javadesigner wrote:
>> empty is not the same as null in java. this is a java specific
>> discussion btw.
>> 
> 
> Vraimente.
> 
> java.util.Map map = con.getTypeMap();
> 
> So, the variable "map" is now an empty map object. Highly likely it
> contains hex zeroes. It could contain the string "empty" but that does
> not sound reasonable. Maybe there is no memory address and memory is
> only allocated with the first "put".

That is not how maps work in Java. A map is a collection of keys and 
values (aka a hashtable or dictionary), an empty map has no keys (and 
thus no values).

> System.out.println("map:"+map);
> 
> So, println accesses the memory occupied by the object and assuming it
> contains unprintable hex zeroes, it can either display "null", or
> convert to printable zeroes or ignore it and display nothing.
> 
> What output did you expect from  "System.out.println("map:"+map);"??
> That is the question.

Printing out a map is not what you'd normally do in Java, but if you do, 
an empty map will print (without quotes): '{}', assuming the 
java.util.HashMap implementation or the value of 
java.util.Collections.emptyMap().

Mark