From 828012dbd4652ce69e2e04cea519b6c14bcf5de4 Mon Sep 17 00:00:00 2001 From: aiwenmo <32723967+aiwenmo@users.noreply.github.com> Date: Sun, 15 Jan 2023 20:19:13 +0800 Subject: [PATCH] [Fix-1563] [metadata-mysql] NPE caused by querying data (#1564) Co-authored-by: wenmo <32723967+wenmo@users.noreply.github.com> --- .../java/com/dlink/metadata/convert/MySqlTypeConvert.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dlink-metadata/dlink-metadata-mysql/src/main/java/com/dlink/metadata/convert/MySqlTypeConvert.java b/dlink-metadata/dlink-metadata-mysql/src/main/java/com/dlink/metadata/convert/MySqlTypeConvert.java index 2020d88381..2b3ef3ec4d 100644 --- a/dlink-metadata/dlink-metadata-mysql/src/main/java/com/dlink/metadata/convert/MySqlTypeConvert.java +++ b/dlink-metadata/dlink-metadata-mysql/src/main/java/com/dlink/metadata/convert/MySqlTypeConvert.java @@ -37,7 +37,8 @@ public ColumnType convert(Column column) { if (Asserts.isNull(column)) { return columnType; } - String t = column.getType().toLowerCase(); + Integer length = Asserts.isNull(column.getLength()) ? 0 : column.getLength(); + String t = Asserts.isNull(column.getType()) ? "" : column.getType().toLowerCase(); boolean isNullable = !column.isKeyFlag() && column.isNullable(); if (t.contains("numeric") || t.contains("decimal")) { columnType = ColumnType.DECIMAL; @@ -59,7 +60,7 @@ public ColumnType convert(Column column) { } else { columnType = ColumnType.DOUBLE; } - } else if (t.contains("boolean") || (t.contains("tinyint") && column.getLength() == 1) || t.contains("bit")) { + } else if (t.contains("boolean") || (t.contains("tinyint") && length.equals(1)) || t.contains("bit")) { if (isNullable) { columnType = ColumnType.JAVA_LANG_BOOLEAN; } else {