Skip to content

fix(OSBulkHelper): getIndexName() always returns fallback — wrong type passed to getActiveIndexName #35314

@fabrizzio-dotCMS

Description

@fabrizzio-dotCMS

Description

OSBulkHelper.getIndexName() always returns the hardcoded fallback \"dotcms_content\" instead of the actual active index, because it passes DEFAULT_INDEX_SUFFIX (e.g. \"content\") to ContentletIndexAPI.getActiveIndexName(type), which only resolves when type is \"working\" or \"live\".

// OSBulkHelper.java line 286
private String getIndexName() {
    // DEFAULT_INDEX_SUFFIX = "content" — never matches IndexType.WORKING or IndexType.LIVE
    return Try.of(() -> APILocator.getContentletIndexAPI().getActiveIndexName(DEFAULT_INDEX_SUFFIX))
        .getOrElse(() -> {
            Logger.warn(this, "Could not resolve active index name, using default");
            return "dotcms_" + DEFAULT_INDEX_SUFFIX; // ← always lands here
        });
}

getActiveIndexName returns null for any type that is neither "working" nor "live", so Try never fails but resolves to null, causing the getOrElse fallback to fire every time.

Current blast radius: OSBulkHelper is not wired into any production code path yet (only referenced in a test comment), so this is not causing active data loss. However it must be fixed before the class is used.

Acceptance Criteria

  • getIndexName() resolves the correct active OS working index (or live, depending on caller intent) using versionedIndicesAPI directly or a dedicated OS-aware resolution method
  • The fallback path (Logger.warn + "dotcms_content") is only reached when no index exists, not on every call
  • A unit test covers both the happy path and the fallback

Additional Context

  • File: dotCMS/src/main/java/com/dotcms/content/index/opensearch/OSBulkHelper.java line 286
  • Identified via TODO audit on PR task(Migrate ESMappingAPIImpl) Refs #34933 #35289
  • ContentletIndexAPI.getActiveIndexName source: ContentletIndexAPIImpl.java line 2568

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

New

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions