Uploaded image for project: 'camunda BPM'
  1. camunda BPM
  2. CAM-11410 Camunda Engine Quarkus Extension
  3. CAM-13748

CDI: Investigate the default configuration of auto-inject-fields

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Fixed
    • Icon: L3 - Default L3 - Default
    • 7.16.0, 7.16.0-alpha4
    • None
    • quarkus
    • None

      Problem

      The engine-cdi module defines the custom annotations @ProcessVariableTyped and @ProcessVariable. It can be used in two ways:

      1. Accompanied with the @Inject CDI annotation on a field, the value of the variable by name defined by #value or member name is injected
      2. When a StartProcessInterceptor assigns a value to a field annotated with the aforementioned annotations, and without @Inject, a new variable is created

      The first case is not problematic for the Quarkus extension. However, the second case conflicts with the default Quarkus behavior: it tries to inject beans since the aforementioned annotations get in turn the annotation @Qualifier dynamically (implicitly) assigned. This breaks the engine-cdi behavior.

      Example

      @Dependent
      public class DeclarativeProcessController {
      
        @ProcessVariableTyped
        String untypedName;  // this is going to be set as a process variable but conflicts with the Quarkus default behavior since it tries to auto-inject
      
        @Inject
        @ProcessVariableTyped
        TypedValue injectedValue; // variable with name "injectedValue" is injected
      
        @StartProcess("keyOfTheProcess")
        public void startProcessByKey() {
          untypedName = "untypedName";
        }
      
      }
      

      Solution Ideas

      1. Disable auto-inject-fields in the extension
        • Pros: engine-cdi behavior works out of the box
        • Cons: The configuration changes the default behavior for the entire application (including all extensions)
          • Users might find it annoying that their business logic does not work anymore after adding the Camunda extension, or even worse: users don't use the Camunda extension because it changes the default behavior of Quarkus
      2. Document that there is only full support for the StartProcessInterceptor if auto-inject-fields is disabled; by default, this property is enabled
        • Pros: When adding the Camunda extension, the previously created business logic continues to work; the user can decide on their own if enabling the configuration makes sense or not
        • Cons: The aforementioned problem occurs under the circumstances described 
      3. Remove @Qualifier annotation from @ProcessVariableTyped and @ProcessVariable
        • Pros: Both weld and quarkus test suites are successful independently of the auto-inject-fields configuration
        • Cons: Removing the @Qualifier annotation from the annotations is against the CDI specification; while Weld 1.0 is graceful in this regard, we might face problems when we ever update to a newer Weld version or use another CDI implementation
      4. Configure quarkus to exclude only these annotations with the help of an AnnotationsTransformer
        • Pros: Default behavior must not be changed
        • Cons:
          • Confusing because annotation behavior is not consistent.
          • Leads to additional implementation and test effort.
          • Might break unrecoverable in future Quarkus releases if they change the behavior of the AnnotationsTransformer.

      Decision

      • Forcing the user to change the already created business logic to use the Camunda extension is frustrating (solution #1).
      • Removing the @Qualifier annotation might have side effects that we cannot foresee currently (solution #3).
      • Configuring quarkus to exclude only the problematic annotations is inconsistent and extra effort while we are not aware of if the users actually want to use it (solution #4).

      Before we build something inconsistent like solution #4, let's wait for user feedback. We can still build solution #4 if we see a demand for it. Until then, we will document the limitation. When we don't manage to complete the subtask CAM-13770 within the 7.16 release cycle, we convert it at the end of the project from a sub-task to a bug report.

      Alternative Solution

      @Dependent
      public class DeclarativeProcessController {
      
        @Inject
        public BusinessProcess process;
      
        String untypedName;
      
        @Inject
        @ProcessVariableTyped
        TypedValue injectedValue; // variable with name "injectedValue" is injected
      
        @StartProcess("keyOfTheProcess")
        public void startProcessByKey() {
          untypedName = "untypedName";
          process.setVariable("untypedName", untypedName);
        }
      
      }
      

      [1] https://github.com/quarkusio/quarkus/blob/main/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/AutoInjectFieldProcessor.java#L57-L81

        This is the controller panel for Smart Panels app

              tassilo.weidner Tassilo Weidner
              tassilo.weidner Tassilo Weidner
              Tassilo Weidner Tassilo Weidner
              Nikola Koevski Nikola Koevski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: