Skip to content

SOLR-17370 - Fix facet IllegalAccessException for string fields with numeric values #3346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

heythm
Copy link
Contributor

@heythm heythm commented May 10, 2025

https://issues.apache.org/jira/browse/SOLR-17370

Description

This PR addresses a bug in Solr's facet serialization logic that could cause a java.lang.IllegalAccessException when faceting on string fields that contain numeric-looking values. The issue was observed when a field defined as type="string" in the schema (e.g. dv_device_code) was included in the facet field list, and some of its values were numeric. The serialization code would attempt to use Java reflection on internal Lucene classes (such as LongPoint), resulting in an access violation and a 500 error.

Solution

  • Added a defensive check in Utils.getReflectWriter to detect Lucene Point types (e.g org.apache.lucene.document.LongPoint) and avoid attempting reflective serialization on them.
  • If such a type is encountered, Solr now falls back to a string representation (ClassName:toString()), preventing the IllegalAccessException and ensuring robust serialization.
  • The fix is minimally invasive and only affects the serialization path for objects that would otherwise trigger the reflective access error.

Tests

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide

// which are not meant to be serialized this way and can cause IllegalAccessException.
String lucenePointPkg = "org.apache.lucene.document.";
if (o != null
&& o.getClass().getName().startsWith(lucenePointPkg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feel like a hack to me. Perhaps it's the best choice but hard for me to say at this time before understanding how this is invoked. Maybe there's a solution preventing a Point field from getting here in the first place. A test would help!

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

Successfully merging this pull request may close these issues.

2 participants