Skip to content

Fix silently swallowed Solr core initialization failures - #848

Open
gallardo wants to merge 1 commit into
alkacon:masterfrom
gallardo:fix/solr-core-init-failures
Open

Fix silently swallowed Solr core initialization failures#848
gallardo wants to merge 1 commit into
alkacon:masterfrom
gallardo:fix/solr-core-init-failures

Conversation

@gallardo

Copy link
Copy Markdown
Contributor

Problem

When the embedded Solr core of a CmsSolrIndex cannot be created, the failure is effectively swallowed and the index is left in a broken-but-enabled state:

  1. In CmsSearchManager#registerSolrIndex(), only NullPointerException is caught around CoreContainer.create(...). Any other RuntimeException — e.g. a SolrException wrapping an org.apache.lucene.index.IndexFormatTooOldException — propagates raw.
  2. It therefore bypasses the CmsConfigurationException handling in CmsSolrIndex#initialize() that would disable the index, and lands in the broad catch (Exception) of CmsSearchManager#initSearchIndexes(), which only logs a WARN.
  3. Because setEnabled(false) never ran, the status report right below logs the index as successfully configured (directly after the WARN about its failed initialization), and every later query against the index fails with an unexplained NullPointerException on the missing Solr client (m_solr is null).

This is not a theoretical path: after upgrading an installation to Solr/Lucene 10, a "Solr Online" index whose data directory was originally created with Lucene 8.x fails core creation with IndexFormatTooOldException (Lucene only reads indexes created by the current and previous major version). The only diagnostics are one WARN at startup plus misleading "successfully configured" INFO, followed by NPEs at query time. A follow-on symptom of the half-failed creation is SolrException: Could not create a new core in .../solr/<name> as another core is already defined there on re-initialization.

Changes

  • registerSolrIndex(): catch RuntimeException instead of only NullPointerException around core creation and wrap it into the existing CmsConfigurationException, so the index is disabled through the normal path with a clear error message.
  • initSearchIndexes(): additionally call index.setEnabled(false) in the catch block, so any initialization failure not handled inside initialize() itself is reported truthfully by the status log instead of as a success.

Status

Draft until tested against a real installation (reproduction environment: OpenCms with embedded Solr 10 and a Lucene-8-created index directory).

🤖 Generated with Claude Code

When the embedded Solr core cannot be created in registerSolrIndex() -
e.g. CoreContainer.create() throws a SolrException wrapping an
IndexFormatTooOldException after a Lucene major version upgrade - the
exception is not converted into a CmsConfigurationException, because only
NullPointerException is caught. It then propagates past the handling in
CmsSolrIndex#initialize() that would disable the index, so the index stays
enabled without a Solr client, initSearchIndexes() reports it as
successfully configured, and every later query fails with an unexplained
NullPointerException on the missing client.

Two changes:
- registerSolrIndex(): catch RuntimeException instead of only
  NullPointerException around core creation and wrap it into the existing
  CmsConfigurationException, so the index is disabled with a clear error.
- initSearchIndexes(): also disable the index in the catch block, so any
  initialization failure not handled inside initialize() itself is
  reported truthfully by the status log instead of as a success.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@gallardo
gallardo marked this pull request as ready for review July 28, 2026 15:36
@gallardo

gallardo commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Verification of PR #848 on OpenCms 21.0.1 (official Docker image)

Environment: alkacon/opencms-docker:21.0.1 (Jetty + MariaDB, Mercury demo), index corruption simulated by truncating WEB-INF/index/Solr Online/index/segments_* to 16 bytes while the container was stopped.

Without the fix (stock 21.0.1 jar) — the bug

Startup log (opencms.log): Solr's own internal error is the only trace; OpenCms logs no WARN/ERROR of its own and then reports misleading success:

16:08:04 ERROR [apache.solr.core.CoreContainer: 990] SolrCore failed to load on startup
         org.apache.solr.common.SolrException: Unable to create core [Solr-Online]
         ...
         Caused by: org.apache.lucene.index.CorruptIndexException: Unexpected file read error while reading index.
         Caused by: java.io.EOFException: read past EOF: ... segments_12
16:08:08  INFO [pencms.search.CmsSearchManager:3137] . Search index : Successfully configured search index "Solr Online" for project "Online"

Every subsequent Solr query fails (opencms-search.log), with pages rendering empty lists (HTTP 200):

WARN [ncms.jsp.CmsJspTagSimpleSearch: 435] The search failed.
Caused by: java.lang.NullPointerException: Cannot invoke "org.apache.solr.client.solrj.SolrClient.query(...)" because "this.m_solr" is null
	at org.opencms.search.solr.CmsSolrIndex.search(CmsSolrIndex.java:1043)

With the fix (same corruption, patched jar = build_21_0_1 + this PR's commit)

Startup now disables the index and reports it truthfully; the unaffected "Solr Offline" index still initializes fine:

16:12:51  WARN [pencms.search.CmsSearchManager:3149] . Search index : Unable to configure search index "Solr Online" for project "Online" - search index "Solr Online" has been disabled
16:12:53  INFO [pencms.search.CmsSearchManager:3146] . Search index : Successfully configured search index "Solr Offline" for project "Offline"

No misleading "Successfully configured" for the broken index (0 occurrences), and the real cause is captured in opencms-search.log via CmsSolrIndex.initialize:

ERROR [encms.search.solr.CmsSolrIndex: 689] Solr Server for index: Solr Online (Solr-Online) ... could not be created.
 org.opencms.configuration.CmsConfigurationException: ...
	at org.opencms.search.CmsSearchManager.registerSolrIndex(CmsSearchManager.java:2280)
	at org.opencms.search.solr.CmsSolrIndex.initialize(CmsSolrIndex.java:687)
Caused by: org.apache.solr.common.SolrException: Error CREATEing SolrCore 'Solr-Online': Unable to create core [Solr-Online]
Caused by: org.apache.lucene.index.CorruptIndexException: Unexpected file read error while reading index.
Caused by: java.io.EOFException: read past EOF: ... segments_12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant