Skip to content

Commit 0ee6a6d

Browse files
committed
Minor fix/improvement to PropertyMetadata construction, was NPEing under some conditions
1 parent c96c0b7 commit 0ee6a6d

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Project: jackson-databind
66
2.8.8 (not yet released)
77

88
#1533: `AsPropertyTypeDeserializer` ignores `DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT`
9+
- Minor fix to creation of `PropertyMetadata`, had one path that could lead to NPE
910

1011
2.8.7 (21-Feb-2017)
1112

src/main/java/com/fasterxml/jackson/databind/PropertyMetadata.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,29 @@ public static PropertyMetadata construct(boolean req, String desc) {
7272
return construct(req, desc, null, null);
7373
}
7474

75+
/**
76+
* @since 2.8.8
77+
*/
78+
public static PropertyMetadata construct(Boolean req, String desc, Integer index,
79+
String defaultValue) {
80+
if ((desc != null) || (index != null) || (defaultValue != null)) {
81+
return new PropertyMetadata(req, desc, index, defaultValue);
82+
}
83+
if (req == null) {
84+
return STD_REQUIRED_OR_OPTIONAL;
85+
}
86+
return req ? STD_REQUIRED : STD_OPTIONAL;
87+
}
88+
89+
@Deprecated // since 2.8.8
7590
public static PropertyMetadata construct(boolean req, String desc, Integer index,
7691
String defaultValue) {
7792
if (desc != null || index != null || defaultValue != null) {
7893
return new PropertyMetadata(req, desc, index, defaultValue);
7994
}
8095
return req ? STD_REQUIRED : STD_OPTIONAL;
8196
}
82-
97+
8398
/**
8499
* Minor optimization: let's canonicalize back to placeholders in cases
85100
* where there is no real data to consider

src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,11 +844,10 @@ protected SettableBeanProperty constructCreatorProperty(DeserializationContext c
844844
metadata = PropertyMetadata.STD_REQUIRED_OR_OPTIONAL;
845845
} else {
846846
Boolean b = intr.hasRequiredMarker(param);
847-
boolean req = (b != null && b.booleanValue());
848847
String desc = intr.findPropertyDescription(param);
849848
Integer idx = intr.findPropertyIndex(param);
850849
String def = intr.findPropertyDefaultValue(param);
851-
metadata = PropertyMetadata.construct(req, desc, idx, def);
850+
metadata = PropertyMetadata.construct(b, desc, idx, def);
852851
}
853852
}
854853
JavaType type = resolveMemberAndTypeAnnotations(ctxt, param, param.getType());

src/main/java/com/fasterxml/jackson/databind/deser/SettableBeanProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected SettableBeanProperty(String propName, JavaType type, PropertyName wrap
133133
boolean isRequired)
134134
{
135135
this(new PropertyName(propName), type, wrapper, typeDeser, contextAnnotations,
136-
PropertyMetadata.construct(isRequired, null, null, null));
136+
PropertyMetadata.construct(Boolean.valueOf(isRequired), null, null, null));
137137
}
138138

139139
protected SettableBeanProperty(PropertyName propName, JavaType type, PropertyName wrapper,

src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public PropertyMetadata getMetadata() {
500500
return (desc == null) ? PropertyMetadata.STD_REQUIRED_OR_OPTIONAL
501501
: PropertyMetadata.STD_REQUIRED_OR_OPTIONAL.withDescription(desc);
502502
}
503-
return PropertyMetadata.construct(b.booleanValue(), desc, idx, def);
503+
return PropertyMetadata.construct(b, desc, idx, def);
504504
}
505505

506506
protected Boolean _findRequired() {

0 commit comments

Comments
 (0)