Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-5839

EnumerableInterpretable#StaticFieldDetector can overwrite its flag and return an incorrect result

    XMLWordPrintableJSON

Details

    Description

      In EnumerableInterpretable, before using the bindable cache, it is verified whether the class contains static fields (because in that case, the cache shall not be used):

        static Bindable getBindable(ClassDeclaration expr, ...) {
          ...
          if (CalciteSystemProperty.BINDABLE_CACHE_MAX_SIZE.value() != 0) {
            StaticFieldDetector detector = new StaticFieldDetector();
            expr.accept(detector);
            if (!detector.containsStaticField) {
              return BINDABLE_CACHE.get(classBody, () ->  compileToBindable(expr.name, s, compiler));
            }
          }
      
        ....
      
        /**
         * A visitor detecting if the Java AST contains static fields.
         */
        static class StaticFieldDetector extends VisitorImpl<Void> {
          boolean containsStaticField = false;
      
          @Override public Void visit(final FieldDeclaration fieldDeclaration) {
            containsStaticField = (fieldDeclaration.modifier & Modifier.STATIC) != 0;
            return containsStaticField ? null : super.visit(fieldDeclaration);
          }
        }
      

      However, it seem that the containsStaticField flag in {StaticFieldDetector can be overwritten when inspecting the field declarations of the class, so that, if a non-static field is inspected after a static field, the flag will be then (re)set to false; and the final result of the shuttle will be wrong (false, when it should have been true).

      Attachments

        Issue Links

          Activity

            People

              rubenql Ruben Q L
              rubenql Ruben Q L
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: