class InstanceUUID {

    public static synchronized String get() {
        if (uuid == null) {
            try {
                File file = new File(OpenHAB.getUserDataFolder() + File.separator + UUID_FILE_NAME);
                if (!file.exists()) {
                    uuid = java.util.UUID.randomUUID().toString();
                    writeFile(file, uuid);
                } else {
                    uuid = readFirstLine(file);
                    if (uuid != null && !uuid.isEmpty()) {
                        LOGGER.debug("UUID '{}' has been restored from file '{}'", file.getAbsolutePath(), uuid);
                    } else {
                        uuid = java.util.UUID.randomUUID().toString();
                        LOGGER.warn("UUID file '{}' has no content, rewriting it now with '{}'", file.getAbsolutePath(),
                                uuid);
                        writeFile(file, uuid);
                    }
                }
            } catch (IOException e) {
                LOGGER.error("Failed writing the UUID file: {}", e.getMessage());
                return null;
            }
        }
        return uuid;
    }

}