title: Strange behaviour of ArrayList in jsf
body: <p>i'm developing web app using jsf. I trying display property "brandName" of element with index 0 in ArrayList "materialsSummaryBean.electrolyserMaterialLotList" and this property for all elements using "c:forEach".</p>
  
  <pre><code>            &lt;br/&gt;
              #{materialsSummaryBean.electrolyserMaterialLotList.get(0).material.material.brandName}
              &lt;br/&gt;
              #{materialsSummaryBean.electrolyserMaterialLotList.get(0).material.material.brandName}
              &lt;br/&gt;
              #{materialsSummaryBean.electrolyserMaterialLotList.get(0).material.material.brandName}
              &lt;br/&gt;
              #{materialsSummaryBean.electrolyserMaterialLotList.get(0).material.material.brandName}
              &lt;br/&gt;
              #{materialsSummaryBean.electrolyserMaterialLotList.get(0).material.material.brandName}
              &lt;br/&gt;
              #{materialsSummaryBean.electrolyserMaterialLotList.get(0).material.material.brandName}
              &lt;br/&gt;
              #{materialsSummaryBean.electrolyserMaterialLotList.get(0).material.material.brandName}
              &lt;br/&gt;
              #{materialsSummaryBean.electrolyserMaterialLotList.get(0).material.material.brandName}
              &lt;br/&gt;
              &lt;hr/&gt;
  
              &lt;c:forEach
                      items="#{materialsSummaryBean.electrolyserMaterialLotList}"
                      var="item" varStatus="loop"&gt;
                          #{item.material.material.brandName}
                          &lt;br/&gt;
                          #{item.material.material.brandName}
                          &lt;br/&gt;
                          #{item.material.material.brandName}
                          &lt;br/&gt;
                          #{item.material.material.brandName}
                          &lt;br/&gt;
                          #{item.material.material.brandName}
                          &lt;br/&gt;
                          #{item.material.material.brandName}
                          &lt;br/&gt;
                          #{item.material.material.brandName}
                          &lt;br/&gt;
                          &lt;hr/&gt;
                  &lt;/c:forEach&gt;
  </code></pre>
  
  <p>In result i have absolutly randomize list of values for element with index 0:</p>
  
  <pre><code>ШБ-5 
  ЗШБ класс 4 
  МШ-39 
  ЗШБ класс 4 
  МШ-39 
  КПД-400И 
  ШБ-5 
  МШ-39 
  </code></pre>
  
  <p>For all elements in list: </p>
  
  <pre><code>                        ЗШБ класс 4
                          ЗШБ класс 4
                          КПД-400И
                          ЗШБ класс 4
                          ШБ-5
                          МШ-39
                          ЗШБ класс 4
  
                          &lt;hr /&gt;
  
                          ЗШБ класс 4
                          ЗШБ класс 4
                          МШ-39
                          КПД-400И
                          ЗШБ класс 4
                          ШБ-5
                          МШ-39
  
                          &lt;hr /&gt;
  
                          МШ-39
                          КПД-400И
                          ЗШБ класс 4
                          КПД-400И
                          ЗШБ класс 4
                          ШБ-5
                          МШ-39
  
                          &lt;hr /&gt;
  
                          ШБ-5
                          ЗШБ класс 4
                          МШ-39
                          МШ-39
                          ШБ-5
                          КПД-400И
                          МШ-39
  
                          &lt;hr /&gt;
  </code></pre>
  
  <p>And i don't have any idea what is it and what is the problem.</p>
  
  <p>MaterialsSummaryBean method "getElectrolyserMaterialLotList":</p>
  
  <pre><code>public List&lt;MaterialLotSummaryData&gt; getElectrolyserMaterialLotList() {
      MaterialLotFilter materialLotFilter = new MaterialLotFilter();
      materialLotFilter.setElectrolyserId(id);
      return materialService.getMaterialLotByElectrolyserId(materialLotFilter);
  }
  </code></pre>
  
  <p>And "getMaterialLotByElectrolyserId" method:</p>
  
  <pre><code>public List&lt;MaterialLotSummaryData&gt; getMaterialLotByElectrolyserId(MaterialLotFilter materialLotFilter) {
      Long electrolyserId = materialLotFilter.getElectrolyserId();
      if (electrolyserId == null) {
          throw new IllegalArgumentException("Electrolyser id cannot be null.");
      }
  
      TypedQuery&lt;Unit&gt; queryUnit = em.createQuery(
              "select u from Unit u where u.electrolyser.id = :selectedElectrolyser", 
              Unit.class)
              .setParameter("selectedElectrolyser", electrolyserId);
  
  
      List&lt;Unit&gt; unitList = queryUnit.getResultList();
      HashSet&lt;MaterialLot&gt; materialLotList = new HashSet&lt;MaterialLot&gt;();
  
      HashMap&lt;Long, Double&gt; materialLotUsageMap = new HashMap&lt;Long, Double&gt;();
  
      for (Unit unit : unitList) {
          MaterialLot currentMaterialLot = unit.getMaterialLot();
  
          if (currentMaterialLot == null) continue;
  
          materialLotList.add(currentMaterialLot);
  
  
          Double usage = unit.getActualMaterial().getAmount();
          if (!materialLotUsageMap.containsKey(currentMaterialLot.getId())) {
              materialLotUsageMap.put(currentMaterialLot.getId(), (usage == null) ? 0 : usage);
          } else {
              if(usage == null) continue;
              Double currentUsage = materialLotUsageMap.get(currentMaterialLot.getId());
              materialLotUsageMap.put(currentMaterialLot.getId(), currentUsage + usage);
          }
      }
  
      List&lt;MaterialLotData&gt; result = mapper.createList(materialLotList, MaterialLotData.class);
  
      MaterialLotSummaryData summaryData;
      ArrayList&lt;MaterialLotSummaryData&gt; summaries = new ArrayList&lt;MaterialLotSummaryData&gt;();
      for (MaterialLotData materialLot : result) {
          if (materialLotUsageMap.containsKey(materialLot.getId())) {
              summaryData = new MaterialLotSummaryData();
              summaryData.setId(materialLot.getId());
              summaryData.setAcceptanceDate(materialLot.getAcceptanceDate());
              summaryData.setLotNumber(materialLot.getLotNumber());
              summaryData.setMaterial(materialLot.getActualMaterial());
              summaryData.setNumber(materialLot.getNumber());
              summaryData.setManufacturer(materialLot.getManufacturer());
  
              Double usage = materialLotUsageMap.get(materialLot.getId());
              summaryData.setUsage(usage);
              summaries.add(summaryData);
  
              materialLotUsageMap.remove(materialLot.getId());
          }
      }
  
      return summaries;
  }
  </code></pre>