Author: ggregory
Date: Tue Sep 19 13:20:06 2006
New Revision: 447947
URL: http://svn.apache.org/viewvc?view=rev&rev=447947
Log:
https://issues.apache.org/jira/browse/LANG-279
HashCodeBuilder throws java.lang.StackOverflowError when an object contains a
cycle.
Modified:
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/HashCodeBuilderTest.java
Modified:
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/HashCodeBuilderTest.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/HashCodeBuilderTest.java?view=diff&rev=447947&r1=447946&r2=447947
==============================================================================
---
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/HashCodeBuilderTest.java
(original)
+++
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/HashCodeBuilderTest.java
Tue Sep 19 13:20:06 2006
@@ -16,6 +16,9 @@
*/
package org.apache.commons.lang.builder;
+import
org.apache.commons.lang.builder.ToStringBuilderTest.ReflectionTestCycleA;
+import
org.apache.commons.lang.builder.ToStringBuilderTest.ReflectionTestCycleB;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -29,6 +32,28 @@
*/
public class HashCodeBuilderTest extends TestCase {
+ /**
+ * A reflection test fixture.
+ */
+ static class ReflectionTestCycleA {
+ ReflectionTestCycleB b;
+
+ public int hashCode() {
+ return HashCodeBuilder.reflectionHashCode(this);
+ }
+ }
+
+ /**
+ * A reflection test fixture.
+ */
+ static class ReflectionTestCycleB {
+ ReflectionTestCycleA a;
+
+ public int hashCode() {
+ return HashCodeBuilder.reflectionHashCode(this);
+ }
+ }
+
public HashCodeBuilderTest(String name) {
super(name);
}
@@ -467,4 +492,34 @@
this.three = three;
}
}
+
+ /**
+ * Test Objects pointing to each other.
+ */
+ public void testReflectionObjectCycle() {
+ ReflectionTestCycleA a = new ReflectionTestCycleA();
+ ReflectionTestCycleB b = new ReflectionTestCycleB();
+ a.b = b;
+ b.a = a;
+ // Causes:
+ // java.lang.StackOverflowError
+ // at java.lang.ClassLoader.getCallerClassLoader(Native Method)
+ // at java.lang.Class.getDeclaredFields(Class.java:992)
+ // at
org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:373)
+ // at
org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:349)
+ // at
org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:155)
+ // at
+ //
org.apache.commons.lang.builder.HashCodeBuilderTest$ReflectionTestCycleB.hashCode(HashCodeBuilderTest.java:53)
+ // at
org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:422)
+ // at
org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:383)
+ // at
org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:349)
+ // at
org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:155)
+ // at
+ //
org.apache.commons.lang.builder.HashCodeBuilderTest$ReflectionTestCycleA.hashCode(HashCodeBuilderTest.java:42)
+ // at
org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:422)
+
+ // a.hashCode();
+ // b.hashCode();
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]