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

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 weeks, 2 days ago