Message-ID: From: "sly461 (@sly461)" To: "pgjdbc/pgjdbc" Date: Mon, 28 Jul 2025 13:30:03 +0000 Subject: [pgjdbc/pgjdbc] issue #3743: Retrieving the result set from the multi-dimensional array will get an error in binary mode. List-Id: X-GitHub-Author-Id: 32794108 X-GitHub-Author-Login: sly461 X-GitHub-Issue: 3743 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: closed X-GitHub-Type: issue X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3743 Content-Type: text/plain; charset=utf-8 Please read https://stackoverflow.com/help/minimal-reproducible-example **Describe the issue** I'm trying to use a three-dimensional array. However, I found that I can retrieve the result set normally in regular mode, but an error occurs **in binary mode**. **Driver Version?** 42.7.7 **Java Version?** java 21 **OS Version?** Windows 10 **PostgreSQL Version?** PostgreSQL 14.18 **To Reproduce** Steps to reproduce the behaviour: ``` import java.sql.*; import java.util.Properties; public class TestMultiDimensionalArrayRetrieveResultSets { public static void main(String []args) throws Exception { String url = "jdbc:postgresql://localhost:5432/test"; Properties props = new Properties(); props.setProperty("user", "test"); props.setProperty("password", "test"); // forceBinary props.setProperty("prepareThreshold", "-1"); Connection conn = DriverManager.getConnection(url, props); Statement stmt = conn.createStatement(); stmt.execute("DROP TABLE IF EXISTS TestArray"); stmt.execute("CREATE TABLE TestArray(intarr int[])"); stmt.execute("INSERT INTO TestArray VALUES ('{{{0},{1}},{{2},{3}},{{4},{5}}}')"); ResultSet rs = stmt.executeQuery("SELECT intarr FROM TestArray"); rs.next(); // {{{0},{1}},{{2},{3}},{{4},{5}}} Array arr = rs.getArray(1); ResultSet arrrs = arr.getResultSet(); arrrs.next(); // {{0},{1}} Array arr1 = arrrs.getArray(2); ResultSet arr1rs = arr1.getResultSet(); arr1rs.next(); // {0} Array arr11 = arr1rs.getArray(2); ResultSet arr11rs = arr11.getResultSet(); arr11rs.next(); System.out.println(arr11rs.getInt(2)); arr11rs.next(); arr11rs.close(); arr1rs.next(); // {1} Array arr12 = arr1rs.getArray(2); ResultSet arr12rs = arr12.getResultSet(); arr12rs.next(); System.out.println(arr12rs.getInt(2)); arr12rs.next(); arr12rs.close(); arr1rs.next(); arr1rs.close(); } } ``` **Expected behaviour** I expected to be able to retrieve the values in a three-dimensional array, but it actually got an error **in binary mode**: ``` Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: arraycopy: last source index 33554459 out of bounds for byte[84] at java.base/java.lang.System.arraycopy(Native Method) at org.postgresql.jdbc.PgArray.storeValues(PgArray.java:275) at org.postgresql.jdbc.PgArray.readBinaryResultSet(PgArray.java:205) at org.postgresql.jdbc.PgArray.getResultSetImpl(PgArray.java:374) at org.postgresql.jdbc.PgArray.getResultSet(PgArray.java:336) at org.postgresql.test.TestMultiDimensionalArrayRetrieveResultSets.main(TestMultiDimensionalArrayRetrieveResultSets.java:25) ```