@Override
 public void clear() throws StorageException {
   final StubIndexImpl stubIndex = StubIndexImpl.getInstanceOrInvalidate();
   final Collection<StubIndexKey> allStubIndexKeys =
       stubIndex != null
           ? stubIndex.getAllStubIndexKeys()
           : Collections.<StubIndexKey>emptyList();
   try {
     for (StubIndexKey key : allStubIndexKeys) {
       //noinspection ConstantConditions
       stubIndex.getWriteLock(key).lock();
     }
     getWriteLock().lock();
     if (stubIndex != null) {
       stubIndex.clearAllIndices();
     }
     super.clear();
   } finally {
     getWriteLock().unlock();
     for (StubIndexKey key : allStubIndexKeys) {
       //noinspection ConstantConditions
       stubIndex.getWriteLock(key).unlock();
     }
   }
 }