@@ -206,6 +206,41 @@ public static TestClassMap getInstance() {
206206 }
207207}
208208
209+ class TestClassFinalField implements Serializable {
210+ public final int i1 ;
211+ public final Integer i2 ;
212+
213+ //Compile-time constant
214+ public final String str = "abc" ;
215+
216+ public TestClassFinalField () {
217+ i1 = 99 ;
218+ i2 = 3 ;
219+ }
220+
221+ public TestClassFinalField (int i1 , Integer i2 ) {
222+ this .i1 = i1 ;
223+ this .i2 = i2 ;
224+ }
225+
226+ @ Override
227+ public boolean equals (Object obj ) {
228+ if (obj == null ) {
229+ return false ;
230+ }
231+ if (!this .getClass ().equals (obj .getClass ())) {
232+ return false ;
233+ }
234+ TestClassFinalField other = (TestClassFinalField )obj ;
235+ return (this .i1 == other .i1 ) && this .i2 .equals (other .i2 ) && this .str .equals (other .str );
236+ }
237+
238+ @ Override
239+ public int hashCode () {
240+ return Integer .hashCode (i1 ) + this .i2 .hashCode () + str .hashCode ();
241+ }
242+ }
243+
209244public class SerDesTest {
210245
211246 private SerDes writer ;
@@ -218,7 +253,8 @@ private SerDes makeSerDes() throws NoSuchMethodException, SecurityException {
218253 TestClassComposed .class ,
219254 TestClassBoxedPrimitive .class ,
220255 TestClassListAndSet .class ,
221- TestClassMap .class ));
256+ TestClassMap .class ,
257+ TestClassFinalField .class ));
222258 }
223259
224260 @ Before
@@ -319,14 +355,31 @@ public void testNull() throws Exception {
319355 testWith (null );
320356 }
321357
358+ /**
359+ * Tests serialization of final fields.
360+ *
361+ * @throws Exception
362+ */
363+ @ Test
364+ public void testFinalFields () throws Exception {
365+ String whatItShouldBe = new TestClassFinalField ().str ;
366+
367+ TestClassFinalField obj = (TestClassFinalField )testWith (new TestClassFinalField ());
368+ assertTrue (obj .str .equals (whatItShouldBe ));
369+
370+ obj = (TestClassFinalField )testWith (new TestClassFinalField (5 , 87 ));
371+ assertTrue (obj .str .equals (whatItShouldBe ));
372+ }
373+
322374
323- private void testWith (Object obj ) throws Exception {
375+ private Object testWith (Object obj ) throws Exception {
324376 Object result = this .serializeAndDeserialize (obj , writer , reader );
325377 if (obj != null ) {
326378 assertTrue (obj .equals (result ));
327379 } else {
328380 assertTrue (result == null );
329381 }
382+ return result ;
330383 }
331384
332385 private Object serializeAndDeserialize (Object obj , SerDes writer , SerDes reader ) throws Exception {
0 commit comments