public static synchronized @Nonnull Map<String, Object> loadYamlFile(File file)
            throws Exception {
        try (FileInputStream inputStream = new FileInputStream((file))) {
            Map<String, Object> yamlResult =
                    (Map<String, Object>) loader.loadFromInputStream(inputStream);
            return yamlResult == null ? new HashMap<>() : yamlResult;
        } catch (FileNotFoundException e) {
            LOG.error("Failed to find YAML file", e);
            throw e;
        } catch (IOException | YamlEngineException e) {
            if (e instanceof MarkedYamlEngineException) {
                YamlEngineException exception =
                        wrapExceptionToHiddenSensitiveData((MarkedYamlEngineException) e);
                LOG.error("Failed to parse YAML configuration", exception);
                throw exception;
            } else {
                throw e;
            }
        }
    }
@Test
    void testLoadYamlFile_DuplicateKeyException() {
        File confFile = new File(tmpDir, "invalid.yaml");
        try (final PrintWriter pw = new PrintWriter(confFile)) {
            pw.println("key: secret1");
            pw.println("key: secret2");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        assertThatThrownBy(() -> YamlParserUtils.loadYamlFile(confFile))
                .isInstanceOf(YamlEngineException.class)
                .satisfies(
                        e ->
                                assertThat(ExceptionUtils.stringifyException(e))
                                        .doesNotContain("secret1", "secret2"));
    }