Bug 1459499 - jdbc driver attempts to get type information on dropped columns
Summary: jdbc driver attempts to get type information on dropped columns
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: postgresql-jdbc
Version: 27
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Pavel Raiskup
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1459502
TreeView+ depends on / blocked
 
Reported: 2017-06-07 10:01 UTC by Eli Mesika
Modified: 2017-08-24 11:25 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-08-24 07:03:30 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Sample tar file for reproducing the bug (1.86 KB, application/x-gzip)
2017-06-07 10:01 UTC, Eli Mesika
no flags Details

Description Eli Mesika 2017-06-07 10:01:56 UTC
Created attachment 1285738 [details]
Sample tar file for reproducing the bug

Description of problem:

jdbc driver attempts to get type information on dropped columns when calling a stored procedure that access a table which one/more of its columns was dropped.

When upgrading to version 42.1.1 we got an exception when accessing a stored procedure that does a simple select from one of our tables :

java.lang.NullPointerException
at org.postgresql.jdbc.TypeInfoCache.getSQLType(TypeInfoCache.java:185)

Generally speaking, the bug is that jdbc driver attempts to get type information on dropped
columns when calling a stored procedure that access a table which one of its columns was dropped.

The attached sample.tar package demonstraits this failure

In this package please find :

    pom.xml - the maven pom file
    src - java source directory for the sample code
    sample.sql - SQL code for creating a sample table and a stored procedure to demonstrate the peoblem.


Version-Release number of selected component (if applicable):

42.1.1

How reproducible:

Steps to Reproduce:

1) please extract the package to a directory named 'sample'

2) create the following DB user

createuser -U postgres -P -s -e testuser

when prompt for password for the new user type:

123456

3) create a database that is owned by the "testuser" user :

su - postgres -c "psql -U postgres -c 'create database testdb owner testuser template template0;' template1"

4) create the sample table and the SP that access it :

psql -U testuser -f ./sample.sql testdb

5) run the following from pgsql prompt

SELECT
relnatts,
attname,
attisdropped
FROM
pg_class
JOIN pg_attribute att ON attrelid = pg_class.oid
WHERE
relname = 'vm_dynamic';

you will get the folowing result and as you see all attisdropped = false since this is a new created table

relnatts | attname | attisdropped
----------+----------+--------------
3 | tableoid | f
3 | cmax | f
3 | xmax | f
3 | cmin | f
3 | xmin | f
3 | ctid | f
3 | key_col | f
3 | val_col | f
3 | comment | f

6) compile and run the application from the sample directory

mvn clean install -Dm2.localRepository=
for example: mvn clean install -Dm2.localRepository=/home/emesika/.m2/repository
java -jar target/JDBCDriverBug-1.0-SNAPSHOT.jar

The result is that callMetaDataStoredProcedureDirectly method perfprms as expected

7) run the following from pgsql prompt

alter table sample drop column comment ;

8) run the following from pgsql prompt

SELECT
relnatts,
attname,
attisdropped
FROM
pg_class
JOIN pg_attribute att ON attrelid = pg_class.oid
WHERE
relname = 'vm_dynamic';

relnatts | attname | attisdropped
----------+------------------------------+--------------
3 | tableoid | f
3 | cmax | f
3 | xmax | f
3 | cmin | f
3 | xmin | f
3 | ctid | f
3 | key_col | f
3 | val_col | f
3 | ........pg.dropped.3........ | t

Now you have a column named "........pg.dropped.3........" , this is the 'comment' column that was dropped

9) compile and run the application from the sample directory

mvn clean install -Dm2.localRepository=
java -jar target/JDBCDriverBug-1.0-SNAPSHOT.jar

You will got this Exception:

Exception in thread "main" java.lang.NullPointerException
at org.postgresql.jdbc.TypeInfoCache.getSQLType(TypeInfoCache.java:185)
at org.postgresql.jdbc.TypeInfoCache.getSQLType(TypeInfoCache.java:181)
at org.postgresql.jdbc.PgDatabaseMetaData.getProcedureColumns(PgDatabaseMetaData.java:1153)
at JDBCSample.JDBCDriverBug.callMetaDataStoredProcedureDirectly(JDBCDriverBug.java:47)
at JDBCSample.JDBCDriverBug.main(JDBCDriverBug.java:17)


Actual results:

When a table has any dropped columns , a stored procedure that attempts to access that table will cause NullPointerException when trying to return the stored procedure call result metadata 


Expected results:

dropped columns should be omitted for metadata queries as it was in old drivers 
(9.2.x)


Additional info:

Please see also the open issue in :

See issue https://github.com/pgjdbc/pgjdbc/issues/838

Comment 1 Pavel Raiskup 2017-06-08 10:43:26 UTC
Eli, thanks for the report.  Upstream maintainer (Dave Cramer) proposed fix
for issue 838, can you confirm (in upstream tracker especially) it fixes your
issue?  Thanks!

Comment 2 Eli Mesika 2017-06-08 12:43:55 UTC
(In reply to Pavel Raiskup from comment #1)
> Eli, thanks for the report.  Upstream maintainer (Dave Cramer) proposed fix
> for issue 838, can you confirm (in upstream tracker especially) it fixes your
> issue?  Thanks!

I test the fix and it resolved the issue , I also wrote this as a comment in the original issue (https://github.com/pgjdbc/pgjdbc/issues/838)

Comment 3 Eli Mesika 2017-07-30 08:36:46 UTC
According to my testings this issue is already solved in 42.1.2 and tested also in 42.1.3 , so , the status of this BZ should reflect the fact that it was already resolved ...

Comment 4 Jan Kurik 2017-08-15 07:40:57 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 27 development cycle.
Changing version to '27'.

Comment 5 Pavel Raiskup 2017-08-24 07:03:30 UTC
Sorry for the delay, I've built the new postgresql-jdbc version 42.1.4-1
into Rawhide.

Comment 6 Martin Perina 2017-08-24 08:58:08 UTC
(In reply to Pavel Raiskup from comment #5)
> Sorry for the delay, I've built the new postgresql-jdbc version 42.1.4-1
> into Rawhide.

Any chance it will be available in F25 or F26?

Comment 7 Pavel Raiskup 2017-08-24 11:25:37 UTC
Well, I would rather avoid rebasing the package in stable Fedora.

Would you be OK to have a look at back-patching the stable releases + f27?


Note You need to log in before you can comment on or make changes to this bug.