Skip to content
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

UnsupportedOperationException instead of IllegalArgumentException from PointInSetQuery when values are out of order #14161

Open
jhinch-at-atlassian-com opened this issue Jan 22, 2025 · 4 comments
Labels

Comments

@jhinch-at-atlassian-com

Description

PointInSetQuery in its constructor will check if the values provided to it are in order and if not will attempt to throw an exception:

          throw new IllegalArgumentException(
              "values are out of order: saw " + previous + " before " + current);

However instead of this exception, the following exception is thrown:

java.lang.UnsupportedOperationException
	at org.apache.lucene.util.BytesRefBuilder.hashCode(BytesRefBuilder.java:172)
	at java.base/java.lang.Object.toString(Object.java:256)
	at java.base/java.lang.StringConcatHelper.stringOf(StringConcatHelper.java:453)
	at org.apache.lucene.search.PointInSetQuery.<init>(PointInSetQuery.java:116)

This is because previous is a BytesRefBuilder which does not support the hashCode() method which is used by the default toString() method.

Either BytesRefBuilder should be updated to allow for toString() to be invoked on it or the code should be modified to retrieve the BytesRef within the BytesRefBuilder so that the correct exception is thrown

Version and environment details

  • JDK 21
  • Lucene 9.11.1
@gsmiller
Copy link
Contributor

Oh gross. Good catch! It seems like the desire in this exception message is to print out the previous bytes ref in the same was as current. I wonder if we should implement BytesRefBuilder#toString to delegate to its underlying ref buffer?

@jhinch-at-atlassian-com
Copy link
Author

Having BytesRefBuilder#toString delegate to its underlying buffer or calling BytesRefBuilder#get within PointInSetQuery both seem like reasonable options.

@gsmiller
Copy link
Contributor

@jhinch-at-atlassian-com agreed. I might lean towards implementing a BytesRefBuilder#toString method since it could potentially help in other places where this trappy behavior might happen. Do you have any interest in opening a pull request? I'd be happy to review it.

@jhinch-at-atlassian-com
Copy link
Author

I should be able to contribute a PR. Just need to finalise details around the CLA and then I will raise a PR

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

No branches or pull requests

2 participants