From 50e9337e8dba5f992666450a1eeed71b5f40e31a Mon Sep 17 00:00:00 2001 From: ManuelCalvo3Pillar <102541613+ManuelCalvo3Pillar@users.noreply.github.com> Date: Thu, 2 Mar 2023 16:28:15 -0600 Subject: [PATCH] Fixing issue when trying to deserialize a Blob object. RAD-2620 --- SQL console/RELEASE-NOTES | 3 +++ .../com/serotonin/m2m2/db/dao/SqlConsole.java | 24 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/SQL console/RELEASE-NOTES b/SQL console/RELEASE-NOTES index 389be3af7..c953fb0fb 100644 --- a/SQL console/RELEASE-NOTES +++ b/SQL console/RELEASE-NOTES @@ -1,3 +1,6 @@ +*Version 4.5.1* +* Fixing issue when trying to deserialize a Blob object. + *Version 4.5.0* * Upgraded for Mango 4.5.0 diff --git a/SQL console/src/com/serotonin/m2m2/db/dao/SqlConsole.java b/SQL console/src/com/serotonin/m2m2/db/dao/SqlConsole.java index d901b8586..542011728 100644 --- a/SQL console/src/com/serotonin/m2m2/db/dao/SqlConsole.java +++ b/SQL console/src/com/serotonin/m2m2/db/dao/SqlConsole.java @@ -7,6 +7,7 @@ import java.sql.Blob; import java.sql.ResultSet; import java.sql.ResultSetMetaData; +import java.sql.SQLException; import java.sql.Types; import java.util.ArrayList; import java.util.LinkedList; @@ -17,6 +18,7 @@ import org.springframework.stereotype.Component; import com.infiniteautomation.mango.rest.latest.SqlQueryResult; +import com.serotonin.ShouldNeverHappenException; import com.serotonin.db.spring.ExtendedJdbcTemplate; import com.serotonin.util.SerializationHelper; @@ -50,12 +52,7 @@ public SqlQueryResult query(String sqlString, String serializedDataMsg) { row.add(rs.getString(i + 1)); else if (meta.getColumnType(i + 1) == Types.LONGVARBINARY || meta.getColumnType(i + 1) == Types.BLOB) { - Blob blob = rs.getBlob(i + 1); - Object o; - if (blob == null) - o = null; - else - o = SerializationHelper.readObjectInContext(blob.getBinaryStream()); + Object o = readObjectFromBlob(rs.getBlob(i + 1)); row.add(serializedDataMsg + "(" + o + ")"); } else row.add(rs.getObject(i + 1)); @@ -68,4 +65,19 @@ else if (meta.getColumnType(i + 1) == Types.LONGVARBINARY return result; }); } + + private static Object readObjectFromBlob(Blob blob) throws SQLException { + Object o; + + if (blob == null) { + o = null; + } else { + try { + o = SerializationHelper.readObjectInContext(blob.getBinaryStream()); + } catch (ShouldNeverHappenException e) { + o = "BLOB"; + } + } + return o; + } }