Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-5676

QueryNodeImpl is too mutable

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: modules/queryparser
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      We use query nodes both during parsing and as a method of building queries. Somehow a bug has crept into our system where a QueryNode somehow gets mutated to have a parent when the node we created didn't originally have a parent. Some processor in our pipeline treats nodes differently based on the parent, which makes it a very hard to find bug.

      It would be very helpful if there were a method like freeze() which would make the instance immutable from thereon, something like the following:

      private volatile boolean frozen;
      
      public final boolean isFrozen() {
          return frozen;
      };
      
      protected void aboutToMakeChanges() {
          if (isFrozen()) {
              throw new IllegalStateException("This object is frozen");
          }
      }
      
      public A freeze() {
          frozen = true;
          return this;
      }
      
      // ...
      
      private void setParent(QueryNode parent) {
          aboutToMakeChanges();
          // existing code
      }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              trejkaz Trejkaz
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: