This is an automated email from the ASF dual-hosted git repository. struberg pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/openjpa.git
commit 9c9138603dbd2bb32fd3931e98bba0d015ba01b6 Author: Mark Struberg <[email protected]> AuthorDate: Mon Mar 29 14:20:11 2021 +0200 OPENJPA-2814 fix mem leak in ForeignKey detected by Gregory Jevardat, thanks! --- .../org/apache/openjpa/jdbc/schema/Constraint.java | 28 ++++++++++ .../org/apache/openjpa/jdbc/schema/ForeignKey.java | 60 ++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java index f1c7009..f7f9fdb 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java @@ -249,4 +249,32 @@ public abstract class Constraint extends ReferenceCounter { name = name.substring(name.lastIndexOf('.') + 1); return "<" + name.toLowerCase() + ">"; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Constraint that = (Constraint) o; + + if (_deferred != that._deferred) return false; + if (_name != null ? !_name.equals(that._name) : that._name != null) return false; + if (_fullPath != null ? !_fullPath.equals(that._fullPath) : that._fullPath != null) return false; + if (_table != null ? !_table.equals(that._table) : that._table != null) return false; + if (_tableName != null ? !_tableName.equals(that._tableName) : that._tableName != null) return false; + if (_schemaName != null ? !_schemaName.equals(that._schemaName) : that._schemaName != null) return false; + return _columnName != null ? _columnName.equals(that._columnName) : that._columnName == null; + } + + @Override + public int hashCode() { + int result = _name != null ? _name.hashCode() : 0; + result = 31 * result + (_fullPath != null ? _fullPath.hashCode() : 0); + result = 31 * result + (_table != null ? _table.hashCode() : 0); + result = 31 * result + (_tableName != null ? _tableName.hashCode() : 0); + result = 31 * result + (_schemaName != null ? _schemaName.hashCode() : 0); + result = 31 * result + (_columnName != null ? _columnName.hashCode() : 0); + result = 31 * result + (_deferred ? 1 : 0); + return result; + } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java index 376a235..4cd8851 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java @@ -913,6 +913,66 @@ public class ForeignKey extends Constraint { return new Column[] { fkCol, pkCol }; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + ForeignKey that = (ForeignKey) o; + + if (_seq != that._seq) return false; + if (_delAction != that._delAction) return false; + if (_upAction != that._upAction) return false; + if (_index != that._index) return false; + if (_pkTableName != null ? !_pkTableName.equals(that._pkTableName) : that._pkTableName != null) return false; + if (_pkSchemaName != null ? !_pkSchemaName.equals(that._pkSchemaName) : that._pkSchemaName != null) return false; + if (_pkColumnName != null ? !_pkColumnName.equals(that._pkColumnName) : that._pkColumnName != null) return false; + if (_joins != null ? !_joins.equals(that._joins) : that._joins != null) return false; + if (_joinsPK != null ? !_joinsPK.equals(that._joinsPK) : that._joinsPK != null) return false; + if (_consts != null ? !_consts.equals(that._consts) : that._consts != null) return false; + if (_constsPK != null ? !_constsPK.equals(that._constsPK) : that._constsPK != null) return false; + // Probably incorrect - comparing Object[] arrays with Arrays.equals + if (!Arrays.equals(_locals, that._locals)) return false; + // Probably incorrect - comparing Object[] arrays with Arrays.equals + if (!Arrays.equals(_pks, that._pks)) return false; + // Probably incorrect - comparing Object[] arrays with Arrays.equals + if (!Arrays.equals(_constVals, that._constVals)) return false; + // Probably incorrect - comparing Object[] arrays with Arrays.equals + if (!Arrays.equals(_constCols, that._constCols)) return false; + // Probably incorrect - comparing Object[] arrays with Arrays.equals + if (!Arrays.equals(_constValsPK, that._constValsPK)) return false; + // Probably incorrect - comparing Object[] arrays with Arrays.equals + if (!Arrays.equals(_constColsPK, that._constColsPK)) return false; + if (_pkTable != null ? !_pkTable.equals(that._pkTable) : that._pkTable != null) return false; + return _autoAssign != null ? _autoAssign.equals(that._autoAssign) : that._autoAssign == null; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (_pkTableName != null ? _pkTableName.hashCode() : 0); + result = 31 * result + (_pkSchemaName != null ? _pkSchemaName.hashCode() : 0); + result = 31 * result + (_pkColumnName != null ? _pkColumnName.hashCode() : 0); + result = 31 * result + _seq; + result = 31 * result + (_joins != null ? _joins.hashCode() : 0); + result = 31 * result + (_joinsPK != null ? _joinsPK.hashCode() : 0); + result = 31 * result + (_consts != null ? _consts.hashCode() : 0); + result = 31 * result + (_constsPK != null ? _constsPK.hashCode() : 0); + result = 31 * result + _delAction; + result = 31 * result + _upAction; + result = 31 * result + _index; + result = 31 * result + Arrays.hashCode(_locals); + result = 31 * result + Arrays.hashCode(_pks); + result = 31 * result + Arrays.hashCode(_constVals); + result = 31 * result + Arrays.hashCode(_constCols); + result = 31 * result + Arrays.hashCode(_constValsPK); + result = 31 * result + Arrays.hashCode(_constColsPK); + result = 31 * result + (_pkTable != null ? _pkTable.hashCode() : 0); + result = 31 * result + (_autoAssign != null ? _autoAssign.hashCode() : 0); + return result; + } + /* * ForeignKey utility class which determines equality based upon the * non-column state of the keys.
