1 Reply Latest reply on Dec 9, 2008 2:44 PM by kruno

    Seam 2.0.2 SP1 possibile bug

    kruno

      I've found out something very interesting.
      I had a need to instate two different seam SFSB components of the same type in one conversation. That was not such a big problem, but then I noticed that objects of type List in side those sfsb-s were pointing to the same object in memory in stead of two different.
      That does not happened if sfsb is not seam component.
      Maybe it will be easier to understand with an example:


      This is a simple SFSB, his interface is pretty much normal it exposes all public methods of the bean.


      @Stateful
      public class Sfsb implements SfsbLocal {
      
           ...
           
           private ProxyToList proxy= new ProxyToList();
           
           private List<String> params= new Vector<String>();
      
           public List<String> getParams() {
                return params;
           }
      
           public void setParams(List<String> params) {
                this.params = params;
           }
      
           public ProxyToList getProxy() {
                return proxy;
           }
      
           public void setProxy(ProxyToList proxy) {
                this.proxy = proxy;
           }
           
           
           public void doSomething(){
                log.debug("STOP HERE WITH DEBUGER "+this );
           }
           
           ...
      }
      




      This is a test method in some component, it creates two SFSB of the same type, over the initial context.


      public void test() {
                InitialContext ic;
                try {
                     ic = new InitialContext();
                         SfsbLocal s1= (SfsbLocal) ic.lookup( "orkaXErp/Sfsb/local" ); 
                      SfsbLocal s2= (SfsbLocal) ic.lookup( "orkaXErp/Sfsb/local" ); 
                     log.debug(s1);
                     log.debug(s2);
                     
                     s1.obradi();
                     s2b.obradi();
                     
                     
                } catch (NamingException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                }
      
      
           }
      
      


      This test requires the use of debugger.


      Now if use debugger and set break point in method doSomething of sfsb, you will notice
      that references s1 and s2 point to to  different objects and that reference params also points to different objects in memory.
      THAT IS OK that is the way it should be,
      but if you add name annotation on that sfsb, thus making it seam component, the references s1 and s2 still point to the different objects in memory but their reference params point to the same Object(Vector).
      In other words s1 and s2 share same params List.
      And that actually causes a lot of problems for me, and also what is a weird thing it applies only to Lists not regular objects.
      I've solved my problem to wrap list in side another object, but it is a still weird thing.
      I hope I have explained it well, if it is not clear please ask i will explain more.



      Thanks in advance Kruno.

        • 1. Re: Seam 2.0.2 SP1 possibile bug
          kruno

          Maybe it is easier to test the problem with this pice of code:


          public void test() {
                    InitialContext ic;
                    try {
                         ic = new InitialContext();
                         SfsbLocal s1= (SfsbLocal) ic.lookup( "orkaXErp/Sfsb/local" ); 
                         SfsbLocal s2= (SfsbLocal) ic.lookup( "orkaXErp/Sfsb/local" ); 
                         s1.getParams().add("S1");
                         s2.getParams().add("S2");
          
                                 //ITERATOR FOR FIRST BEAN
                         Iterator<String>it=s1.getParams().iterator();
                         while(it.hasNext()){
                              System.err.println(it.next());
                         }
          
                                    //ITERATOR FOR SECOND BEAN
                         Iterator<String>it2=s2.getParams().iterator();
                         while(it2.hasNext()){
                              System.err.println(it2.next());
                         }
                         
                    } catch (NamingException e) {
                         // TODO Auto-generated catch block
                         e.printStackTrace();
                    }
          
          
               }
          



          This is the product of this test when SFSB is a seam component:


          14:38:25,879 [http-127.0.0.1-8080-6] ERROR STDERR :152 - IN S1 SFSB S1
          14:38:25,880 [http-127.0.0.1-8080-6] ERROR STDERR :152 - IN S1 SFSB S2
          14:38:25,882 [http-127.0.0.1-8080-6] ERROR STDERR :152 - IN S2 SFSB S1
          14:38:25,883 [http-127.0.0.1-8080-6] ERROR STDERR :152 - IN S2 SFSB S2


          and this is when it is not:


          14:42:22,411 [http-127.0.0.1-8080-6] ERROR STDERR :152 - IN S1 SFSB S1
          14:42:22,412 [http-127.0.0.1-8080-6] ERROR STDERR :152 - IN S2 SFSB S2



          Once again thanks Kruno.