[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Bug in Microcontainer - Errors from DependencyInfo/Item

alesj do-not-reply at jboss.com
Fri Jul 11 09:39:55 EDT 2008


I've added a test - BadDependencyInfoTestCase - that checks every method of DependencyInfo/Item, throwing an exception after a number of invocations.

There is a few issues I found in AbstractController.

1) trivial one - suppressed
Dependency info in install method

  |          DependencyInfo dependencies = context.getDependencyInfo();
  |          if (trace)
  |          {
  |             String dependsOn = "[]";
  |             if (dependencies != null)
  |             {
  |                try
  |                {
  |                   Set<DependencyItem> set = dependencies.getIDependOn(null);
  |                   if (set != null)
  |                      dependsOn = set.toString();
  |                }
  |                catch (Throwable t)
  |                {
  |                   log.warn("Exception getting dependencies: " + t);
  |                   dependsOn = null;
  |                }
  |             }
  |             if (dependsOn != null)
  |                log.trace("Dependencies for " + name + ": " + dependsOn);
  | 

2) moving to error - no uninstall since we're in uninstall

  |       DependencyInfo dependencies = context.getDependencyInfo();
  |       if (dependencies != null)
  |       {
  |          try
  |          {
  |             Set<DependencyItem> dependsOnMe = dependencies.getDependsOnMe(null);
  |             if (dependsOnMe.isEmpty() == false)
  |             {
  |                for (DependencyItem item : dependsOnMe)
  |                {
  |                   if (item.isResolved())
  |                   {
  |                      ControllerState dependentState = item.getDependentState();
  |                      if (dependentState == null || dependentState.equals(fromState))
  |                      {
  |                         if (item.unresolved(this))
  |                         {
  |                            ControllerContext dependent = getContext(item.getName(), null);
  |                            if (dependent != null)
  |                            {
  |                               ControllerState whenRequired = item.getWhenRequired();
  |                               if (whenRequired == null)
  |                                  whenRequired = ControllerState.NOT_INSTALLED;
  |                               if (isBeforeState(dependent.getState(), whenRequired) == false)
  |                                  uninstallContext(dependent, whenRequired, trace);
  |                            }
  |                         }
  |                      }
  |                   }
  |                }
  |             }
  |          }
  |          catch (Throwable error)
  |          {
  |             log.error("Error resolving dependencies for " + fromState.getStateString() + ": " + context.toShortString(), error);
  |             // Not much else we can do - no uninstall, since we are at uninstall ;-)
  |             errorContexts.put(context.getName(), context);
  |             context.setError(error);
  |          }
  |       }
  | 

3) Currently not testing this:

  |          for (Method method : methods)
  |          {
  |             // Should we suppress this?
  |             if ("getLifecycleCallbacks".equals(method.getName()))
  |                continue;
  | 
If handleInstallLifecycleCallbacks throws exception ((in initial incrementState)) on DependencyInfo::getLifecycleCallbacks(), it gets caught, but re-thrown:

  |          boolean ok = incrementState(context, trace);
  |          if (ok)
  |          {
  |             try
  |             {
  |                registerControllerContext(context);
  |             }
  |             catch (Throwable t)
  |             {
  |                // This is probably unreachable? But let's be paranoid
  |                ok = false;
  |                throw t;
  |             }
  |          }
  |          if (ok)
  |          {
  |             resolveContexts(trace);
  |          }
  |          else
  |          {
  |             errorContexts.remove(context);
  |             throw context.getError();
  |          }
  | 
Should we add context-2-error-handling code to this method?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4163867#4163867

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4163867



More information about the jboss-dev-forums mailing list