Skip to content

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 #2928

@IvanPizhenko

Description

@IvanPizhenko

Please read https://stackoverflow.com/help/minimal-reproducible-example

Describe the issue
A clear and concise description of what the issue is.

Driver Version?
42.6.0

Java Version?
17

OS Version?
Ubuntu 22.04 LTS

PostgreSQL Version?
PostgreSQL 14.8 (Ubuntu 14.8-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0, 64-bit

To Reproduce
Steps to reproduce the behaviour:

Provide less port numbers than host names (in my case, it was 2 host name and 1 port number), when creating data source (in my case, PGSimpleDataSource was created by Hikari pool).

Expected behaviour
Likely you need to make sure that if port numbers are ever provided, number of port numbers matches to number of hosts.

What actually happens

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
	at org.postgresql.ds.common.BaseDataSource.getUrl(BaseDataSource.java:1340)
	at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:103)
	at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:87)
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359)
...

This happens in the following code inside BaseDataSource.getUrl():

      if (portNumbers != null && portNumbers.length >= i && portNumbers[i] != 0) {
        url.append(":").append(portNumbers[i]);
      }

portNumbers.length >= i and then portNumbers[i] is incorrect, it should be portNumbers.length > i (strictly greater than i).

Logs
See stacktrace above.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions