You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Jeroen Daanen (JIRA)" <ji...@apache.org> on 2016/12/01 10:07:58 UTC

[jira] [Created] (FELIX-5436) Log message 'callback not found on component instances' incorrectly shown if exception occurs during calling of callback method

Jeroen Daanen created FELIX-5436:
------------------------------------

             Summary: Log message 'callback not found on component instances' incorrectly shown if exception occurs during calling of callback method
                 Key: FELIX-5436
                 URL: https://issues.apache.org/jira/browse/FELIX-5436
             Project: Felix
          Issue Type: Bug
          Components: Dependency Manager
    Affects Versions: org.apache.felix.dependencymanager-r8
            Reporter: Jeroen Daanen
            Priority: Minor


In the method ComponentImpl.invokeCallbackMethod(Object[], String, Class<?>[][], Object[][], boolean) a message is logged when an exception occurs during call of the callback method, because in that case the 'callbackFound' variable is not set.
This is confusing when reading error log.

Suggestion for code change:

{code}
    public void invokeCallbackMethod(Object[] instances, String methodName, Class<?>[][] signatures,
        Object[][] parameters, boolean logIfNotFound) {
        boolean callbackFound = false;
        boolean exceptionOccurredInCallback = false;
        for (int i = 0; i < instances.length; i++) {
            try {
                InvocationUtil.invokeCallbackMethod(instances[i], methodName, signatures, parameters);
                callbackFound |= true;
            }
            catch (NoSuchMethodException e) {
                // if the method does not exist, ignore it
            }
            catch (InvocationTargetException e) {
                // the method itself threw an exception, log that
                m_logger.log(Logger.LOG_ERROR, "Invocation of '" + methodName + "' failed.", e.getCause());
                exceptionOccurredInCallback = true;
            }
            catch (Throwable e) {
                m_logger.log(Logger.LOG_ERROR, "Could not invoke '" + methodName + "'.", e);
                exceptionOccurredInCallback = true;
            }
        }
        
        // If the callback is not found, we don't log if the method is on an AbstractDecorator.
        // (Aspect or Adapter are not interested in user dependency callbacks)        
        if (logIfNotFound && ! exceptionOccurredInCallback && ! callbackFound && ! (getInstance() instanceof AbstractDecorator)) {
            if (m_logger == null) {
                System.out.println("\"" + methodName + "\" callback not found on component instances "
                    + Arrays.toString(instances));
            } else {
                m_logger.log(LogService.LOG_ERROR, "\"" + methodName + "\" callback not found on component instances "
                    + Arrays.toString(instances));
            }

        }
    }
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)