ReflectedProject (final ClassLoader classLoader) { ourProjectsLock.lock(); try { for (Iterator<SoftReference<Pair<ReflectedProject, ClassLoader>>> iterator = ourProjects.iterator(); iterator.hasNext();) { final SoftReference<Pair<ReflectedProject, ClassLoader>> ref = iterator.next(); final Pair<ReflectedProject, ClassLoader> pair = ref.get(); if (pair == null) { iterator.remove(); } else { if (pair.second == classLoader) { return pair.first; } } } } finally { ourProjectsLock.unlock(); } final ReflectedProject reflectedProj = new ReflectedProject(classLoader); ourProjectsLock.lock(); try { ourProjects.add(new SoftReference<>( Pair.create(reflectedProj, classLoader) )); } finally { ourProjectsLock.unlock(); } return reflectedProj; }