3 Replies Latest reply on Sep 16, 2008 6:28 PM by gimpy21

    Map empties itself

    gimpy21

      The problem boils down to a Map<String, ZipCode> (w/about 40k items) in a conversation scoped bean emptying itself.


      @Name("zipCodeManager")
      @Scope(ScopeType.CONVERSATION)
      public class ZipCodeManager implements Serializable
      {
           @In(required=false)
           private Session session;
           
           private Map<String, ZipCode> unassigned = new HashMap< String, ZipCode>();
           
           private Map<String, ZipCode> test = new HashMap< String, ZipCode>();
           
           @Create
           public void initialize()
           {
                List<ZipCode> results = session.createQuery("...").list();
                
                for(ZipCode z : results)
                     unassigned.put(z.getValue(), z);
                
                test.put("1", new ZipCode("ONE"));
                test.put("2", new ZipCode("TWO"));
                test.put("3", new ZipCode("THREE"));
           }
      
              public int getAvailableCount()
           {
                System.err.println("zipCodeManager.getAvailableCount() actual: " + unassigned.size());
                System.err.println("zipCodeManager.getAvailableCount() test: " + test.size());
                return test.size();
           }
      
              <snip methods that do nothing but print the name of the method being called>
      }
      



      Calling getAvailableCount() will always have test print 3 but actual can end up emptying itself.


      I have two beans that brought this to light. One is mapped to a page and has a dropdown of states. The user selects one and clicks a button. The method the button is tied to calls the proper ZipCodeManager method and all is well. The other bean allows the user to select a state and then the counties within that state. The user selects a state and the county listbox gets updated by an onchange event on the dropdown (calling stateChanged()). The user then selects some counties and clicks the button. Here's the odd part: If I put a call to zipCodeManager.getAvailableCount() within stateChanged(), everything works okay. When removed, the Map count is zero when I get to the method that the button is tied to. Finally, if I change the Map to a List<ZipCode>, it never empties itself.


      I'm using Seam 2.0.0.GA, JBoss 4.2, zipCodeManager gets injected into the two beans mentioned above, and this is all in a long running conversation.


      Thanks for any help.

        • 1. Re: Map empties itself
          gimpy21

          I should also add that I get the same problem when changing the Map to a Set. Also, if i declare


          private SortedMap<String, ZipCode> unassigned = new TreeMap<String, ZipCode>();
          



          Seam will die saying it expects a HashMap.

          • 2. Re: Map empties itself
            gimpy21

            Another piece to the puzzle (or another puzzle perhaps). I go and assign some zip codes to my object as described above (using a List). Works great. Assign a company to my object. Still great. Go back to assign some more zip codes. I now have a List of null entries. The List's size is identical to when I went to assign my company. I have many lists and maps in my project and none of them behave like this. As a note, I don't have any methods that reassign to the list that could mess up and assign nulls.

            • 3. Re: Map empties itself
              gimpy21

              Upgrading to Seam 2.0.1.GA fixed the emptying of both Lists and Maps.