Skip to content
Permalink
Browse files

fix: avoid NPE in new PgArray(, null).toString()

closes #526, closes #524
  • Loading branch information
goeland86 authored and vlsi committed Mar 2, 2016
1 parent e6b5bb3 commit 74b497248d0fdc3e6db32b2628256f88738c2f74
@@ -171,6 +171,10 @@ public Object getArrayImpl(long index, int count, Map<String, Class<?>> map) thr
return readBinaryArray((int) index, count);
}

if (fieldString == null) {
return null;
}

buildArrayList();

if (count == 0) {
@@ -881,7 +885,7 @@ public ResultSet getResultSetImpl(long index, int count, Map<String, Class<?>> m
}

public String toString() {
if (fieldString == null) {
if (fieldString == null && fieldBytes != null) {
try {
Object array = readBinaryArray(1,0);
java.sql.Array tmpArray = connection.createArrayOf(getBaseTypeName(), (Object[]) array);
@@ -8,8 +8,10 @@

package org.postgresql.test.jdbc2;

import org.postgresql.core.BaseConnection;
import org.postgresql.geometric.PGbox;
import org.postgresql.geometric.PGpoint;
import org.postgresql.jdbc.PgArray;
import org.postgresql.test.TestUtil;

import org.junit.Assert;
@@ -267,6 +269,12 @@ public void testNullValues() throws SQLException {
Assert.assertEquals(3, i[2].intValue());
}

@Test
public void testNullFieldString() throws SQLException {
Array arr = new PgArray((BaseConnection) conn, 1, (String) null);
Assert.assertNull(arr.toString());
}

@Test
public void testUnknownArrayType() throws SQLException {
Statement stmt = conn.createStatement();

0 comments on commit 74b4972

Please sign in to comment.
You can’t perform that action at this time.