Skip to content

Commit 00d5b9b

Browse files
dlwetteronlineAndyScherzinger
authored andcommitted
add workaround for kotlin
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent 87004bd commit 00d5b9b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public NextcloudRetrofitServiceMethod(String apiEndpoint, @NonNull Method method
9292
this.method = method;
9393
this.returnType = method.getGenericReturnType();
9494
Annotation[] methodAnnotations = method.getAnnotations();
95-
this.parameterAnnotationsArray = method.getParameterAnnotations();
95+
this.parameterAnnotationsArray = filterParameterAnnotations(method.getParameterAnnotations());
9696

9797
for (Annotation annotation : methodAnnotations) {
9898
parseMethodAnnotation(annotation);
@@ -115,8 +115,26 @@ public NextcloudRetrofitServiceMethod(String apiEndpoint, @NonNull Method method
115115

116116
}
117117

118+
/**
119+
* filter out empty parameter annotations (e.g. when using kotlin)
120+
* @param annotations
121+
* @return
122+
*/
123+
private Annotation[][] filterParameterAnnotations(Annotation[][] annotations) {
124+
List<Annotation[]> res = new ArrayList<>();
125+
126+
for(Annotation[] annotation : annotations) {
127+
if(annotation.length > 0) {
128+
res.add(annotation);
129+
}
130+
}
131+
132+
return res.toArray(new Annotation[res.size()][]);
133+
}
134+
118135
public T invoke(NextcloudAPI nextcloudAPI, Object[] args) throws Exception {
119-
if(parameterAnnotationsArray.length != args.length) {
136+
//if(parameterAnnotationsArray.length != args.length) {
137+
if(args.length < parameterAnnotationsArray.length) { // Ignore if too many parameters are given (e.g. when using kotlin)
120138
throw new InvalidParameterException("Expected: " + parameterAnnotationsArray.length + " params - were: " + args.length);
121139
}
122140

0 commit comments

Comments
 (0)