Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-90402

Constructor used by ProxyUtil._constructors introduces class loader memory leak

    Details

      Description

      Currently, we have the following code in ProxyUtil:

      	private static final ConcurrentMap<Class<?>, Constructor<?>> _constructors =
      		new ConcurrentReferenceKeyHashMap<>(
      			new ConcurrentReferenceValueHashMap<Class<?>, Constructor<?>>(
      				FinalizeManager.WEAK_REFERENCE_FACTORY),
      			FinalizeManager.WEAK_REFERENCE_FACTORY);
      

      As written, it looks like it was intended to use the following constructor, which reuses the inner (weak) hash map to ensure that references to the class and constructor object are weak.

      	public ConcurrentReferenceKeyHashMap(
      		ConcurrentMap<Reference<K>, V> innerConcurrentMap,
      		FinalizeManager.ReferenceFactory referenceFactory) {
      
      		super(innerConcurrentMap);
      
      		_referenceFactory = referenceFactory;
      	}
      

      However, due to the ambiguity introduced by all of the generics, the Java compiler instead chooses the following constructor:

      	public ConcurrentReferenceKeyHashMap(
      		Map<? extends K, ? extends V> map,
      		FinalizeManager.ReferenceFactory referenceFactory) {
      		this(new ConcurrentHashMap<Reference<K>, V>(), referenceFactory);
      
      		putAll(map);
      	}
      

      This guarantees a class loader memory leak, because rather than having weak references to the constructor (via ConcurrentReferenceValueHashMap), we instead will instantiate a regular ConcurrentHashMap and hold onto strong references to the constructor.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              brian.chan Brian Chan
              Reporter:
              minhchau.dang Minhchau Dang
              Participants of an Issue:
              Recent user:
              Jason Pince
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 36 weeks ago

                  Packages

                  Version Package
                  7.0.0 DXP FP78
                  7.0.10.11 DXP SP11
                  7.0.X
                  7.1.10 DXP FP10
                  7.1.10.2 SP2
                  7.1.3 CE GA4
                  7.1.X
                  7.2.X
                  7.2.1 CE GA2
                  7.3.10 DXP GA1
                  Master