diff --git a/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java b/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java index 81770eb7..1d822dd9 100644 --- a/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java +++ b/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java @@ -92,7 +92,7 @@ public NextcloudRetrofitServiceMethod(String apiEndpoint, @NonNull Method method this.method = method; this.returnType = method.getGenericReturnType(); Annotation[] methodAnnotations = method.getAnnotations(); - this.parameterAnnotationsArray = method.getParameterAnnotations(); + this.parameterAnnotationsArray = filterParameterAnnotations(method.getParameterAnnotations()); for (Annotation annotation : methodAnnotations) { parseMethodAnnotation(annotation); @@ -115,8 +115,28 @@ public NextcloudRetrofitServiceMethod(String apiEndpoint, @NonNull Method method } + /** + * filter out empty parameter annotations (e.g. when using coroutines in kotlin (suspend functions)) + * For functions that are suspendable, the Continuation parameter will be added on the JVM side. + * https://blog.kotlin-academy.com/a-little-reflection-about-coroutines-34050cbc4fe6 + * @param annotations + * @return + */ + private Annotation[][] filterParameterAnnotations(Annotation[][] annotations) { + List res = new ArrayList<>(); + + for(Annotation[] annotation : annotations) { + if(annotation.length > 0) { + res.add(annotation); + } + } + + return res.toArray(new Annotation[res.size()][]); + } + public T invoke(NextcloudAPI nextcloudAPI, Object[] args) throws Exception { - if(parameterAnnotationsArray.length != args.length) { + //if(parameterAnnotationsArray.length != args.length) { + if(args.length < parameterAnnotationsArray.length) { // Ignore if too many parameters are given (e.g. when using kotlin) throw new InvalidParameterException("Expected: " + parameterAnnotationsArray.length + " params - were: " + args.length); }