From e59bbf8e31fe449360e2849b63a3a3654aa6849c Mon Sep 17 00:00:00 2001 From: saschamarkus Date: Wed, 12 Aug 2015 15:13:03 +0200 Subject: [PATCH] Issue 11510: Throw Exception for missing settings file An Exception will be thrown when the givven YAML-file doesn't exist. --- .../org/elasticsearch/common/settings/Settings.java | 2 +- .../settings/loader/YamlSettingsLoaderTests.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/common/settings/Settings.java b/core/src/main/java/org/elasticsearch/common/settings/Settings.java index 2671874f86f..4d422575480 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -1129,7 +1129,7 @@ public final class Settings implements ToXContent { } InputStream is = classLoader.getResourceAsStream(resourceName); if (is == null) { - return this; + throw new SettingsException("Failed to load settings from [" + resourceName + "]"); } return loadFromStream(resourceName, is); diff --git a/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java b/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java index e43f5e7f2aa..362188ea03d 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java @@ -63,4 +63,17 @@ public class YamlSettingsLoaderTests extends ESTestCase { .loadFromClasspath("org/elasticsearch/common/settings/loader/indentation-with-explicit-document-start-settings.yml") .build(); } + + + @Test + public void testYamlSettingsNoFile() throws Exception { + String invalidResourceName = "org/elasticsearch/common/settings/loader/no-test-settings.yml"; + try { + Settings defaultSettings = settingsBuilder().loadFromClasspath(invalidResourceName).build(); + fail("For a not exiting file an exception should be thrown."); + } catch (Exception e) { + assertTrue(e instanceof SettingsException); + assertThat(e.getMessage(), equalTo("Failed to load settings from [" + invalidResourceName + "]")); + } + } } \ No newline at end of file