You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Nuno Santos (Jira)" <ji...@apache.org> on 2022/08/04 14:49:00 UTC

[jira] [Created] (OAK-9881) Unreachable code in the logic that processes like constraints

Nuno Santos created OAK-9881:
--------------------------------

             Summary: 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


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)