Program: 91204
Project: 91204
Buggy source:
private void updateTypeMapping(java.lang.reflect.Type type,SymbolTable genericsSymbolTable,SymbolType parameterizedType,boolean genericArgs) throws InvalidTypeException {
  if (parameterizedType != null) {
    if (type instanceof TypeVariable) {
      TypeVariable<?> tv=(TypeVariable<?>)type;
      String vname=tv.getName();
      Symbol<?> s=genericsSymbolTable.findSymbol(vname);
      if (s != null) {
        boolean isInTheTopScope=genericsSymbolTable.getScopes().peek().findSymbol(vname) != null;
        SymbolType refactor=s.getType().refactor(vname,parameterizedType,genericArgs || isInTheTopScope);
        s.setType(refactor);
      }
 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++) {
          if (!parameterizedType.equals(paramBounds.get(i))) {
            updateTypeMapping(bounds[i],genericsSymbolTable,paramBounds.get(i),genericArgs);
          }
        }
      }
    }
 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);
        }
      }
      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);
        }
      }
    }
 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);
        }
      }
    }
 else     if (type instanceof GenericArrayType) {
      GenericArrayType arrayType=(GenericArrayType)type;
      SymbolType st=parameterizedType.clone();
      st.setArrayCount(parameterizedType.getArrayCount() - 1);
      updateTypeMapping(arrayType.getGenericComponentType(),genericsSymbolTable,st,genericArgs);
    }
 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);
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
private void updateTypeMapping(java.lang.reflect.Type type,SymbolTable genericsSymbolTable,SymbolType parameterizedType,boolean genericArgs) throws InvalidTypeException {
  if (parameterizedType != null) {
    if (type instanceof TypeVariable) {
      TypeVariable<?> tv=(TypeVariable<?>)type;
      String vname=tv.getName();
      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);
          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++) {
          if (!parameterizedType.equals(paramBounds.get(i))) {
            updateTypeMapping(bounds[i],genericsSymbolTable,paramBounds.get(i),genericArgs);
          }
        }
      }
    }
 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);
        }
      }
      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);
        }
      }
    }
 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);
        }
      }
    }
 else     if (type instanceof GenericArrayType) {
      GenericArrayType arrayType=(GenericArrayType)type;
      SymbolType st=parameterizedType.clone();
      st.setArrayCount(parameterizedType.getArrayCount() - 1);
      updateTypeMapping(arrayType.getGenericComponentType(),genericsSymbolTable,st,genericArgs);
    }
 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);
          }
        }
      }
    }
  }
}