Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackOverflowError in getObject if the type of column is NUMERIC and the format binary #1635

Closed
1 of 2 tasks
mahmoudbahaa opened this issue Dec 3, 2019 · 5 comments
Closed
1 of 2 tasks

Comments

@mahmoudbahaa
Copy link
Contributor

mahmoudbahaa commented Dec 3, 2019

I'm submitting a ...

  • bug report
  • feature request

Describe the issue
Sample code :

        Properties properties = new Properties();
        properties.put("user", user);
        properties.put("password", password);
        properties.put("binaryTransferEnable", "NUMERIC");
        properties.put("prepareThreshold", "-1");

        Connection conn = DriverManager.getConnection(url, properties);
        ResultSet rs = conn.createStatement().executeQuery("select 4.3");
        rs.next();
        rs.getObject(1);
        arrayRS.getString(1);`

any of the last 2 statements would throw an exception stack trace for the getObject for example:

Exception in thread "main" java.lang.StackOverflowError
	at java.lang.StringBuffer.setLength(StringBuffer.java:192)
	at java.text.DecimalFormat.expandAffix(DecimalFormat.java:2844)
	at java.text.DecimalFormat.expandAffixes(DecimalFormat.java:2812)
	at java.text.DecimalFormat.applyPattern(DecimalFormat.java:3498)
	at java.text.DecimalFormat.<init>(DecimalFormat.java:464)
	at sun.util.locale.provider.NumberFormatProviderImpl.getInstance(NumberFormatProviderImpl.java:180)
	at sun.util.locale.provider.NumberFormatProviderImpl.getNumberInstance(NumberFormatProviderImpl.java:149)
	at java.text.NumberFormat.getInstance(NumberFormat.java:875)
	at java.text.NumberFormat.getInstance(NumberFormat.java:861)
	at java.text.NumberFormat.getInstance(NumberFormat.java:442)
	at java.text.MessageFormat.subformat(MessageFormat.java:1271)
	at java.text.MessageFormat.format(MessageFormat.java:865)
	at java.text.Format.format(Format.java:157)
	at java.text.MessageFormat.format(MessageFormat.java:841)
	at java.util.logging.Formatter.formatMessage(Formatter.java:138)
	at java.util.logging.SimpleFormatter.format(SimpleFormatter.java:151)
	at java.util.logging.StreamHandler.publish(StreamHandler.java:211)
	at java.util.logging.FileHandler.publish(FileHandler.java:701)
	at java.util.logging.Logger.log(Logger.java:738)
	at java.util.logging.Logger.doLog(Logger.java:765)
	at java.util.logging.Logger.log(Logger.java:831)
	at org.postgresql.jdbc.PgResultSet.getString(PgResultSet.java:1870)
	at org.postgresql.jdbc.PgResultSet.getFixedString(PgResultSet.java:2657)
	at org.postgresql.jdbc.PgResultSet.getNumeric(PgResultSet.java:2344)
	at org.postgresql.jdbc.PgResultSet.internalGetObject(PgResultSet.java:185)
	at org.postgresql.jdbc.PgResultSet.getString(PgResultSet.java:1879)
	at org.postgresql.jdbc.PgResultSet.getFixedString(PgResultSet.java:2657)
	at org.postgresql.jdbc.PgResultSet.getNumeric(PgResultSet.java:2344)
	at org.postgresql.jdbc.PgResultSet.internalGetObject(PgResultSet.java:185)
	at org.postgresql.jdbc.PgResultSet.getString(PgResultSet.java:1879)
        ...

with the last 4 lines keep repeating

Driver Version?

42.2.8

Java Version?

1.8

OS Version?

Windows

PostgreSQL Version?

tried on both Postgres 10.6 and 9.6.15

To Reproduce
Steps to reproduce the behaviour:
see describe

Expected behaviour
should return "4.3"

Logs
If possible PostgreSQL logs surrounding the occurrence of the issue
Additionally logs from the driver can be obtained adding

loggerLevel=TRACE&loggerFile=pgjdbc-trace.log 

to the connection string

jdbc logs :


Dec 03, 2019 10:30:18 PM org.postgresql.Driver connect
Dec 03, 2019 11:39:55 PM org.postgresql.Driver connect
FINE: Connecting with URL: jdbc:postgresql://localhost:5432/demo?loggerLevel=TRACE&loggerFile=pgjdbc-trace.log
Dec 03, 2019 11:39:55 PM org.postgresql.jdbc.PgConnection <init>
FINE: PostgreSQL JDBC Driver 42.2.8
Dec 03, 2019 11:39:55 PM org.postgresql.jdbc.PgConnection setDefaultFetchSize
FINE:   setDefaultFetchSize = 0
Dec 03, 2019 11:39:55 PM org.postgresql.jdbc.PgConnection setPrepareThreshold
FINE:   setPrepareThreshold = -1
Dec 03, 2019 11:39:55 PM org.postgresql.jdbc.PgConnection setForceBinary
FINE:   setForceBinary = true
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.ConnectionFactoryImpl openConnectionImpl
FINE: Trying to establish a protocol version 3 connection to localhost:5432
Dec 03, 2019 11:39:55 PM org.postgresql.core.Encoding <init>
FINEST: Creating new Encoding UTF-8 with fastASCIINumbers true
Dec 03, 2019 11:39:55 PM org.postgresql.core.Encoding <init>
FINEST: Creating new Encoding UTF-8 with fastASCIINumbers true
Dec 03, 2019 11:39:55 PM org.postgresql.core.Encoding <init>
FINEST: Creating new Encoding UTF-8 with fastASCIINumbers true
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.ConnectionFactoryImpl enableSSL
FINEST:  FE=> SSLRequest
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.ConnectionFactoryImpl enableSSL
FINEST:  <=BE SSLRefused
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.ConnectionFactoryImpl tryConnect
FINE: Receive Buffer Size is 65,536
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.ConnectionFactoryImpl tryConnect
FINE: Send Buffer Size is 65,536
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.ConnectionFactoryImpl sendStartupPacket
FINEST:  FE=> StartupPacket(user=postgres, database=demo, client_encoding=UTF8, DateStyle=ISO, TimeZone=Africa/Cairo, extra_float_digits=2)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.ConnectionFactoryImpl doAuthentication
FINEST:  <=BE AuthenticationReqMD5(salt=58ec0452)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.ConnectionFactoryImpl doAuthentication
FINEST:  FE=> Password(md5digest=md58dde4366a6bf1448727e76960777cc80)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.ConnectionFactoryImpl doAuthentication
FINEST:  <=BE AuthenticationOk
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(application_name = )
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(client_encoding = UTF8)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(DateStyle = ISO, MDY)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(integer_datetimes = on)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(IntervalStyle = postgres)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(is_superuser = on)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(server_encoding = UTF8)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(server_version = 9.6.15)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(session_authorization = postgres)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(standard_conforming_strings = on)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(TimeZone = Africa/Cairo)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl readStartupMessages
FINEST:  <=BE BackendKeyData(pid=6,548,ckey=705,344,782)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveRFQ
FINEST:  <=BE ReadyForQuery(I)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl execute
FINEST:   simple execute, handler=org.postgresql.core.SetupQueryRunner$SimpleResultHandler@3581c5f3, maxRows=0, fetchSize=0, flags=1,047
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendParse
FINEST:  FE=> Parse(stmt=null,query="SET extra_float_digits = 3",oids={})
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendBind
FINEST:  FE=> Bind(stmt=null,portal=null)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendExecute
FINEST:  FE=> Execute(portal=null,limit=1)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendSync
FINEST:  FE=> Sync
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl processResults
FINEST:  <=BE ParseComplete [null]
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl processResults
FINEST:  <=BE BindComplete [unnamed]
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveCommandStatus
FINEST:  <=BE CommandStatus(SET)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveRFQ
FINEST:  <=BE ReadyForQuery(I)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl execute
FINEST:   simple execute, handler=org.postgresql.core.SetupQueryRunner$SimpleResultHandler@64a294a6, maxRows=0, fetchSize=0, flags=1,047
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendParse
FINEST:  FE=> Parse(stmt=null,query="SET application_name = 'PostgreSQL JDBC Driver'",oids={})
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendBind
FINEST:  FE=> Bind(stmt=null,portal=null)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendExecute
FINEST:  FE=> Execute(portal=null,limit=1)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendSync
FINEST:  FE=> Sync
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl processResults
FINEST:  <=BE ParseComplete [null]
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl processResults
FINEST:  <=BE BindComplete [unnamed]
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveParameterStatus
FINEST:  <=BE ParameterStatus(application_name = PostgreSQL JDBC Driver)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveCommandStatus
FINEST:  <=BE CommandStatus(SET)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveRFQ
FINEST:  <=BE ReadyForQuery(I)
Dec 03, 2019 11:39:55 PM org.postgresql.jdbc.PgConnection <init>
FINEST:     types using binary send = TIMESTAMPTZ,NUMERIC,UUID,INT2_ARRAY,INT4_ARRAY,BYTEA,TEXT_ARRAY,TIMETZ,INT8,INT2,INT4,VARCHAR_ARRAY,INT8_ARRAY,POINT,TIMESTAMP,TIME,BOX,FLOAT4,FLOAT8,FLOAT4_ARRAY,FLOAT8_ARRAY
Dec 03, 2019 11:39:55 PM org.postgresql.jdbc.PgConnection <init>
FINEST:     types using binary receive = TIMESTAMPTZ,NUMERIC,UUID,INT2_ARRAY,INT4_ARRAY,BYTEA,TEXT_ARRAY,TIMETZ,INT8,INT2,INT4,VARCHAR_ARRAY,INT8_ARRAY,POINT,DATE,TIMESTAMP,TIME,BOX,FLOAT4,FLOAT8,FLOAT4_ARRAY,FLOAT8_ARRAY
Dec 03, 2019 11:39:55 PM org.postgresql.jdbc.PgConnection <init>
FINEST:     integer date/time = true
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl execute
FINEST:   simple execute, handler=org.postgresql.jdbc.PgStatement$StatementResultHandler@7dc5e7b4, maxRows=0, fetchSize=0, flags=48
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendParse
FINEST:  FE=> Parse(stmt=S_1,query="select 4.3",oids={})
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendDescribeStatement
FINEST:  FE=> Describe(statement=S_1)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendSync
FINEST:  FE=> Sync
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl processResults
FINEST:  <=BE ParseComplete [S_1]
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl processResults
FINEST:  <=BE ParameterDescription
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveFields
FINEST:  <=BE RowDescription(1)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveFields
FINEST:         Field(?column?,NUMERIC,65535,T)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveRFQ
FINEST:  <=BE ReadyForQuery(I)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl processResults
FINEST:  FE marking setPortalDescribed(false) for query SYNC
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl execute
FINEST:   simple execute, handler=org.postgresql.jdbc.PgStatement$StatementResultHandler@156643d4, maxRows=0, fetchSize=0, flags=16
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl flushIfDeadlockRisk
FINEST: Couldn't estimate result size or result size unbounded, disabling batching for this query.
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl flushIfDeadlockRisk
FINEST: Forcing Sync, receive buffer full or batching disallowed
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendSync
FINEST:  FE=> Sync
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveRFQ
FINEST:  <=BE ReadyForQuery(I)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendBind
FINEST:  FE=> Bind(stmt=S_1,portal=null)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendExecute
FINEST:  FE=> Execute(portal=null,limit=0)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl sendSync
FINEST:  FE=> Sync
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl processResults
FINEST:  <=BE BindComplete [unnamed]
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl processResults
FINEST:  <=BE DataRow(len=12)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveCommandStatus
FINEST:  <=BE CommandStatus(SELECT 1)
Dec 03, 2019 11:39:55 PM org.postgresql.core.v3.QueryExecutorImpl receiveRFQ
FINEST:  <=BE ReadyForQuery(I)
Dec 03, 2019 11:39:55 PM org.postgresql.jdbc.PgResultSet getObject
FINEST:   getObject columnIndex: 1
Dec 03, 2019 11:39:55 PM org.postgresql.jdbc.PgResultSet getString
FINEST:   getString columnIndex: 1
....

with last 2 line repeated more than 1500 times.

@mahmoudbahaa mahmoudbahaa changed the title StackOverflowError in getObject in array result set StackOverflowError in getObject if the type of column is NUMERIC and the format binary Dec 3, 2019
@mahmoudbahaa
Copy link
Contributor Author

I can see that Oid.NUMERIC does not yet support binary transfer in pgjbc, but shouldn't it force it to text or throw an exception on attempting on setting binary transfer enabled to NUMERIC ?

@mahmoudbahaa
Copy link
Contributor Author

I made 2 PRs:

  1. Only allow binary transfer for those Oids that the pgjdbc currently s… #1637 so as not to allow binary transfer of any oid not supported
  2. Add Binary Support for Oid.NUMERIC and Oid.NUMERIC_ARRAY #1636 for actually implementing binary support of Oid.NUMERIC and Oid.NUMERIC_ARRAY

@davecramer
Copy link
Member

Any chance you can fix those PR's to build under Jdk 6 and 7 and I'll push them ?

@mahmoudbahaa
Copy link
Contributor Author

both PRs are now green

@mahmoudbahaa
Copy link
Contributor Author

closing this as both PRs are now merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants