31
31
import java .util .List ;
32
32
import java .util .Objects ;
33
33
34
+ import com .esotericsoftware .kryo .WarnUnregisteredClassesTest ;
35
+ import com .esotericsoftware .minlog .Log ;
34
36
import org .apache .commons .lang .builder .EqualsBuilder ;
37
+ import org .junit .Before ;
35
38
import org .junit .Rule ;
36
39
import org .junit .Test ;
37
40
import org .junit .rules .ExpectedException ;
@@ -42,6 +45,16 @@ public class CompatibleFieldSerializerTest extends KryoTestCase {
42
45
supportsCopy = true ;
43
46
}
44
47
48
+ WarnUnregisteredClassesTest .LoggerStub log ;
49
+
50
+ @ Before
51
+ public void setUp () throws Exception {
52
+ log = new WarnUnregisteredClassesTest .LoggerStub ();
53
+ Log .setLogger (log );
54
+ Log .INFO ();
55
+ kryo = new Kryo ();
56
+ }
57
+
45
58
@ Rule public ExpectedException exceptionRule = ExpectedException .none ();
46
59
47
60
@ Test
@@ -642,4 +655,45 @@ public int hashCode () {
642
655
return Objects .hash (value , list , serializable );
643
656
}
644
657
}
658
+
659
+ @ Test
660
+ public void testLogWarningOnDuplicateFieldInClassHierarchy () {
661
+ kryo .setReferences (true );
662
+ CompatibleFieldSerializer serializer = new CompatibleFieldSerializer (kryo , ClassWithDuplicateField .class );
663
+ serializer .getCompatibleFieldSerializerConfig ().setChunkedEncoding (true );
664
+ serializer .getCompatibleFieldSerializerConfig ().setExtendedFieldNames (false );
665
+ serializer .updateFields ();
666
+ kryo .register (ClassWithDuplicateField .class , serializer );
667
+
668
+ final ClassWithDuplicateField duplicateField = new ClassWithDuplicateField ();
669
+ roundTrip (31 , duplicateField );
670
+ assertEquals (2 , log .messages .size ());
671
+ }
672
+
673
+ static class ClassWithDuplicateField extends SuperClassWithDuplicateField {
674
+ private Boolean customNote = true ;
675
+ }
676
+
677
+ static class SuperClassWithDuplicateField implements Serializable {
678
+ private Boolean customNote = false ;
679
+
680
+ public SuperClassWithDuplicateField () {}
681
+
682
+ public SuperClassWithDuplicateField (Boolean customNote ) {
683
+ this .customNote = customNote ;
684
+ }
685
+
686
+ public boolean equals (Object obj ) {
687
+ if (this == obj )
688
+ return true ;
689
+ if (obj == null )
690
+ return false ;
691
+ if (getClass () != obj .getClass ())
692
+ return false ;
693
+ SuperClassWithDuplicateField other = (SuperClassWithDuplicateField )obj ;
694
+ if (customNote != other .customNote )
695
+ return false ;
696
+ return true ;
697
+ }
698
+ }
645
699
}
0 commit comments