DataProvider (@NotNull DataProvider provider1, @Nullable DataProvider provider2) { if (provider2 == null) { return provider1; } List<? extends DataProvider> p1 = provider1 instanceof CompositeDataProvider ? ((CompositeDataProvider)provider1).myProviders : Collections.singletonList(provider1); List<? extends DataProvider> p2 = provider2 instanceof CompositeDataProvider ? ((CompositeDataProvider)provider2).myProviders : Collections.singletonList(provider2); return new CompositeDataProvider(new ArrayList<>(ContainerUtil.concat(p1, p2))); }