Fix `isAllowed` check and write test to ensure that additional object instances are not created unnecessarily. See gh-40615
.isEmpty()