[
https://issues.apache.org/jira/browse/OAK-9881?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17575310#comment-17575310
]
Thomas Mueller commented on OAK-9881:
-------------------------------------
The original code (before the patch) only supports "*" at the very end, but
otherwise was correct I think:
{noformat}
- if (first.contains("%")) {
- first = first.replace("%", "*");
- }
- if (first.endsWith("*")) {
+ first = first.replace('%', WildcardQuery.WILDCARD_STRING);
+ first = first.replace('_', WildcardQuery.WILDCARD_CHAR);
+
+ int indexOfWS = first.indexOf(WildcardQuery.WILDCARD_STRING);
+ int indexOfWC = first.indexOf(WildcardQuery.WILDCARD_CHAR);
+ int len = first.length();
+
+ if (indexOfWS == len || indexOfWC == len) {
// remove trailing "*" for prefixquery
first = first.substring(0, first.length() - 1);
if (JCR_PATH.equals(name)) {
{noformat}
> Unreachable code in the logic that processes like constraints
> -------------------------------------------------------------
>
> Key: OAK-9881
> URL: https://issues.apache.org/jira/browse/OAK-9881
> Project: Jackrabbit Oak
> Issue Type: Bug
> Components: indexing
> Reporter: Nuno Santos
> Priority: Minor
>
> In ElasticRequestHandler, the following code has a section that is
> unreachable:
> {code:java}
> private static Query like(String name, String first) {
> first = first.replace('%', WildcardQuery.WILDCARD_STRING);
> first = first.replace('_', WildcardQuery.WILDCARD_CHAR);
> int indexOfWS = first.indexOf(WildcardQuery.WILDCARD_STRING);
> int indexOfWC = first.indexOf(WildcardQuery.WILDCARD_CHAR);
> int len = first.length();
> if (indexOfWS == len || indexOfWC == len) {
> // Unreachable code
> }{code}
> The condition {{indexOfWS == len || indexOfWC == len}} will always evaluate
> to false because the variables {{indexOfWS}} and {{indexOfWC}} are between
> {{-1}} and {{len-1}} (from the specification of {{indexOf()}}), so they will
> never be equal to {{len}}. (I found this issue from a warning in the static
> analyzer of IntelliJ).
> Is this indeed a bug? If so, then we are missing tests to expose this bug.
> The same logic can be found here:
> https://github.com/apache/jackrabbit-oak/blob/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java#L767-L791
--
This message was sent by Atlassian Jira
(v8.20.10#820010)