LANG-1229: Performance regression due to cyclic hashCode guard

To fix this issues revert the unreleased "LANG-456: HashCodeBuilder throws StackOverflowError in bidirectional navigable".

This reverts commit b5749b4f54.
This commit is contained in:
pascalschumacher 2016-06-08 22:21:41 +02:00
parent 528f6e8e70
commit 9bd439b4e0
3 changed files with 2 additions and 88 deletions

View File

@ -117,7 +117,6 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="LANG-1031" type="add" dev="britter" due-to="Felipe Adorno">Add annotations to exclude fields from ReflectionEqualsBuilder, ReflectionToStringBuilder and ReflectionHashCodeBuilder</action>
<action issue="LANG-1127" type="add" dev="chas, britter">Use JUnit rules to set and reset the default Locale and TimeZone</action>
<action issue="LANG-1128" type="fix" dev="britter" due-to="Jack Tan">JsonToStringStyle doesn't handle chars and objects correctly</action>
<action issue="LANG-456" type="fix" dev="britter" due-to="Bob Fields, Woosan Ko, Bruno P. Kinoshita">HashCodeBuilder throws StackOverflowError in bidirectional navigable association</action>
<action issue="LANG-1126" type="fix" dev="britter">DateFormatUtilsTest.testSMTP depends on the default Locale</action>
<action issue="LANG-1123" type="fix" dev="chas" due-to="Christian P. Momon">Unit test FastDatePrinterTimeZonesTest needs a timezone set</action>
<action issue="LANG-916" type="fix" dev="chas" due-to="Christian P. Momon">CLONE - DateFormatUtils.format does not correctly change Calendar TimeZone in certain situations</action>

View File

@ -871,35 +871,7 @@ public HashCodeBuilder append(final Object object) {
append((Object[]) object);
}
} else {
if (object instanceof Long) {
append(((Long) object).longValue());
} else if (object instanceof Integer) {
append(((Integer) object).intValue());
} else if (object instanceof Short) {
append(((Short) object).shortValue());
} else if (object instanceof Character) {
append(((Character) object).charValue());
} else if (object instanceof Byte) {
append(((Byte) object).byteValue());
} else if (object instanceof Double) {
append(((Double) object).doubleValue());
} else if (object instanceof Float) {
append(((Float) object).floatValue());
} else if (object instanceof Boolean) {
append(((Boolean) object).booleanValue());
} else if (object instanceof String) {
iTotal = iTotal * iConstant + object.hashCode();
} else {
if (isRegistered(object)) {
return this;
}
try {
register(object);
iTotal = iTotal * iConstant + object.hashCode();
} finally {
unregister(object);
}
}
}
}
return this;

View File

@ -19,7 +19,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
/**
@ -31,8 +30,6 @@ public class HashCodeBuilderTest {
* A reflection test fixture.
*/
static class ReflectionTestCycleA {
int index = 10;
String name = "ReflectionTestCycleA";
ReflectionTestCycleB b;
@Override
@ -45,8 +42,6 @@ public int hashCode() {
* A reflection test fixture.
*/
static class ReflectionTestCycleB {
int index = 11;
String name = "ReflectionTestCycleB";
ReflectionTestCycleA a;
@Override
@ -55,42 +50,6 @@ public int hashCode() {
}
}
/**
* A nonreflection test fixture.
*/
static class NonreflectionTestCycleA {
int index = 20;
String name = "NonreflectionTestCycleA";
NonreflectionTestCycleB b;
@Override
public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder();
builder.append(index);
builder.append(name);
builder.append(b);
return builder.toHashCode();
}
}
/**
* A nonreflection test fixture.
*/
static class NonreflectionTestCycleB {
int index = 21;
String name = "NonreflectionTestCycleB";
NonreflectionTestCycleA a;
@Override
public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder();
builder.append(index);
builder.append(name);
builder.append(a);
return builder.toHashCode();
}
}
// -----------------------------------------------------------------------
@Test(expected=IllegalArgumentException.class)
@ -562,7 +521,7 @@ public TestObjectWithMultipleFields(final int one, final int two, final int thre
}
/**
* Test Objects pointing to each other when {@link HashCodeBuilder#reflectionHashCode(Object, String...)} used.
* Test Objects pointing to each other.
*/
@Test
public void testReflectionObjectCycle() {
@ -594,22 +553,6 @@ public void testReflectionObjectCycle() {
assertNull(HashCodeBuilder.getRegistry());
}
/**
* Test Objects pointing to each other when <code>append()</code> methods are used on <code>HashCodeBuilder</code> instance.
*/
@Test
public void testNonreflectionObjectCycle() {
final NonreflectionTestCycleA a = new NonreflectionTestCycleA();
final NonreflectionTestCycleB b = new NonreflectionTestCycleB();
a.b = b;
b.a = a;
a.hashCode();
assertNull(HashCodeBuilder.getRegistry());
b.hashCode();
assertNull(HashCodeBuilder.getRegistry());
}
/**
* Ensures LANG-520 remains true
*/