From 2714ba90caf09ce475de68cb85313460a8e83831 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Fri, 22 Apr 2011 23:03:26 +0000 Subject: [PATCH] LUCENE-3042: Add a more specific test that can be backported to 3.x and prev git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1096077 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/util/TestAttributeSource.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lucene/src/test/org/apache/lucene/util/TestAttributeSource.java b/lucene/src/test/org/apache/lucene/util/TestAttributeSource.java index bf1c0d1934d..3d464a03572 100644 --- a/lucene/src/test/org/apache/lucene/util/TestAttributeSource.java +++ b/lucene/src/test/org/apache/lucene/util/TestAttributeSource.java @@ -147,4 +147,14 @@ public class TestAttributeSource extends LuceneTestCase { fail("Should throw IllegalArgumentException"); } catch (IllegalArgumentException iae) {} } + + public void testLUCENE_3042() throws Exception { + final AttributeSource src1 = new AttributeSource(); + src1.addAttribute(CharTermAttribute.class).append("foo"); + int hash1 = src1.hashCode(); // this triggers a cached state + final AttributeSource src2 = new AttributeSource(src1); + src2.addAttribute(TypeAttribute.class).setType("bar"); + assertTrue("The hashCode is identical, so the captured state was preserved.", hash1 != src1.hashCode()); + assertEquals(src2.hashCode(), src1.hashCode()); + } }