1 Reply Latest reply on Oct 18, 2007 12:09 PM by Ales Justin

    getInstanceClassFactory in ManagedObjectFactory

    Ales Justin Master

      Is this expeced behaviour:

      I'm running some tests for BeanMetaDataICF:

       ManagedObjectFactory factory = ManagedObjectFactory.getInstance();
       BeanInstanceClassFactory instanceClassFactory = new BeanInstanceClassFactory();
       factory.setInstanceClassFactory(AbstractBeanMetaData.class, instanceClassFactory);
      

      Which adds InstanceClassFactory for AbstractBeanMetaData.class.

      But then I was getting weird NPE exception in BeanManagedDeploymentUnitTestCase.
      AbstractManagedObjectFactory.getInstanceClassFactory was still holding weak ref for AbstractBeanMetaData.class, but the actual referent was null.
       public <T extends Serializable> InstanceClassFactory<T> getInstanceClassFactory(Class<T> clazz)
       {
       synchronized (instanceFactories)
       {
       WeakReference<InstanceClassFactory> weak = instanceFactories.get(clazz);
       if (weak != null)
       return weak.get();
       }
       return (InstanceClassFactory<T>)this;
       }
      


      Adding try/finally to my BeanMDICF test did the trick.
       factory.setInstanceClassFactory(AbstractBeanMetaData.class, instanceClassFactory);
       try
       {
       ...
       }
       finally
       {
       factory.setInstanceClassFactory(AbstractBeanMetaData.class, null);
       }