[jOOQ/jOOQ#13392] Generated column name for binary bind values shouldn't

use Java's byte[].toString()
This commit is contained in:
Lukas Eder 2022-04-04 12:44:02 +02:00
parent 5ceedce7e7
commit 04bd61869c
2 changed files with 21 additions and 3 deletions

View File

@ -97,7 +97,7 @@ abstract class AbstractParam<T> extends AbstractParamX<T> implements SimpleQuery
* <li>Otherwise, take the string value of <code>value</code></li>
* </ul>
*/
static Name name(Object value, String paramName) {
static final Name name(Object value, String paramName) {
return DSL.name(
paramName != null
? paramName
@ -112,10 +112,21 @@ abstract class AbstractParam<T> extends AbstractParamX<T> implements SimpleQuery
: String.valueOf(value)
: name(value)
);
}
private final static String name(Object value) {
// [#13392] The generated name of a byte[] value shouldn't depend on the
// identity of the value, but on the value itself
if (value instanceof byte[]) { byte[] b = (byte[]) value;
return "b_" + Internal.hash0(Arrays.hashCode(Arrays.copyOf(b, 16)));
}
else
return String.valueOf(value);
}
// ------------------------------------------------------------------------
// XXX: QueryPart API
// ------------------------------------------------------------------------

View File

@ -615,10 +615,17 @@ public final class Internal {
* account FindBugs' <code>RV_ABSOLUTE_VALUE_OF_HASHCODE</code> pattern
*/
public static final int hash(QueryPart part) {
return hash0(CTX.render(part));
}
static final int hash0(Object object) {
if (object == null)
return 0;
// [#6025] Prevent unstable alias generation for derived tables due to
// inlined bind variables in hashCode() calculation
// [#6175] TODO: Speed this up with a faster way to calculate a hash code
return 0x7FFFFFF & CTX.render(part).hashCode();
else
return 0x7FFFFFF & object.hashCode();
}
}