I have a list of tasks that need to be updated. To avoid duplicates, it first gets converted into a `Map<Id, Task>` whose `values` are updated as follows:

```
Map<Id, Task> mapIdTasksToUpdate = new Map<Id, Task>(taskList);
update mapIdTasksToUpdate.values();

```

The problem is: initializing the map as `new Map<Id, Task>(taskList)` throws a list exception: 'System.ListException: Row with duplicate Id at index: X'. The number X varies from one execution to another. However, when trying to initialize an empty map and then put row by row manually as:

```
Map<Id, Task> mapIdTasksToUpdate = new Map<Id, Task>();
for(Task taskToUpdate : taskList)
     mapIdTasksToUpdate.put(taskToUpdate.Id, taskToUpdate);
update mapIdTasksToUpdate.values();

```

it executes without any exceptions. 

What is the difference between the two approaches that makes the system throws the list exception? Why is it complaining about duplicates when maps can't hold any (assuming `Id` as keys)? Any ideas?

P.S.: I think its worth to mention that the exception is thrown from an Apex Test class. I couldn't reproduce the error otherwise. Additionally, I already made sure (using `System.debug`) that there is not a duplicate `Id` being inserted on the map.

I appreciate any help you may give me.

Charles

EDIT: I'm adding how the taskList is created and populated:

```
public void updateClosedTasks(List<Task> closedTasks) {

   if(closedTasks== null || closedTasks.size() == 0)
      return;

   List<Task> taskList = new List<Task>();

      for(Task taskToUpdate : closedTasks)
      {
         if(taskToUpdate.masterTask__c)
            taskList.add(taskToUpdate );
      }

      if(taskList.size() > 0)
         TaskBO.getInstance().updateTasks(taskList);
}

```

The method `TaskBO.getInstance().updateTasks()` does the updating from the map.