Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
org.apache.felix.dependencymanager-r8
-
None
-
None
Description
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:
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)); } } }