Skip to content

Commit aa4de63

Browse files
authored
Fix a potential problem in JavaTimeModule._findFactory() (#381)
* Update JavaTimeModule.java Validate the order of the argument types against the order of the parameters. The previous version ignored mismatches and returned the first method with the correct name and correct number of parameters regardless of parameter types.
1 parent e66b5c1 commit aa4de63

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/JavaTimeModule.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,21 +266,27 @@ protected AnnotatedMethod _findFactory(AnnotatedClass cls, String name, Class<?>
266266
{
267267
final int argCount = argTypes.length;
268268
for (AnnotatedMethod method : cls.getFactoryMethods()) {
269-
if (!name.equals(method.getName())
270-
|| (method.getParameterCount() != argCount)) {
271-
continue;
269+
if (name.equals(method.getName())
270+
&& (method.getParameterCount() == argCount)
271+
&& _allArgTypesMatch(argTypes, method)) {
272+
return method;
272273
}
273-
for (int i = 0; i < argCount; ++i) {
274-
Class<?> argType = method.getParameter(i).getRawType();
275-
if (!argType.isAssignableFrom(argTypes[i])) {
276-
continue;
277-
}
278-
}
279-
return method;
280274
}
281275
return null;
282276
}
283277

278+
// @since 2.21
279+
private boolean _allArgTypesMatch(Class<?>[] expectedArgTypes, AnnotatedMethod method)
280+
{
281+
for (int i = 0, len = expectedArgTypes.length; i < len; ++i) {
282+
Class<?> argType = method.getParameter(i).getRawType();
283+
if (!argType.isAssignableFrom(expectedArgTypes[i])) {
284+
return false;
285+
}
286+
}
287+
return true;
288+
}
289+
284290
/**
285291
* Container for serializers, with one tweak; specific lookup we need to deal
286292
* with specific {@code TemporalAdjuster} closure subtypes.

release-notes/CREDITS-2.x

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,15 @@ Joey Muia (@jmuia)
222222
`WRITE_DURATIONS_AS_TIMESTAMPS` enabled
223223
(2.19.0)
224224

225-
Henning Pöttker (@ hpoettker)
225+
Henning Pöttker (@hpoettker)
226226
* Contributed #342: Lenient deserialization of `LocalDate` is not time-zone aware
227227
(2.19.0)
228228

229229
Boleslav Bobcik (@bbobcik)
230230
* Reported, contributed fix for #364: Deserialization of Month in ONE_BASED_MONTHS
231231
mode fails for value "12"
232232
(2.19.0)
233+
234+
Albert Lovers (@AlbertLovers)
235+
* Reported, contributed fix for #381: Fix a potential problem in `JavaTimeModule._findFactory()`
236+
(2.21.0)

release-notes/VERSION-2.x

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Modules:
1717
#376: Allow specifying custom `DateTimeFormatter` for `OffsetDateTime` ser/deser
1818
(new constructors?)
1919
(requested by @ZIRAKrezovic)
20-
21-
No changes since 2.20
20+
#381: Fix a potential problem in `JavaTimeModule._findFactory()`
21+
(reported, fix by, Albert L)
2222

2323
2.20.1 (30-Oct-2025)
2424
2.20.0 (28-Aug-2025)

0 commit comments

Comments
 (0)