Uploaded image for project: 'CDAP'
  1. CDAP
  2. CDAP-6837

WorkerContext.execute() is inconsistent with the Transactional API

    XMLWordPrintableJSON

    Details

    • Release Notes:
      Fixed an issue in WorkerContext that did not properly implement the contract of the Transactional interface. Note that this fix may cause incompatibilities with previous releases in certain cases. See below for more details.
    • Rank:
      1|hzy5rj:

      Description

      The Transactional API defines:

        void execute(TxRunnable runnable) throws TransactionFailureException;
      

      and WorkerContext implements Transactional. However, it declares this method to not throw checked exceptions:

        void execute(TxRunnable runnable);
      

      That means that any TransactionFailureException thrown from WorkerContext.execute() is wrapped into RuntimeException, and callers must write code similar to this to handle the exception:

      try {
        getContext().execute(...);
      } catch (Exception e) {
        if (e.getCause() instanceof TransactionFailureException) {
          // handle it
        } else {
          // what to expect else? not clear
          throw Throwables.propagate(e);
        } 
      } 
      

      This is a) ugly and b) inconsistent with other implementations of Transactional.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                andreas Andreas Neumann
                Reporter:
                andreas Andreas Neumann
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: