Skip to content

Commit 278037a

Browse files
authored
another batch of instanceof changes (#5391)
1 parent a90d58c commit 278037a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+233
-251
lines changed

src/main/java/tools/jackson/databind/exc/IgnoredPropertyException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public static IgnoredPropertyException from(JsonParser p,
3838
Collection<Object> propertyIds)
3939
{
4040
Class<?> ref;
41-
if (fromObjectOrClass instanceof Class<?>) {
42-
ref = (Class<?>) fromObjectOrClass;
41+
if (fromObjectOrClass instanceof Class<?> class1) {
42+
ref = class1;
4343
} else { // also acts as null check:
4444
ref = fromObjectOrClass.getClass();
4545
}

src/main/java/tools/jackson/databind/exc/UnrecognizedPropertyException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public static UnrecognizedPropertyException from(JsonParser p,
3838
Collection<Object> propertyIds)
3939
{
4040
Class<?> ref;
41-
if (fromObjectOrClass instanceof Class<?>) {
42-
ref = (Class<?>) fromObjectOrClass;
41+
if (fromObjectOrClass instanceof Class<?> class1) {
42+
ref = class1;
4343
} else {
4444
ref = fromObjectOrClass.getClass();
4545
}

src/main/java/tools/jackson/databind/ext/javatime/JavaTimeInitializer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ public ValueInstantiator modifyValueInstantiator(DeserializationConfig config,
173173
// So... in practice it really should always work, in the end. :)
174174
if (ZoneId.class.isAssignableFrom(raw)) {
175175
// let's assume we should be getting "empty" StdValueInstantiator here:
176-
if (defaultInstantiator instanceof StdValueInstantiator) {
177-
StdValueInstantiator inst = (StdValueInstantiator) defaultInstantiator;
176+
if (defaultInstantiator instanceof StdValueInstantiator inst) {
178177
// one further complication: we need ZoneId info, not sub-class
179178
AnnotatedClass ac;
180179
if (raw == ZoneId.class) {

src/main/java/tools/jackson/databind/ext/javatime/deser/JSR310DeserializerBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ public Object handleUnexpectedToken(Class<?> instClass, JsonToken t,
229229
protected DateTimeException _peelDTE(DateTimeException e) {
230230
while (true) {
231231
Throwable t = e.getCause();
232-
if (t != null && t instanceof DateTimeException) {
233-
e = (DateTimeException) t;
232+
if (t != null && t instanceof DateTimeException dte) {
233+
e = dte;
234234
continue;
235235
}
236236
break;

src/main/java/tools/jackson/databind/introspect/AnnotationIntrospectorPair.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ protected boolean _isExplicitClassOrOb(Object maybeCls, Class<?> implicit) {
724724
if ((maybeCls == null) || (maybeCls == implicit)) {
725725
return false;
726726
}
727-
if (maybeCls instanceof Class<?>) {
728-
return !ClassUtil.isBogusClass((Class<?>) maybeCls);
727+
if (maybeCls instanceof Class<?> class1) {
728+
return !ClassUtil.isBogusClass(class1);
729729
}
730730
return true;
731731
}
@@ -734,7 +734,7 @@ protected Object _explicitClassOrOb(Object maybeCls, Class<?> implicit) {
734734
if ((maybeCls == null) || (maybeCls == implicit)) {
735735
return null;
736736
}
737-
if ((maybeCls instanceof Class<?>) && ClassUtil.isBogusClass((Class<?>) maybeCls)) {
737+
if (maybeCls instanceof Class<?> class1 && ClassUtil.isBogusClass(class1)) {
738738
return null;
739739
}
740740
return maybeCls;

src/main/java/tools/jackson/databind/introspect/EnumNamingStrategyFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public static EnumNamingStrategy createEnumNamingStrategyInstance(Object namingD
2929
if (namingDef == null) {
3030
return defaultNamingStrategy;
3131
}
32-
if (namingDef instanceof EnumNamingStrategy) {
33-
return (EnumNamingStrategy) namingDef;
32+
if (namingDef instanceof EnumNamingStrategy strategy) {
33+
return strategy;
3434
}
3535
if (!(namingDef instanceof Class)) {
3636
throw new IllegalArgumentException(String.format(

src/main/java/tools/jackson/databind/jsontype/TypeResolverProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ protected TypeResolverBuilder<?> _findTypeResolver(MapperConfig<?> config,
234234
// to map it to "PROPERTY" instead of "EXTERNAL_PROPERTY"
235235
if (ann instanceof AnnotatedClass) {
236236
JsonTypeInfo.As inclusion = typeInfo.getInclusionType();
237-
if (inclusion == JsonTypeInfo.As.EXTERNAL_PROPERTY && (ann instanceof AnnotatedClass)) {
237+
if (inclusion == JsonTypeInfo.As.EXTERNAL_PROPERTY) {
238238
typeInfo = typeInfo.withInclusionType(JsonTypeInfo.As.PROPERTY);
239239
}
240240
}

src/main/java/tools/jackson/databind/jsontype/impl/ClassNameIdResolver.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public JavaType typeFromId(DatabindContext ctxt, String id) throws JacksonExcept
7373
protected JavaType _typeFromId(DatabindContext ctxt, String id) throws JacksonException
7474
{
7575
DeserializationContext deserializationContext = null;
76-
if (ctxt instanceof DeserializationContext) {
77-
deserializationContext = (DeserializationContext) ctxt;
76+
if (ctxt instanceof DeserializationContext dContext) {
77+
deserializationContext = dContext;
7878
}
7979
if ((_allowedSubtypes != null) && (deserializationContext != null)
8080
&& deserializationContext.isEnabled(
@@ -108,12 +108,12 @@ protected String _idFrom(DatabindContext ctxt, Object value, Class<?> cls)
108108
// Enum sets and maps are problematic since we MUST know type of
109109
// contained enums, to be able to deserialize.
110110
// In addition, EnumSet is not a concrete type either
111-
if (value instanceof EnumSet<?>) { // Regular- and JumboEnumSet...
112-
Class<?> enumClass = ClassUtil.findEnumType((EnumSet<?>) value);
111+
if (value instanceof EnumSet<?> enumSet) { // Regular- and JumboEnumSet...
112+
Class<?> enumClass = ClassUtil.findEnumType(enumSet);
113113
// not optimal: but EnumSet is not a customizable type so this is sort of ok
114114
str = ctxt.getTypeFactory().constructCollectionType(EnumSet.class, enumClass).toCanonical();
115-
} else if (value instanceof EnumMap<?,?>) {
116-
Class<?> enumClass = ClassUtil.findEnumType((EnumMap<?,?>) value);
115+
} else if (value instanceof EnumMap<?,?> enumMap) {
116+
Class<?> enumClass = ClassUtil.findEnumType(enumMap);
117117
Class<?> valueClass = Object.class;
118118
// not optimal: but EnumMap is not a customizable type so this is sort of ok
119119
str = ctxt.getTypeFactory().constructMapType(EnumMap.class, enumClass, valueClass).toCanonical();

src/main/java/tools/jackson/databind/jsontype/impl/TypeDeserializerBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ protected Object _deserializeWithNativeTypeId(JsonParser p, DeserializationConte
246246
"No (native) type id found when one was expected for polymorphic type handling");
247247
}
248248
} else {
249-
String typeIdStr = (typeId instanceof String) ? (String) typeId : String.valueOf(typeId);
249+
String typeIdStr = (typeId instanceof String string) ? string : String.valueOf(typeId);
250250
deser = _findDeserializer(ctxt, typeIdStr);
251251
}
252252
return deser.deserialize(p, ctxt);

src/main/java/tools/jackson/databind/node/ArrayNode.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ protected ObjectNode _withObject(JsonPointer origPtr,
9393
}
9494
JsonNode n = _at(currentPtr);
9595
// If there's a path, follow it
96-
if ((n != null) && (n instanceof BaseJsonNode)) {
97-
ObjectNode found = ((BaseJsonNode) n)._withObject(origPtr, currentPtr.tail(),
96+
if (n instanceof BaseJsonNode baseNode) {
97+
ObjectNode found = baseNode._withObject(origPtr, currentPtr.tail(),
9898
overwriteMode, preferIndex);
9999
if (found != null) {
100100
return found;
@@ -116,8 +116,8 @@ protected ArrayNode _withArray(JsonPointer origPtr,
116116
}
117117
JsonNode n = _at(currentPtr);
118118
// If there's a path, follow it
119-
if ((n != null) && (n instanceof BaseJsonNode)) {
120-
ArrayNode found = ((BaseJsonNode) n)._withArray(origPtr, currentPtr.tail(),
119+
if (n instanceof BaseJsonNode baseNode) {
120+
ArrayNode found = baseNode._withArray(origPtr, currentPtr.tail(),
121121
overwriteMode, preferIndex);
122122
if (found != null) {
123123
return found;
@@ -296,22 +296,21 @@ public Collection<JsonNode> elements() {
296296
@Override
297297
public boolean equals(Comparator<JsonNode> comparator, JsonNode o)
298298
{
299-
if (!(o instanceof ArrayNode)) {
300-
return false;
301-
}
302-
ArrayNode other = (ArrayNode) o;
303-
final int len = _children.size();
304-
if (other.size() != len) {
305-
return false;
306-
}
307-
List<JsonNode> l1 = _children;
308-
List<JsonNode> l2 = other._children;
309-
for (int i = 0; i < len; ++i) {
310-
if (!l1.get(i).equals(comparator, l2.get(i))) {
299+
if (o instanceof ArrayNode other) {
300+
final int len = _children.size();
301+
if (other.size() != len) {
311302
return false;
312303
}
304+
List<JsonNode> l1 = _children;
305+
List<JsonNode> l2 = other._children;
306+
for (int i = 0; i < len; ++i) {
307+
if (!l1.get(i).equals(comparator, l2.get(i))) {
308+
return false;
309+
}
310+
}
311+
return true;
313312
}
314-
return true;
313+
return false;
315314
}
316315

317316
/*
@@ -1163,8 +1162,8 @@ public boolean equals(Object o)
11631162
{
11641163
if (o == this) return true;
11651164
if (o == null) return false;
1166-
if (o instanceof ArrayNode) {
1167-
return _children.equals(((ArrayNode) o)._children);
1165+
if (o instanceof ArrayNode arrayNode) {
1166+
return _children.equals(arrayNode._children);
11681167
}
11691168
return false;
11701169
}

0 commit comments

Comments
 (0)