Skip to content

Commit

Permalink
(jcabi#179) Handle primitives correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Aug 23, 2020
1 parent ca8b129 commit f9be7b8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main/java/com/jcabi/http/request/BaseRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
package com.jcabi.http.request;

import com.fasterxml.jackson.databind.util.ClassUtil;
import com.google.common.base.Joiner;
import com.jcabi.aspects.Immutable;
import com.jcabi.aspects.Loggable;
Expand Down Expand Up @@ -283,13 +284,17 @@ public <T extends Wire> Request through(final Class<T> type,
final Object... args) {
Constructor<?> ctor = null;
for (final Constructor<?> opt : type.getDeclaredConstructors()) {
if (opt.getParameterTypes().length == args.length + 1) {
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());
final Class<?>[] types = opt.getParameterTypes();
if (types.length == args.length + 1) {
boolean match = true;
for (int i = 1; i < types.length && match; i++) {
Class<?> arg = types[i];
if (types[i].isPrimitive()) {
arg = ClassUtil.wrapperType(arg);
}
match = arg.isAssignableFrom(args[i - 1].getClass());
}
if (allmatch) {
if (match) {
ctor = opt;
break;
}
Expand Down

0 comments on commit f9be7b8

Please sign in to comment.