SonarSource/sonarqube · error · IllegalArgumentException

' ' and ' ' cannot be used at the same time as they refer…

Error message

'%s' and '%s' cannot be used at the same time as they refer to the same setting

What it means

api/settings/values collects requested setting keys; since keys are compared case-insensitively via propertyDefinitions::validKey, two requested keys that differ only in case map to the same setting. getKeysToDisplayMap's merge function detects the duplicate and throws, refusing ambiguous input rather than silently dropping one.

Solutions

  1. Deduplicate keys case-insensitively before sending the request
  2. Use the canonical key casing from api/settings/definitions
  3. If aggregating from multiple sources, lowercase/normalize keys with a Set before joining

Example fix

// before
keys = keysA + keysB  // may contain 'Sonar.Core.Enabled' and 'sonar.core.enabled'
// after
Set<String> normalized = keys.stream().map(String::toLowerCase).collect(Collectors.toSet());
Defensive patterns

Strategy: validation

Validate before calling

const uniqueKeys = [...new Set(keys.map(k => k.toLowerCase()))];
if (uniqueKeys.length !== keys.length) throw new Error('Duplicate keys differing in case');

Try / catch

try { await getSettingsValues(keys); } catch (e) { if (/cannot be used at the same time/.test(e.message)) { return getSettingsValues([...new Set(keys.map(k => k.toLowerCase()))]); } throw e; }

Prevention

When it happens

Trigger: GET api/settings/values?keys=Sonar.Core.Enabled,sonar.core.enabled (same key in different case) or any two keys normalizing to the same valid key.

Common situations: Building the keys parameter dynamically from sources with different casing (config file vs UI), union of two lists not deduplicated case-insensitively.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/7eb655045342a17b. Report an issue: GitHub.

Appendix: source

Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java:185

  }

  private Collection<Setting> loadComponentSettings(DbSession dbSession, EntityDto entity, Set<String> keys) {
    return loadComponentSettings(dbSession, keys, entity.getUuid());
  }

  private List<Setting> loadDefaultValues(Set<String> keys) {
    return propertyDefinitions.getAll().stream()
      .filter(definition -> keys.contains(definition.key()))
      .filter(defaultProperty -> !isEmpty(defaultProperty.defaultValue()))
      .map(Setting::createFromDefinition)
      .toList();
  }

  private Map<String, String> getKeysToDisplayMap(Set<String> keys) {
    return keys.stream()
      .collect(Collectors.toMap(propertyDefinitions::validKey, Function.identity(),
        (u, v) -> {
          throw new IllegalArgumentException(format("'%s' and '%s' cannot be used at the same time as they refer to the same setting", u, v));
        }));
  }

  private List<Setting> loadGlobalSettings(DbSession dbSession, Set<String> keys) {
    List<PropertyDto> properties = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, keys);
    List<PropertyDto> propertySets = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, getPropertySetKeys(properties));
    return properties.stream()
      .map(property -> Setting.createFromDto(property, filterPropertySets(property.getKey(), propertySets, null), propertyDefinitions.get(property.getKey())))
      .toList();
  }

  /**
   * Return list of settings by component uuids
   */
  private Collection<Setting> loadComponentSettings(DbSession dbSession, Set<String> keys, String entityUuid) {
    List<PropertyDto> properties = dbClient.propertiesDao().selectPropertiesByKeysAndEntityUuids(dbSession, keys, Set.of(entityUuid));
    List<PropertyDto> propertySets = dbClient.propertiesDao().selectPropertiesByKeysAndEntityUuids(dbSession, getPropertySetKeys(properties), Set.of(entityUuid));

View on GitHub (pinned to 184c821202)