code: public static RecursionDetection detectRecursiveInjection(Throwable t) {
          RecursionDetection rd;
          boolean recursiveInjection = false;
          boolean logged = false;
          Throwable cause = t;
          Throwable lastCause = null;
          while (cause != null && cause != lastCause) {
              if (cause instanceof StackOverflowError ||
                  cause instanceof RecursiveInjectionException) {
                  recursiveInjection = true;
  
                  if (cause instanceof RecursiveInjectionException &&
                      ((RecursiveInjectionException) cause).ivLogged) {
                      logged = true;
                      break;
                  }
              }
              lastCause = cause;
              cause = cause.getCause();
          }
  
          if (recursiveInjection && logged) {
              rd = RecursionDetection.RecursiveAlreadyLogged;
          } else if (recursiveInjection) {
              rd = RecursionDetection.Recursive;
          } else {
              rd = RecursionDetection.NotRecursive;
          }
  
          return rd;
      }
docs: This method detects whether a given Throwable is the result of a
  recursive injection. A recursive injection can exist when a bean
  specifies to inject an instance of the same type of interface into
  itself, or if it injects another EJB that directly or indirectly
  injects the original EJB. If this occurs in Stateful Session beans,
  we will fail because the injection process requires that the injected
  EJB be started - which requires it to be injected.
  <br/>
  This method will attempt to detect an injection cycle by searching
  the passed-in throwable for a StackOverflowError in the cause chain.
  In the future we may want to provide a more elegant cycle-detection
  strategy.
  <br/>
  
  @param t - the Throwable to check
  @return true if the passed-in Throwable's "cause chain" contains an
  instance of StackOverflowError