in core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtil.java [842:858]
private static void removeFromCollection(Object target, Field field, Object item) {
try {
field.setAccessible(true);
Collection<Object> collection = (Collection<Object>)field.get(target);
if (collection == null) {
collection = newCollectionInstance(field.getType());
}
if (item != null) {
collection.remove(item);
}
field.set(target, collection);
} catch (IllegalAccessException | IllegalArgumentException | InstantiationException ex) {
throw new RuntimeException("Unable to set field '" + field.getName() + "' for class "
+ target.getClass().getName(), ex);
}
}