Skip to content

[Feature/Extensions] [BUG] SettingsModule#registerDynamicSetting contains unreachable code #4531

@dbwiddis

Description

@dbwiddis

Describe the bug

registerDynamicSetting() javadocs state:

Settings can be of Node Scope or Index Scope.

However, this is a "must". And regardless of the scope, some of this code isn't reachable:

public boolean registerDynamicSetting(Setting<?> setting) {
try {
registerSetting(setting);
if (setting.hasNodeScope()) {
return clusterSettings.registerSetting(setting);
}
if (setting.hasIndexScope()) {
return indexScopedSettings.registerSetting(setting);
}
logger.info("Registered new Setting: " + setting.getKey() + " successfully ");
} catch (Exception e) {
logger.error("Could not register setting " + setting.getKey());
throw new SettingsException("Could not register setting:" + setting.getKey());
}
return false;
}

In the case the setting has neither Node nor Index scope, line 190 calls registerSetting() which contains this code:

if (setting.hasNodeScope() || setting.hasIndexScope()) {
    if (setting.hasNodeScope()) {
        // ...
    }
    if (setting.hasIndexScope()) {
        // ...
    }
} else {
    throw new IllegalArgumentException("No scope found for setting [" + setting.getKey() + "]");
}

This jumps immediately to the catch block with an unhelpful log message.

In the case it has Node Scope it passes the first check but returns at line 192.

In the case it has Index Scope and not Node Scope it returns at line 195. However it never reaches this line if it has both Index Scope and Node Scope.

There is no possibility of it ever reaching the log message at line 197.

To Reproduce
Steps to reproduce the behavior:

  1. Attempt to register a setting without either Node Scope or Index Scope
  2. Observe the failure to register
  3. Wonder why, edit the code to produce a stack trace
  4. Find the IllegalArgumentExcxeption that gets swallowed in the catch block.

Expected behavior
Log warnings that clearly state why it didn't work (e.g., you didn't have the correct scope). I believe including the caught exception in the re-thrown exception would provide a "Caused By" link to clarify it, but haven't tested this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions