Uploaded image for project: 'Commons Pool'
  1. Commons Pool
  2. POOL-284

"Returned object not currently part of this pool" when using mutable objects

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2
    • 2.4.1
    • None

    Description

      I'm using pool to reuse expensive Sets (storing millions of items). Here is a test which fails:

              GenericObjectPoolConfig config = new GenericObjectPoolConfig ();
              GenericObjectPool<Set> aPool = new GenericObjectPool<> ( new BasePooledObjectFactory<Set> ()
              {
                  @Override
                  public Set create () throws Exception
                  {
                      return new HashSet();
                  }
      
                  @Override
                  public PooledObject<Set> wrap ( Set o )
                  {
                      return new DefaultPooledObject<> ( o );
                  }
      
                  @Override
                  public void passivateObject ( PooledObject<Set> p ) throws Exception
                  {
                      p.getObject ().clear ();
                      super.passivateObject ( p );
                  }
              }, config );
      
              Set set = aPool.borrowObject ();
      
              set.add ( new Object () );
              
              aPool.returnObject ( set );
      

      This is because GenericObjectPool uses a HashMap<Object, PooledObject> to correlate objects and state. HashMap stores objects correlated to their hashCode. So in case object's state change then hashCode will change, thus Map will fail to correlate this object since it stores old hashCode

      Attachments

        1. StaticBucketMap-mods.patch
          3 kB
          Phil Steitz
        2. pool-283-4.patch
          23 kB
          Phil Steitz
        3. identityWrapper.patch
          4 kB
          Phil Steitz

        Activity

          People

            Unassigned Unassigned
            yavalek Valentin Mayamsin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: