Skip to content

Commit

Permalink
Use Method.getParameterCount() where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 26, 2022
1 parent 8c346ad commit 326bb86
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1419,3 +1419,7 @@ Krishna Ghimire (Krishnaghimir@github)
* Reported #3369: Deserialization ignores other Object fields when Object or Array
value used for enum
(2.13.2)
Christoph Dreis (dreis2211@github)
* Suggested #3293: Use Method.getParameterCount() where possible
(2.13.2)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Project: jackson-databind

2.13.2 (not yet released)

#3293: Use Method.getParameterCount() where possible
(suggested by Christoph D)
#3344: `Set.of()` (Java 9) cannot be deserialized with polymorphic handling
(reported by Sam K)
#3368: `SnakeCaseStrategy` causes unexpected `MismatchedInputException` during
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,8 @@ protected SettableBeanProperty _resolveInnerClassValuedProperty(DeserializationC
// and is inner class of the bean class...
if ((enclosing != null) && (enclosing == _beanType.getRawClass())) {
for (Constructor<?> ctor : valueClass.getConstructors()) {
Class<?>[] paramTypes = ctor.getParameterTypes();
if (paramTypes.length == 1) {
if (ctor.getParameterCount() == 1) {
Class<?>[] paramTypes = ctor.getParameterTypes();
if (enclosing.equals(paramTypes[0])) {
if (ctxt.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(ctor, ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ public Object getValue(Object pojo)

@Override
public String toString() {
// 03-Nov-2020 ckozak: This can use _constructor.getParameterCount() once java 8 is required.
final int argCount = _constructor.getParameterTypes().length;
final int argCount = _constructor.getParameterCount();
return String.format("[constructor for %s (%d arg%s), annotations: %s",
ClassUtil.nameOf(_constructor.getDeclaringClass()), argCount,
(argCount == 1) ? "" : "s", _annotations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ protected AnnotatedConstructor constructNonDefaultConstructor(ClassUtil.Ctor cto
protected AnnotatedMethod constructFactoryCreator(Method m,
TypeResolutionContext typeResCtxt, Method mixin)
{
final int paramCount = m.getParameterTypes().length;
final int paramCount = m.getParameterCount();
if (_intr == null) { // when annotation processing is disabled
return new AnnotatedMethod(typeResCtxt, m, _emptyAnnotationMap(),
_emptyAnnotationMaps(paramCount));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ private static boolean _isIncludableMemberMethod(Method m)
}
// also, for now we have no use for methods with more than 2 arguments:
// (2 argument methods for "any setter", fwtw)
int pcount = m.getParameterTypes().length;
return (pcount <= 2);
return (m.getParameterCount() <= 2);
}

private final static class MethodBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ public Constructor<?> getConstructor() {
public int getParamCount() {
int c = _paramCount;
if (c < 0) {
c = _ctor.getParameterTypes().length;
c = _ctor.getParameterCount();
_paramCount = c;
}
return c;
Expand Down

0 comments on commit 326bb86

Please sign in to comment.