Program: 152927
Project: 152927
Buggy source:
/** 
 * Tries (through a best-guess attempt) to figure out why a given class could not be found. This method will search the given bundle and its classpath to determine the reason for which the class cannot be loaded. <p/> This method tries to be effective especially when the dealing with  {@link NoClassDefFoundError} caused by failure of loading transitiveclasses (such as getting a NCDFE when loading <code>foo.A</code> because <code>bar.B</code> cannot be found).
 * @param bundle the bundle to search for (and which should do the loading)
 * @param className the name of the class that failed to be loaded in dotformat (i.e. java.lang.Thread)
 * @param rootClassName the name of the class that triggered the loading(i.e. java.lang.Runnable)
 */
public static void debugClassLoading(Bundle bundle,String className,String rootClassName){
  boolean trace=log.isTraceEnabled();
  if (!trace)   return;
  Dictionary dict=bundle.getHeaders();
  String bname=dict.get(Constants.BUNDLE_NAME) + "String_Node_Str" + dict.get(Constants.BUNDLE_SYMBOLICNAME)+ "String_Node_Str";
  if (trace)   log.trace("String_Node_Str" + className + "String_Node_Str"+ bname+ "String_Node_Str");
  BundleContext context=OsgiBundleUtils.getBundleContext(bundle);
  String packageName=className.substring(0,className.lastIndexOf('.'));
  if (className.indexOf('.') < 0) {
    if (trace)     log.trace("String_Node_Str");
    return;
  }
  Version iversion=hasImport(bundle,packageName);
  if (iversion != null && context != null) {
    if (trace)     log.trace("String_Node_Str" + iversion + "String_Node_Str");
    Bundle[] bundles=context.getBundles();
    for (int i=0; i < bundles.length; i++) {
      if (bundles[i].getBundleId() != bundle.getBundleId()) {
        Version exported=checkBundleForClass(bundles[i],className,iversion);
        if (exported != null && exported.equals(iversion) && rootClassName != null) {
          for (int j=0; j < bundles.length; j++) {
            Version rootexport=hasExport(bundles[j],rootClassName.substring(0,rootClassName.lastIndexOf('.')));
            if (rootexport != null) {
              Version rootimport=hasImport(bundles[j],packageName);
              if (rootimport == null || !rootimport.equals(iversion)) {
                if (trace)                 log.trace("String_Node_Str" + OsgiStringUtils.nullSafeNameAndSymName(bundles[j]) + "String_Node_Str"+ rootClassName+ "String_Node_Str"+ rootexport+ "String_Node_Str"+ packageName+ "String_Node_Str"+ iversion+ "String_Node_Str");
              }
            }
          }
        }
      }
    }
  }
  if (hasExport(bundle,packageName) != null) {
    if (trace)     log.trace("String_Node_Str");
    checkBundleForClass(bundle,className,iversion);
  }
}

Fixed version (ground truth):
/** 
 * Tries (through a best-guess attempt) to figure out why a given class could not be found. This method will search the given bundle and its classpath to determine the reason for which the class cannot be loaded. <p/> This method tries to be effective especially when the dealing with  {@link NoClassDefFoundError} caused by failure of loading transitiveclasses (such as getting a NCDFE when loading <code>foo.A</code> because <code>bar.B</code> cannot be found).
 * @param bundle the bundle to search for (and which should do the loading)
 * @param className the name of the class that failed to be loaded in dotformat (i.e. java.lang.Thread)
 * @param rootClassName the name of the class that triggered the loading(i.e. java.lang.Runnable)
 */
public static void debugClassLoading(Bundle bundle,String className,String rootClassName){
  boolean trace=log.isTraceEnabled();
  if (!trace)   return;
  Dictionary dict=bundle.getHeaders();
  String bname=dict.get(Constants.BUNDLE_NAME) + "String_Node_Str" + dict.get(Constants.BUNDLE_SYMBOLICNAME)+ "String_Node_Str";
  if (trace)   log.trace("String_Node_Str" + className + "String_Node_Str"+ bname+ "String_Node_Str");
  BundleContext context=OsgiBundleUtils.getBundleContext(bundle);
  int pkgIndex=className.lastIndexOf('.');
  if (pkgIndex < 0) {
    if (trace)     log.trace("String_Node_Str");
    return;
  }
  String packageName=className.substring(0,pkgIndex);
  Version iversion=hasImport(bundle,packageName);
  if (iversion != null && context != null) {
    if (trace)     log.trace("String_Node_Str" + iversion + "String_Node_Str");
    Bundle[] bundles=context.getBundles();
    for (int i=0; i < bundles.length; i++) {
      if (bundles[i].getBundleId() != bundle.getBundleId()) {
        Version exported=checkBundleForClass(bundles[i],className,iversion);
        if (exported != null && exported.equals(iversion) && rootClassName != null) {
          for (int j=0; j < bundles.length; j++) {
            Version rootexport=hasExport(bundles[j],rootClassName.substring(0,rootClassName.lastIndexOf('.')));
            if (rootexport != null) {
              Version rootimport=hasImport(bundles[j],packageName);
              if (rootimport == null || !rootimport.equals(iversion)) {
                if (trace)                 log.trace("String_Node_Str" + OsgiStringUtils.nullSafeNameAndSymName(bundles[j]) + "String_Node_Str"+ rootClassName+ "String_Node_Str"+ rootexport+ "String_Node_Str"+ packageName+ "String_Node_Str"+ iversion+ "String_Node_Str");
              }
            }
          }
        }
      }
    }
  }
  if (hasExport(bundle,packageName) != null) {
    if (trace)     log.trace("String_Node_Str");
    checkBundleForClass(bundle,className,iversion);
  }
}