@@ -871,7 +871,13 @@ public Object handleWeirdKey(Class<?> keyClass, String keyValue,
871
871
// Can bail out if it's handled
872
872
Object key = h .value ().handleWeirdKey (this , keyClass , keyValue , msg );
873
873
if (key != DeserializationProblemHandler .NOT_HANDLED ) {
874
- return key ;
874
+ // Sanity check for broken handlers, otherwise nasty to debug:
875
+ if ((key == null ) || keyClass .isInstance (key )) {
876
+ return key ;
877
+ }
878
+ throw weirdStringException (keyValue , keyClass , String .format (
879
+ "DeserializationProblemHandler.handleWeirdStringValue() for type %s returned value of type %s" ,
880
+ keyClass , key .getClass ()));
875
881
}
876
882
h = h .next ();
877
883
}
@@ -909,9 +915,15 @@ public Object handleWeirdStringValue(Class<?> targetClass, String value,
909
915
LinkedNode <DeserializationProblemHandler > h = _config .getProblemHandlers ();
910
916
while (h != null ) {
911
917
// Can bail out if it's handled
912
- Object key = h .value ().handleWeirdStringValue (this , targetClass , value , msg );
913
- if (key != DeserializationProblemHandler .NOT_HANDLED ) {
914
- return key ;
918
+ Object instance = h .value ().handleWeirdStringValue (this , targetClass , value , msg );
919
+ if (instance != DeserializationProblemHandler .NOT_HANDLED ) {
920
+ // Sanity check for broken handlers, otherwise nasty to debug:
921
+ if ((instance == null ) || targetClass .isInstance (instance )) {
922
+ return instance ;
923
+ }
924
+ throw weirdStringException (value , targetClass , String .format (
925
+ "DeserializationProblemHandler.handleWeirdStringValue() for type %s returned value of type %s" ,
926
+ targetClass , instance .getClass ()));
915
927
}
916
928
h = h .next ();
917
929
}
@@ -951,7 +963,13 @@ public Object handleWeirdNumberValue(Class<?> targetClass, Number value,
951
963
// Can bail out if it's handled
952
964
Object key = h .value ().handleWeirdNumberValue (this , targetClass , value , msg );
953
965
if (key != DeserializationProblemHandler .NOT_HANDLED ) {
954
- return key ;
966
+ // Sanity check for broken handlers, otherwise nasty to debug:
967
+ if ((key == null ) || targetClass .isInstance (key )) {
968
+ return key ;
969
+ }
970
+ throw weirdNumberException (value , targetClass , String .format (
971
+ "DeserializationProblemHandler.handleWeirdNumberValue() for type %s returned value of type %s" ,
972
+ targetClass , key .getClass ()));
955
973
}
956
974
h = h .next ();
957
975
}
@@ -1025,9 +1043,15 @@ public Object handleInstantiationProblem(Class<?> instClass, Object argument,
1025
1043
LinkedNode <DeserializationProblemHandler > h = _config .getProblemHandlers ();
1026
1044
while (h != null ) {
1027
1045
// Can bail out if it's handled
1028
- Object key = h .value ().handleInstantiationProblem (this , instClass , argument , t );
1029
- if (key != DeserializationProblemHandler .NOT_HANDLED ) {
1030
- return key ;
1046
+ Object instance = h .value ().handleInstantiationProblem (this , instClass , argument , t );
1047
+ if (instance != DeserializationProblemHandler .NOT_HANDLED ) {
1048
+ // Sanity check for broken handlers, otherwise nasty to debug:
1049
+ if ((instance == null ) || instClass .isInstance (instance )) {
1050
+ return instance ;
1051
+ }
1052
+ throw instantiationException (instClass , String .format (
1053
+ "DeserializationProblemHandler.handleInstantiationProblem() for type %s returned value of type %s" ,
1054
+ instClass , instance .getClass ()));
1031
1055
}
1032
1056
h = h .next ();
1033
1057
}
0 commit comments