Skip to content

Commit

Permalink
fix: NPE calling getTypeInfo when alias is null, this is the same as PR
Browse files Browse the repository at this point in the history
pgjdbc#2220 in release/42.2
  • Loading branch information
davecramer committed Oct 11, 2021
1 parent aa4b49b commit 5880b80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pgjdbc/src/main/java/org/postgresql/core/TypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String javaCla

String getJavaClass(int oid) throws SQLException;

String getTypeForAlias(String alias);
@Nullable String getTypeForAlias(String alias);

int getPrecision(int oid, int typmod);

Expand Down
12 changes: 10 additions & 2 deletions pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ private PreparedStatement getOidStatement(String pgTypeName) throws SQLException
}

public synchronized int getPGType(String pgTypeName) throws SQLException {
// there really isn't anything else to return other than UNSPECIFIED here.
if ( pgTypeName == null ) {
return Oid.UNSPECIFIED;
}

Integer oid = pgNameToOid.get(pgTypeName);
if (oid != null) {
return oid;
Expand Down Expand Up @@ -544,7 +549,7 @@ private PreparedStatement prepareGetNameStatement() throws SQLException {
return getNameStatement;
}

public int getPGArrayType(String elementTypeName) throws SQLException {
public int getPGArrayType(@Nullable String elementTypeName) throws SQLException {
elementTypeName = getTypeForAlias(elementTypeName);
return getPGType(elementTypeName + "[]");
}
Expand Down Expand Up @@ -696,7 +701,10 @@ public synchronized String getJavaClass(int oid) throws SQLException {
return result == null ? "java.lang.String" : result;
}

public String getTypeForAlias(String alias) {
public @Nullable String getTypeForAlias(@Nullable String alias) {
if ( alias == null ) {
return null;
}
String type = TYPE_ALIASES.get(alias);
if (type != null) {
return type;
Expand Down

0 comments on commit 5880b80

Please sign in to comment.