Skip to content

Commit 326bb86

Browse files
committed
Use Method.getParameterCount() where possible
1 parent 8c346ad commit 326bb86

File tree

7 files changed

+12
-8
lines changed

7 files changed

+12
-8
lines changed

release-notes/CREDITS-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -1419,3 +1419,7 @@ Krishna Ghimire (Krishnaghimir@github)
14191419
* Reported #3369: Deserialization ignores other Object fields when Object or Array
14201420
value used for enum
14211421
(2.13.2)
1422+
1423+
Christoph Dreis (dreis2211@github)
1424+
* Suggested #3293: Use Method.getParameterCount() where possible
1425+
(2.13.2)

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Project: jackson-databind
66

77
2.13.2 (not yet released)
88

9+
#3293: Use Method.getParameterCount() where possible
10+
(suggested by Christoph D)
911
#3344: `Set.of()` (Java 9) cannot be deserialized with polymorphic handling
1012
(reported by Sam K)
1113
#3368: `SnakeCaseStrategy` causes unexpected `MismatchedInputException` during

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,8 @@ protected SettableBeanProperty _resolveInnerClassValuedProperty(DeserializationC
961961
// and is inner class of the bean class...
962962
if ((enclosing != null) && (enclosing == _beanType.getRawClass())) {
963963
for (Constructor<?> ctor : valueClass.getConstructors()) {
964-
Class<?>[] paramTypes = ctor.getParameterTypes();
965-
if (paramTypes.length == 1) {
964+
if (ctor.getParameterCount() == 1) {
965+
Class<?>[] paramTypes = ctor.getParameterTypes();
966966
if (enclosing.equals(paramTypes[0])) {
967967
if (ctxt.canOverrideAccessModifiers()) {
968968
ClassUtil.checkAndFixAccess(ctor, ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ public Object getValue(Object pojo)
169169

170170
@Override
171171
public String toString() {
172-
// 03-Nov-2020 ckozak: This can use _constructor.getParameterCount() once java 8 is required.
173-
final int argCount = _constructor.getParameterTypes().length;
172+
final int argCount = _constructor.getParameterCount();
174173
return String.format("[constructor for %s (%d arg%s), annotations: %s",
175174
ClassUtil.nameOf(_constructor.getDeclaringClass()), argCount,
176175
(argCount == 1) ? "" : "s", _annotations);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ protected AnnotatedConstructor constructNonDefaultConstructor(ClassUtil.Ctor cto
352352
protected AnnotatedMethod constructFactoryCreator(Method m,
353353
TypeResolutionContext typeResCtxt, Method mixin)
354354
{
355-
final int paramCount = m.getParameterTypes().length;
355+
final int paramCount = m.getParameterCount();
356356
if (_intr == null) { // when annotation processing is disabled
357357
return new AnnotatedMethod(typeResCtxt, m, _emptyAnnotationMap(),
358358
_emptyAnnotationMaps(paramCount));

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ private static boolean _isIncludableMemberMethod(Method m)
184184
}
185185
// also, for now we have no use for methods with more than 2 arguments:
186186
// (2 argument methods for "any setter", fwtw)
187-
int pcount = m.getParameterTypes().length;
188-
return (pcount <= 2);
187+
return (m.getParameterCount() <= 2);
189188
}
190189

191190
private final static class MethodBuilder {

src/main/java/com/fasterxml/jackson/databind/util/ClassUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ public Constructor<?> getConstructor() {
14481448
public int getParamCount() {
14491449
int c = _paramCount;
14501450
if (c < 0) {
1451-
c = _ctor.getParameterTypes().length;
1451+
c = _ctor.getParameterCount();
14521452
_paramCount = c;
14531453
}
14541454
return c;

0 commit comments

Comments
 (0)