diff --git a/core/modules/system/src/Tests/File/DirectoryTest.php b/core/modules/system/src/Tests/File/DirectoryTest.php
index 4c15a8e..c9a8b3c 100644
--- a/core/modules/system/src/Tests/File/DirectoryTest.php
+++ b/core/modules/system/src/Tests/File/DirectoryTest.php
@@ -52,6 +52,13 @@ function testFileCheckLocalDirectoryHandling() {
     $absolute_path = drupal_realpath($directory) . DIRECTORY_SEPARATOR . $this->randomMachineName() . DIRECTORY_SEPARATOR . $this->randomMachineName();
     $this->assertTrue(drupal_mkdir($absolute_path, 0775, TRUE), 'No error reported when creating new absolute directories.', 'File');
     $this->assertDirectoryPermissions($absolute_path, 0775);
+
+    // Check that trying to create a new directory whose parent is not writable
+    // fails, but with no PHP error.
+    // Make parent directory read only.
+    @\Drupal::service('file_system')->chmod($parent_path, 0444);
+    $second_child_path = $parent_path . DIRECTORY_SEPARATOR . $this->randomMachineName();
+    $this->assertFalse(@\Drupal::service('file_system')->mkdir($second_child_path, 0775, TRUE), t('Creating child directory under a non writable parent fails.'), 'File');
   }
 
   /**
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index ae6142f..b6d7858 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -832,7 +832,7 @@ function system_check_directory($form_element, FormStateInterface $form_state) {
   }
 
   $logger = \Drupal::logger('file system');
-  if (!is_dir($directory) && !drupal_mkdir($directory, NULL, TRUE)) {
+  if (!is_dir($directory) && !@\Drupal::service('file_system')->mkdir($directory, NULL, TRUE)) {
     // If the directory does not exists and cannot be created.
     $form_state->setErrorByName($form_element['#parents'][0], t('The directory %directory does not exist and could not be created.', array('%directory' => $directory)));
     $logger->error('The directory %directory does not exist and could not be created.', array('%directory' => $directory));
