Skip to content

Commit

Permalink
(#179) Check if the arguments match when selecting ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Aug 23, 2020
1 parent a1be216 commit ca8b129
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/com/jcabi/http/request/BaseRequest.java
Expand Up @@ -284,8 +284,15 @@ public <T extends Wire> Request through(final Class<T> type,
Constructor<?> ctor = null;
for (final Constructor<?> opt : type.getDeclaredConstructors()) {
if (opt.getParameterTypes().length == args.length + 1) {
ctor = opt;
break;
final Class<?>[] types = opt.getParameterTypes();
boolean allmatch = true;
for (int i = 1; i < types.length && allmatch; i++) {
allmatch &= types[i].isAssignableFrom(args[i - 1].getClass());
}
if (allmatch) {
ctor = opt;
break;
}
}
}
if (ctor == null) {
Expand Down

0 comments on commit ca8b129

Please sign in to comment.