fix(serialization): Remove legacy BinaryFormatter support
SonarQube Analysis / sonarqube (pull_request) Successful in 4m42s

The `[Serializable]` attribute and corresponding `[OnDeserialized]` methods have been removed from various breakdown classes. This eliminates reliance on `BinaryFormatter`, which is a deprecated and insecure serialization mechanism in modern .NET.

This change also resolves SonarQube rule S5766 warnings by removing the context in which they apply, leading to cleaner and more secure code.
This commit is contained in:
Thom Lamb
2026-05-20 17:44:21 -05:00
parent 3de3b8bf68
commit 2d9148547f
20 changed files with 0 additions and 201 deletions
@@ -1,5 +1,4 @@
using System.Collections;
using System.Runtime.Serialization;
using Strata.SqlTools.SqlBreakdown.Expressions;
using Strata.SqlTools.SqlBreakdown.Interfaces.Core;
using CommandVisitor = Strata.SqlTools.Visitors.PostgreSql.CommandVisitor;
@@ -15,7 +14,6 @@ namespace Strata.SqlTools.Breakdowns.PostgreSql;
/// Represents a PostgreSQL query breakdown with all clauses, following PostgreSQL SQL standards.
/// Handles positional parameters using $1, $2, ... syntax for parameterized queries.
/// </summary>
[Serializable]
public class QueryBreakdown : SqlServerQueryBreakdown
{
private const string ExpressionNullErrorMessage = "Expression cannot be null.";
@@ -89,14 +87,6 @@ public class QueryBreakdown : SqlServerQueryBreakdown
}
}
/// <summary>
/// Re-establishes invariants after deserialization, since deserialization bypasses the
/// constructors that normally initialize the breakdown's clause state (SonarQube rule S5766).
/// </summary>
/// <param name="context">The streaming context for the deserialization operation.</param>
[OnDeserialized]
private void OnDeserialized(StreamingContext context) => RevalidateBreakdownState();
/// <summary>
/// Adds a parameter to the query using PostgreSQL's positional parameter format ($1, $2, ...).
/// </summary>
@@ -1,4 +1,3 @@
using System.Runtime.Serialization;
using System.Text;
using Strata.SqlTools.SqlBreakdown.Classes;
using Strata.SqlTools.SqlBreakdown.Interfaces;
@@ -13,7 +12,6 @@ namespace Strata.SqlTools.Breakdowns.PostgreSql;
/// including support for PostgreSQL features like schema-qualified identifiers,
/// LIMIT/OFFSET clauses, parameterized queries using $1, $2 syntax, and CTEs.
/// </remarks>
[Serializable]
public class QueryBreakdownCollection : SqlBreakdownCollection
{
private readonly List<QueryBreakdown> _queryBreakdowns;
@@ -36,20 +34,6 @@ public class QueryBreakdownCollection : SqlBreakdownCollection
_queryBreakdowns = queryBreakdowns?.ToList() ?? new List<QueryBreakdown>();
}
/// <summary>
/// Validates that the backing list survived deserialization, since deserialization bypasses
/// the constructors that normally initialize it (SonarQube rule S5766).
/// </summary>
/// <param name="context">The streaming context for the deserialization operation.</param>
[OnDeserialized]
private void OnDeserialized(StreamingContext context)
{
if (_queryBreakdowns is null)
{
throw new SerializationException("Deserialized QueryBreakdownCollection is missing its backing list.");
}
}
/// <summary>
/// Gets the collection of QueryBreakdown objects.
/// </summary>