[#1015] FindBugs: 7 occurrences of "Bad attempt to compute absolute value of signed 32-bit hashcode"

This commit is contained in:
Lukas Eder 2011-12-23 14:42:04 +00:00
parent 0061e7e346
commit 0251dcff1f
4 changed files with 15 additions and 7 deletions

View File

@ -123,7 +123,7 @@ abstract class AbstractSelect<R extends Record> extends AbstractResultQuery<R> i
public final Table<R> asTable() {
// Its usually better to alias nested selects that are used in
// the FROM clause of a query
return new SelectQueryAsTable<R>(this).as("alias_" + Math.abs(hashCode()));
return new SelectQueryAsTable<R>(this).as("alias_" + Util.hash(this));
}
@Override

View File

@ -305,8 +305,8 @@ implements
toSQLReference0(local);
String enclosed = local.render();
String subqueryName = "limit_" + Math.abs(enclosed.hashCode());
String rownumName = "rownum_" + Math.abs(enclosed.hashCode());
String subqueryName = "limit_" + Util.hash(enclosed);
String rownumName = "rownum_" + Util.hash(enclosed);
context.sql("select * from (select ")
.sql(subqueryName)
@ -368,8 +368,8 @@ implements
toSQLReference0(local);
String enclosed = local.render();
String subqueryName = "limit_" + Math.abs(enclosed.hashCode());
String rownumName = "rownum_" + Math.abs(enclosed.hashCode());
String subqueryName = "limit_" + Util.hash(enclosed);
String rownumName = "rownum_" + Util.hash(enclosed);
context.sql("select * from (select ")
.sql(subqueryName)

View File

@ -322,7 +322,7 @@ implements
case SQLSERVER:
case SYBASE: {
if (using instanceof Select) {
int hash = Math.abs(using.hashCode());
int hash = Util.hash(using);
context.sql(" as ")
.sql("dummy_")
@ -335,7 +335,7 @@ implements
// Some fields are unnamed
// [#579] Correct this
String name = StringUtils.isBlank(field.getName())
? "dummy_" + hash + "_" + Math.abs(field.hashCode())
? "dummy_" + hash + "_" + Util.hash(field)
: field.getName();
context.sql(separator).literal(name);

View File

@ -628,4 +628,12 @@ final class Util {
static QueryPartInternal internal(QueryPart part) {
return part.internalAPI(QueryPartInternal.class);
}
/**
* Return a non-negative hash code for a {@link QueryPart}, taking into
* account FindBugs' <code>RV_ABSOLUTE_VALUE_OF_HASHCODE</code> pattern
*/
static int hash(Object object) {
return 0x7FFFFFF & object.hashCode();
}
}