Program: 91183
Project: 91183
Buggy source:
private void updateTypeMapping(java.lang.reflect.Type type,SymbolTable genericsSymbolTable,SymbolType parameterizedType,boolean genericArgs,Set<String> processedTypeVariables) throws InvalidTypeException {
  if (parameterizedType != null) {
    if (type instanceof TypeVariable) {
      TypeVariable<?> tv=(TypeVariable<?>)type;
      String vname=tv.getName();
      if (!processedTypeVariables.contains(vname)) {
        processedTypeVariables.add(vname);
        Symbol<?> s=genericsSymbolTable.findSymbol(vname);
        if (s != null) {
          boolean isInTheTopScope=genericsSymbolTable.getScopes().peek().findSymbol(vname) != null;
          SymbolType st=s.getType();
          if (st != null) {
            SymbolType refactor=s.getType().refactor(vname,parameterizedType,genericArgs || isInTheTopScope);
            refactor.setTemplateVariable(vname);
            s.setType(refactor);
          }
 else {
            s.setType(parameterizedType);
          }
        }
 else {
          genericsSymbolTable.pushSymbol(vname,ReferenceType.TYPE,parameterizedType,null);
        }
        java.lang.reflect.Type[] bounds=tv.getBounds();
        List<SymbolType> paramBounds=parameterizedType.getBounds();
        if (paramBounds != null) {
          for (int i=0; i < bounds.length; i++) {
            updateTypeMapping(bounds[i],genericsSymbolTable,paramBounds.get(i),genericArgs,processedTypeVariables);
          }
        }
      }
    }
 else     if (type instanceof WildcardType) {
      WildcardType wildcard=(WildcardType)type;
      java.lang.reflect.Type[] bounds=wildcard.getUpperBounds();
      List<SymbolType> paramBounds=parameterizedType.getBounds();
      if (paramBounds != null) {
        for (int i=0; i < bounds.length; i++) {
          updateTypeMapping(bounds[i],genericsSymbolTable,paramBounds.get(i),genericArgs,processedTypeVariables);
        }
      }
      bounds=wildcard.getLowerBounds();
      paramBounds=parameterizedType.getLowerBounds();
      if (paramBounds != null) {
        for (int i=0; i < bounds.length; i++) {
          updateTypeMapping(bounds[i],genericsSymbolTable,paramBounds.get(i),genericArgs,processedTypeVariables);
        }
      }
    }
 else     if (type instanceof ParameterizedType) {
      ParameterizedType paramType=(ParameterizedType)type;
      java.lang.reflect.Type[] typeArgs=paramType.getActualTypeArguments();
      List<SymbolType> paramTypeParams=parameterizedType.getParameterizedTypes();
      if (paramTypeParams != null) {
        for (int i=0; i < typeArgs.length; i++) {
          SymbolType st=null;
          if (i < paramTypeParams.size()) {
            st=paramTypeParams.get(i);
          }
          updateTypeMapping(typeArgs[i],genericsSymbolTable,st,genericArgs,processedTypeVariables);
        }
      }
    }
 else     if (type instanceof GenericArrayType) {
      GenericArrayType arrayType=(GenericArrayType)type;
      SymbolType st=parameterizedType.clone();
      st.setArrayCount(parameterizedType.getArrayCount() - 1);
      updateTypeMapping(arrayType.getGenericComponentType(),genericsSymbolTable,st,genericArgs,processedTypeVariables);
    }
 else     if (type instanceof Class) {
      Class<?> clazz=(Class<?>)type;
      Map<String,SymbolType> updateMapping=new LinkedHashMap<String,SymbolType>();
      SymbolType rewrittenType=SymbolType.valueOf(clazz,parameterizedType,updateMapping,null);
      java.lang.reflect.TypeVariable[] tparams=clazz.getTypeParameters();
      List<SymbolType> paramTypes=rewrittenType.getParameterizedTypes();
      if (paramTypes != null) {
        Iterator<SymbolType> it=paramTypes.iterator();
        for (int i=0; i < tparams.length && it.hasNext(); i++) {
          SymbolType st=it.next();
          if (st != null) {
            st.setTemplateVariable(tparams[i].getName());
            updateTypeMapping(tparams[i],genericsSymbolTable,st,true,new HashSet<String>());
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
private void updateTypeMapping(java.lang.reflect.Type type,SymbolTable genericsSymbolTable,SymbolType parameterizedType,boolean genericArgs,Set<String> processedTypeVariables) throws InvalidTypeException {
  if (parameterizedType != null) {
    if (type instanceof TypeVariable) {
      TypeVariable<?> tv=(TypeVariable<?>)type;
      String vname=tv.getName();
      if (!processedTypeVariables.contains(vname)) {
        processedTypeVariables.add(vname);
        Symbol<?> s=genericsSymbolTable.findSymbol(vname);
        if (s != null) {
          boolean isInTheTopScope=genericsSymbolTable.getScopes().peek().findSymbol(vname) != null;
          SymbolType st=s.getType();
          if (st != null) {
            SymbolType refactor=s.getType().refactor(vname,parameterizedType,genericArgs || isInTheTopScope);
            refactor.setTemplateVariable(vname);
            s.setType(refactor);
          }
 else {
            s.setType(parameterizedType);
          }
        }
 else {
          genericsSymbolTable.pushSymbol(vname,ReferenceType.TYPE,parameterizedType,null);
        }
        java.lang.reflect.Type[] bounds=tv.getBounds();
        List<SymbolType> paramBounds=parameterizedType.getBounds();
        if (paramBounds != null) {
          for (int i=0; i < bounds.length; i++) {
            updateTypeMapping(bounds[i],genericsSymbolTable,paramBounds.get(i),genericArgs,processedTypeVariables);
          }
        }
      }
    }
 else     if (type instanceof WildcardType) {
      WildcardType wildcard=(WildcardType)type;
      java.lang.reflect.Type[] bounds=wildcard.getUpperBounds();
      List<SymbolType> paramBounds=parameterizedType.getBounds();
      if (paramBounds != null) {
        for (int i=0; i < bounds.length; i++) {
          updateTypeMapping(bounds[i],genericsSymbolTable,paramBounds.get(i),genericArgs,processedTypeVariables);
        }
      }
      bounds=wildcard.getLowerBounds();
      paramBounds=parameterizedType.getLowerBounds();
      if (paramBounds != null) {
        for (int i=0; i < bounds.length; i++) {
          updateTypeMapping(bounds[i],genericsSymbolTable,paramBounds.get(i),genericArgs,processedTypeVariables);
        }
      }
    }
 else     if (type instanceof ParameterizedType) {
      ParameterizedType paramType=(ParameterizedType)type;
      java.lang.reflect.Type[] typeArgs=paramType.getActualTypeArguments();
      List<SymbolType> paramTypeParams=parameterizedType.getParameterizedTypes();
      if (paramTypeParams != null) {
        for (int i=0; i < typeArgs.length; i++) {
          SymbolType st=null;
          if (i < paramTypeParams.size()) {
            st=paramTypeParams.get(i);
          }
          updateTypeMapping(typeArgs[i],genericsSymbolTable,st,genericArgs,processedTypeVariables);
        }
      }
    }
 else     if (type instanceof GenericArrayType) {
      GenericArrayType arrayType=(GenericArrayType)type;
      SymbolType st=parameterizedType.clone();
      st.setArrayCount(parameterizedType.getArrayCount() - 1);
      updateTypeMapping(arrayType.getGenericComponentType(),genericsSymbolTable,st,genericArgs,processedTypeVariables);
    }
 else     if (type instanceof Class) {
      Class<?> clazz=(Class<?>)type;
      Map<String,SymbolType> updateMapping=new LinkedHashMap<String,SymbolType>();
      SymbolType rewrittenType=SymbolType.valueOf(clazz,parameterizedType,updateMapping,null);
      java.lang.reflect.TypeVariable[] tparams=clazz.getTypeParameters();
      List<SymbolType> paramTypes=rewrittenType.getParameterizedTypes();
      if (paramTypes != null) {
        Iterator<SymbolType> it=paramTypes.iterator();
        HashSet<String> processed=new HashSet<String>();
        for (int i=0; i < tparams.length && it.hasNext(); i++) {
          SymbolType st=it.next();
          if (st != null) {
            st.setTemplateVariable(tparams[i].getName());
            updateTypeMapping(tparams[i],genericsSymbolTable,st,true,processed);
          }
        }
      }
    }
  }
}