larryi      00/10/27 17:34:36

  Modified:    src/share/org/apache/tomcat/util SimplePool.java
  Log:
  Fix put method so idx can't become equal to max causing an
  ArrayIndexOutOfBoundsException.
  
  Update put and get so the code than reads and writes pool[] is synchronized
  too.  Otherwise a get at the wrong time could read the array before it is
  written, and a put at the wrong time could overwrite the object before it is
  read.
  
  Revision  Changes    Path
  1.5       +5 -5      jakarta-tomcat/src/share/org/apache/tomcat/util/SimplePool.java
  
  Index: SimplePool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SimplePool.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SimplePool.java   2000/09/24 23:03:13     1.4
  +++ SimplePool.java   2000/10/28 00:34:36     1.5
  @@ -108,11 +108,11 @@
       public  void put(Object o) {
        int idx=-1;
        synchronized( lock ) {
  -         if( current < max )
  +         if( current < max - 1 )
                idx=++current;
  +         if( idx > 0 ) 
  +             pool[idx]=o;
        }
  -     if( idx > 0 ) 
  -         pool[idx]=o;
       }
   
       /**
  @@ -123,9 +123,9 @@
        synchronized( lock ) {
            if( current >= 0 )
                idx=current--;
  +         if( idx >= 0  ) 
  +             return pool[idx];
        }
  -     if( idx >= 0  ) 
  -         return pool[idx];
        return null;
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to