@Override public String loadContentText(SendingMessage sendingMessage) { SendingMessage msg; try (Transaction tx = persistence.createTransaction()) { EntityManager em = persistence.getEntityManager(); msg = em.reload(sendingMessage, "sendingMessage.loadContentText"); tx.commit(); } Objects.requireNonNull(msg, "Sending message not found: " + sendingMessage.getId()); if (msg.getContentTextFile() != null) { byte[] bodyContent; try { bodyContent = fileStorage.loadFile(msg.getContentTextFile()); } catch (FileStorageException e) { throw new RuntimeException(e); } //noinspection UnnecessaryLocalVariable String res = bodyTextFromByteArray(bodyContent); return res; } else { return msg.getContentText(); } }