diff --git a/core/modules/image/tests/modules/image_module_test/src/Hook/ImageModuleTestHooks.php b/core/modules/image/tests/modules/image_module_test/src/Hook/ImageModuleTestHooks.php
index bd75b066d99de38664b0a2b8d2b5bc2214236ad8..b45ddc542c4a9b4eb54b65a9f80ea450fba2569a 100644
--- a/core/modules/image/tests/modules/image_module_test/src/Hook/ImageModuleTestHooks.php
+++ b/core/modules/image/tests/modules/image_module_test/src/Hook/ImageModuleTestHooks.php
@@ -53,7 +53,7 @@ public function imageStyleFlush($style, $path = NULL): void {
    */
   #[Hook('file_download')]
   public function fileDownload($uri): array {
-    $default_uri = \Drupal::state()->get('image.test_file_download', FALSE);
+    $default_uri = \Drupal::keyValue('image')->get('test_file_download', FALSE);
     if ($default_uri == $uri) {
       return ['X-Image-Owned-By' => 'image_module_test'];
     }
diff --git a/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php b/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php
index 63b2a23a491804305ab5fe09f6c97058647cc927..5c8f1a095594210457521f792121fa6d2bb7820b 100644
--- a/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php
+++ b/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php
@@ -176,7 +176,7 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
     $original_uri = $file_system->copy($file->uri, $scheme . '://', FileExists::Rename);
     // Let the image_module_test module know about this file, so it can claim
     // ownership in hook_file_download().
-    \Drupal::state()->set('image.test_file_download', $original_uri);
+    \Drupal::keyValue('image')->set('test_file_download', $original_uri);
     $this->assertNotFalse($original_uri, 'Created the generated image file.');
 
     // Get the URL of a file that has not been generated and try to create it.
@@ -251,7 +251,7 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
 
       // Make sure that access is denied for existing style files if we do not
       // have access.
-      \Drupal::state()->delete('image.test_file_download');
+      \Drupal::keyValue('image')->delete('test_file_download');
       $this->drupalGet($generate_url);
       $this->assertSession()->statusCodeEquals(403);
 
@@ -301,7 +301,7 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
     $original_uri = $file_system->copy($file->uri, $scheme . '://', FileExists::Rename);
     // Let the image_module_test module know about this file, so it can claim
     // ownership in hook_file_download().
-    \Drupal::state()->set('image.test_file_download', $original_uri);
+    \Drupal::keyValue('image')->set('test_file_download', $original_uri);
 
     // Suppress the security token in the URL, then get the URL of a file that
     // has not been created and try to create it. Check that the security token