Community
Participate
Working Groups
The annotation processing for "on navigation node events" occurs in the afterBind() method of the NavigationNodeController. However for the same instance this method can be called more than once and so multiple listeners will be added and so notifications can also occur more than once. Possible solutions: 1. the NavigationNodeController remembers (boolean flag) whether it already has done the annotation processing or 2. the NavigationNodeControllerAnnotationProcessor does this by remembering the processed NavigationNodeControllers (WeakHashMap) Solution 1 is very simple. Solution 2 is more general (can provide a patch). Besides this problem exists another: the created listeners will never get removed.
+1 for solution 1 (Sounds easier with less risk)
yes, 1. is simpler but 2. is more general since it protects itself instead of relying on someone else to do that. And, I think this: + private final Map<INavigationNodeController, ?> alreadyProcessed = new WeakHashMap<INavigationNodeController, Object>(); private NavigationNodeControllerAnnotationProcessor() { // singleton } /** * Process the {@link OnNavigationNodeEvent} annotations for the given * {@link INavigationNodeController}. * * @param navigationNodeController * the {@link INavigationNodeController} to process */ public void processAnnotations(final INavigationNodeController navigationNodeController) { + synchronized (alreadyProcessed) { + if (alreadyProcessed.containsKey(navigationNodeController)) { + return; + } + alreadyProcessed.put(navigationNodeController, null); + } processAnnotations(navigationNodeController, navigationNodeController.getClass()); } is also quite simple. New code lines marked with +
Fixed with solution 2.