Wrong logging in atlassian.event.internal.AsynchronousAbleEventDispatcher

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Low
    • None
    • Affects Version/s: 6.3.8
    • Component/s: Webhooks
    • 6.03
    • 1
    • Severity 3 - Minor
    • 0

      AsynchronousAbleEventDispatcher uses the following code to log Exceptions that are thrown by Eventlisteners:

      log.error("There was an exception thrown trying to dispatch event '{}' from the invoker '{}'", new Object[]{event, invoker}, e);
      

      What this is supposed to do is to log the event and the invoker in the message, and the full stack trace of the exception afterwards. But the slf4j API is used in a wrong way.

      What the author of this code probably wanted was the first "{}" to be replaced by the first item in the Object array, and the second "{}" to be replaced by the second item in the Object array.

      But the slf4j method that gets called is this one:

        /**
         * Log a message at the ERROR level according to the specified format
         * and arguments.
         * 
         * <p>This form avoids superfluous object creation when the logger
         * is disabled for the ERROR level. </p>
         *
         * @param format the format string
         * @param arg1  the first argument
         * @param arg2  the second argument
         */
        public void error(String format, Object arg1, Object arg2);
      

      So what happens instead is that the first "{}" is replaced by the Object array, and the second "{}" is replaced by the Exception, so in the log file, we get to see toString of the Exception instead of the stacktrace:

      atlassian.event.internal.AsynchronousAbleEventDispatcher] There was an exception thrown trying to dispatch event '[com.atlassian.jira.event.issue.IssueEvent@768ac580[issue=AS-364,comment=com.atlassian.jira.issue.comments.CommentImpl@3bdf13d5,worklog=<null>,changelog=<null>,eventTypeId=6,sendMail=true,params={eventsource=action, baseurl=<SECRET>},subtasksUpdated=false], SingleParameterMethodListenerInvoker{method=public void our.own.IssueEventsListener.onIssueEvent(com.atlassian.jira.event.issue.IssueEvent), listener=our.own.IssueEventsListener@6ff32994}]' from the invoker 'java.lang.RuntimeException: java.lang.NullPointerException'
      

      This makes it hard to track down the code that actually produces that NullPointerException..

      This seems to be a common error triggered by the fact that the slf4j API provides no way to do both string interpolation and stack trace logging. Which is probably okay, as you don't need to care about the performance of the string interpolation in the error case..

      So I suggest using this instead:

      log.error("There was an exception thrown trying to dispatch event '"+event+"' from the invoker '"+invoker+"'", e);
      

            Assignee:
            Unassigned
            Reporter:
            Martin Sander
            Votes:
            15 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated: