void (@NotNull Sdk sdk, @NotNull VirtualFile root, @NotNull OrderRootType rootType, @NotNull Consumer<VirtualFile> rootConsumer) { WriteAction.run(() -> { final SdkModificator modificator = sdk.getSdkModificator(); assertNotNull(modificator); modificator.addRoot(root, rootType); modificator.commitChanges(); }); try { rootConsumer.accept(root); } finally { WriteAction.run(() -> { final SdkModificator modificator = sdk.getSdkModificator(); assertNotNull(modificator); modificator.removeRoot(root, rootType); modificator.commitChanges(); }); } }