8000 Remove Arrays.asList from critical stubbing path in GenericMetadataSu… · mockito/mockito@0215884 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0215884

Browse files
authored
Remove Arrays.asList from critical stubbing path in GenericMetadataSupport (#3610)
On Android, the implementation of `java.util.Arrays.ArrayList.toArray` has a non-trivial implementation that ends up calling into `android.os.Process.myUid()`. Consequently, attempting to stub static methods in `android.os.Process` with `doReturn` will end up calling into `myUid()` before the stubbing completes, triggering an infinite recursion. To work around that, replace the `addAll(asList(...))` call with `Collections.addAll`. As an added benefit this avoids an array copy. This upstreams https://r.android.com/3500336.
1 parent d185035 commit 0215884

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mockito-core/src/main/java/org/mockito/internal/util/reflection/GenericMetadataSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected void registerAllTypeVariables(Type classType) {
9191

9292
Class<?> rawType = extractRawTypeOf(typeToRegister);
9393
typesToRegister.add(rawType.getGenericSuperclass());
94-
typesToRegister.addAll(Arrays.asList(rawType.getGenericInterfaces()));
94+
Collections.addAll(typesToRegister, rawType.getGenericInterfaces());
9595
}
9696
}
9797

0 commit comments

Comments
 (0)
0