Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: null pointer exception from PgResultSetMetaData when there's no …
…column metadata (#1615) * fix all possible NPE in PgResultSetMetaData when there's column metadata
- Loading branch information
1 parent
ec76bac
commit 08bd46b
Showing
2 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
pgjdbc/src/test/java/org/postgresql/jdbc/NoColumnMetadataIssue1613.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2019, PostgreSQL Global Development Group | ||
* See the LICENSE file in the project root for more information. | ||
*/ | ||
|
||
package org.postgresql.jdbc; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.postgresql.test.TestUtil; | ||
import org.postgresql.test.jdbc2.BaseTest4; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.Statement; | ||
|
||
/** | ||
* If the SQL query has no column metadata, the driver shouldn't break by a null pointer exception. | ||
* It should return the result correctly. | ||
* | ||
* @author Ivy (ivyyiyideng@gmail.com) | ||
* | ||
*/ | ||
public class NoColumnMetadataIssue1613 extends BaseTest4 { | ||
@Override | ||
@Before | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
TestUtil.createTempTable(con, "test_no_column_metadata","id int"); | ||
} | ||
|
||
@Test | ||
public void shouldBeNoNPE() throws Exception { | ||
Statement statement = con.createStatement(); | ||
statement.executeQuery("INSERT INTO test_no_column_metadata values (1)"); | ||
ResultSet rs = statement.executeQuery("SELECT x FROM test_no_column_metadata x"); | ||
assertTrue(rs.next()); | ||
} | ||
} |