0 Replies Latest reply on May 20, 2008 11:41 AM by alesj

    Autowire bug on existing target

    alesj

      I found a bug on my autowiring code. :-)

      In case you provide an existing instance when installing bean metadata into Controller (Controller.install(bmd, myinstance)), that instance won't be part of matching contexts since the code that strips down the instance into its class, superclasses, interfaces, ... is in InstantiateAction.
      And we skip that action when target already exists.

      I'm thinking of adding something like

      public class AutowireAction extends InstallsAwareAction
      {
       protected void installActionInternal(KernelControllerContext context) throws Throwable
       {
       KernelController controller = (KernelController)context.getController();
       DependencyInfo dependencyInfo = context.getDependencyInfo();
       if (dependencyInfo != null && dependencyInfo.isAutowireCandidate())
       controller.addInstantiatedContext(context);
       }
      
       protected void uninstallActionInternal(KernelControllerContext context)
       {
       try
       {
       KernelController controller = (KernelController)context.getController();
       DependencyInfo dependencyInfo = context.getDependencyInfo();
       if (dependencyInfo != null && dependencyInfo.isAutowireCandidate())
       controller.removeInstantiatedContext(context);
       }
       catch (Throwable ignored)
       {
       log.debug("Ignored error unsetting context ", ignored);
       }
       }
      
       protected ControllerState getState()
       {
       return ControllerState.INSTANTIATED;
       }
      
       protected Class<? extends KernelControllerContextAware> getActionAwareInterface()
       {
       return InstantiateKernelControllerContextAware.class;
       }
      }

      and then fix the KernelControllerContextActions to have this
       actions.put(ControllerState.INSTANTIATED, new AutowireAction());
      


      And this also addresses this issue, e.g. you wanted to have some install callback in INSTANTIATE action, that wouldn't be triggered either, since we would skip that state. ;-)

      OK?