From 5880b80d433a8a7a6209711280822cb09f812559 Mon Sep 17 00:00:00 2001 From: Dave Cramer Date: Mon, 11 Oct 2021 08:04:04 -0400 Subject: [PATCH] fix: NPE calling getTypeInfo when alias is null, this is the same as PR #2220 in release/42.2 --- .../src/main/java/org/postgresql/core/TypeInfo.java | 2 +- .../main/java/org/postgresql/jdbc/TypeInfoCache.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pgjdbc/src/main/java/org/postgresql/core/TypeInfo.java b/pgjdbc/src/main/java/org/postgresql/core/TypeInfo.java index 0fa3ba8eda..9e77632a3a 100644 --- a/pgjdbc/src/main/java/org/postgresql/core/TypeInfo.java +++ b/pgjdbc/src/main/java/org/postgresql/core/TypeInfo.java @@ -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); diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java b/pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java index 4e902038c3..c96f945818 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java @@ -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; @@ -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 + "[]"); } @@ -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;