Program: 147564
Project: 147564
Buggy source:
/** 
 * Find elementDeclarations that use any types derived from a named type. <p> This shows one way to query the schema for elementDeclarations and then how to find specific kinds of typeDefinitions. </p>
 * @param objList collection set to search for elemDecls
 * @param localName for the type used
 * @return Boolean indicate any XSDElementDeclarations is found or not
 */
public static boolean findElementsUsingType(ArrayList<Object> objList,XSDTypeDefinition localTypedef){
  for (  Object obj : objList) {
    if (obj == localTypedef) {
      continue;
    }
    if (obj instanceof XSDElementDeclaration || obj instanceof XSDTypeDefinition) {
      XSDTypeDefinition typedef=null;
      if (obj instanceof XSDElementDeclaration) {
        XSDElementDeclaration elem=(XSDElementDeclaration)obj;
        if (elem.getAnonymousTypeDefinition() != null) {
          typedef=elem.getAnonymousTypeDefinition();
        }
 else         if (elem.getTypeDefinition() != null) {
          typedef=elem.getTypeDefinition();
        }
 else {
          continue;
        }
      }
 else {
        typedef=(XSDTypeDefinition)obj;
      }
      if (typedef instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition type=(XSDComplexTypeDefinition)typedef;
        if (localTypedef.getName().equals(type.getName()) && (localTypedef instanceof XSDComplexTypeDefinition)) {
          return true;
        }
        if (type.getContent() instanceof XSDParticle) {
          XSDParticle particle=(XSDParticle)type.getContent();
          if (particle.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup group=(XSDModelGroup)particle.getTerm();
            EList<XSDParticle> elist=group.getContents();
            for (            XSDParticle pt : elist) {
              if (pt.getContent() instanceof XSDElementDeclaration) {
                XSDTypeDefinition typeDef=((XSDElementDeclaration)pt.getContent()).getTypeDefinition();
                if (typeDef != null && typeDef.getName() != null) {
                  if ((localTypedef.getName().equals(typeDef.getName()))) {
                    return true;
                  }
                }
              }
            }
          }
        }
      }
 else       if (typedef instanceof XSDSimpleTypeDefinition) {
        XSDSimpleTypeDefinition type=(XSDSimpleTypeDefinition)typedef;
        XSDSimpleTypeDefinition baseType=type.getBaseTypeDefinition();
        if (baseType != null && baseType.getName().equals(localTypedef.getName())) {
          return true;
        }
      }
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Find elementDeclarations that use any types derived from a named type. <p> This shows one way to query the schema for elementDeclarations and then how to find specific kinds of typeDefinitions. </p>
 * @param objList collection set to search for elemDecls
 * @param localName for the type used
 * @return Boolean indicate any XSDElementDeclarations is found or not
 */
public static boolean findElementsUsingType(List<Object> objList,XSDTypeDefinition localTypedef){
  for (  Object obj : objList) {
    if (obj == localTypedef) {
      continue;
    }
    if (obj instanceof XSDParticle || obj instanceof XSDElementDeclaration || obj instanceof XSDTypeDefinition) {
      XSDTypeDefinition typedef=null;
      if (obj instanceof XSDParticle) {
        XSDParticle xsdParticle=(XSDParticle)obj;
        if (xsdParticle.getTerm() instanceof XSDElementDeclaration) {
          obj=xsdParticle.getTerm();
        }
      }
      if (obj instanceof XSDElementDeclaration) {
        XSDElementDeclaration elem=(XSDElementDeclaration)obj;
        if (elem.getAnonymousTypeDefinition() != null) {
          typedef=elem.getAnonymousTypeDefinition();
        }
 else         if (elem.getTypeDefinition() != null) {
          typedef=elem.getTypeDefinition();
        }
 else {
          continue;
        }
      }
 else {
        typedef=(XSDTypeDefinition)obj;
      }
      if (typedef instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition type=(XSDComplexTypeDefinition)typedef;
        if (localTypedef.getName().equals(type.getName()) && (localTypedef instanceof XSDComplexTypeDefinition)) {
          return true;
        }
        if (type.getContent() instanceof XSDParticle) {
          XSDParticle particle=(XSDParticle)type.getContent();
          if (particle.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup group=(XSDModelGroup)particle.getTerm();
            EList<XSDParticle> elist=group.getContents();
            for (            XSDParticle pt : elist) {
              if (pt.getContent() instanceof XSDElementDeclaration) {
                XSDTypeDefinition typeDef=((XSDElementDeclaration)pt.getContent()).getTypeDefinition();
                boolean sameType=(typeDef instanceof XSDComplexTypeDefinition && localTypedef instanceof XSDComplexTypeDefinition) || (typeDef instanceof XSDSimpleTypeDefinition && localTypedef instanceof XSDSimpleTypeDefinition);
                if (typeDef != null && typeDef.getName() != null && sameType) {
                  if ((localTypedef.getName().equals(typeDef.getName()))) {
                    return true;
                  }
                }
              }
            }
          }
        }
      }
 else       if (typedef instanceof XSDSimpleTypeDefinition) {
        XSDSimpleTypeDefinition type=(XSDSimpleTypeDefinition)typedef;
        XSDSimpleTypeDefinition baseType=type.getBaseTypeDefinition();
        if (baseType != null && baseType.getName().equals(localTypedef.getName()) && localTypedef instanceof XSDSimpleTypeDefinition) {
          return true;
        }
      }
    }
  }
  return false;
}