@Override
  public void checkAttributeRecordSanity(int fileId,
                                         int attributeRecordId) throws IOException {
    if (attributeRecordId == NON_EXISTENT_ATTRIBUTE_RECORD_ID) {
      return;
    }

    lock.readLock().lock();
    try {
      storage.readRecord(attributeRecordId, buffer -> {
        AttributesRecord attributesRecord = new AttributesRecord(buffer);
        if (!attributesRecord.isValid()) {
          throw new IllegalStateException(
            "record(" + attributeRecordId + ") is invalid: " + attributesRecord
          );
        }
        attributesRecord.checkBackrefFile(attributeRecordId, fileId);

        if (attributesRecord.hasDirectory()) {
          int entryNo = 0;
          for (AttributeEntry entry = attributesRecord.currentEntry();
               entry.isValid();
               entry.moveToNextEntry(), entryNo++) {
            int attributeId = entry.attributeId();
            if (entry.isValueInlined()) {
              if (!validAttributeId(attributeId)) {
                String valueAsHex = IOUtil.toHexString(entry.inlinedValueAsSlice());
                throw new IllegalStateException(
                  "attributeRecord[id:" + attributeRecordId + "][#" + entryNo + "]" +
                  "{attributeId: " + attributeId + ", value: " + valueAsHex + "} attributeId must be in [1.." + MAX_ATTRIBUTE_ID + "]");
              }
            }
            else {
              int dedicatedRecordId = entry.dedicatedValueRecordId();
              if (!storage.hasRecord(dedicatedRecordId)) {
                throw new IllegalStateException(
                  "attributeRecord[id:" + attributeRecordId + "][#" + entryNo + "]" +
                  "{attributeId: " + attributeId + ", dedicatedId: " + dedicatedRecordId + "} dedicatedId must be != 0");
              }
            }
          }
        }
        else if (attributesRecord.hasDedicatedAttribute()) {
          int attributeId = attributesRecord.dedicatedRecordAttributeId();
          throw new IllegalStateException(
            "attributeRecord[id:" + attributeRecordId + "]{attributeId: " + attributeId + "} " +
            "is dedicated record, but must be a directory record" +
            ": " + attributesRecord
          );
        }
        else {//AssertionError because it must be covered by !isValid() branch above
          throw new AssertionError(
            "attributeRecord[id:" + attributeRecordId + "] " +
            "is of unknown type (!directory & !dedicated) record" +
            ": " + attributesRecord
          );
        }
        return null;
      });
    }
    finally {
      lock.readLock().unlock();
    }
  }
@Override
  public void checkAttributeRecordSanity(int fileId,
                                         int attributeRecordId)