Source:
<code>public Comment createComment(CoreSession session, Comment comment) throws CommentNotFoundException, CommentSecurityException { String parentId = comment.getParentId(); DocumentRef docRef = new IdRef(parentId); if (!CoreInstance.doPrivileged(session, s -> { return s.exists(docRef); })) { throw new CommentNotFoundException("The document or comment " + comment.getParentId() + " does not exist."); } DocumentRef ancestorRef = CoreInstance.doPrivileged(session, s -> { DocumentModel document = s.getDocument(new IdRef(parentId)); <START> return getAncestorRef(s, document); <END> }); if (!session.hasPermission(ancestorRef, SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " can not create comments on document " + parentId); } if (comment.getCreationDate() == null) { comment.setCreationDate(Instant.now()); } return CoreInstance.doPrivileged(session, s -> { DocumentModel documentToComment = s.getDocument(ancestorRef); DocumentModel commentModel = s.createDocumentModel(documentToComment.getPathAsString(), COMMENT_NAME, COMMENT_DOC_TYPE); Comments.commentToDocumentModel(comment, commentModel); if (comment instanceof ExternalEntity) { commentModel.addFacet(EXTERNAL_ENTITY_FACET); Comments.externalEntityToDocumentModel((ExternalEntity) comment, commentModel); } commentModel.setPropertyValue(COMMENT_ANCESTOR_IDS, (Serializable) computeAncestorIds(s, parentId)); commentModel = s.createDocument(commentModel); notifyEvent(s, CommentEvents.COMMENT_ADDED, s.getDocument(docRef), commentModel); return Comments.newComment(commentModel); }); }</code><technical_language>Changes needed</technical_language>

Target:
public Comment createComment(CoreSession session, Comment comment) throws CommentNotFoundException, CommentSecurityException { String parentId = comment.getParentId(); DocumentRef docRef = new IdRef(parentId); if (!CoreInstance.doPrivileged(session, s -> {return s.exists(docRef);})) { throw new CommentNotFoundException("The document or comment " + comment.getParentId() + " does not exist."); } DocumentRef ancestorRef = CoreInstance.doPrivileged(session, s -> { return getAncestorRef(s, s.getDocument(new IdRef(parentId))); }); if (!session.hasPermission(ancestorRef, SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " can not create comments on document " + parentId); } if (comment.getCreationDate() == null) { comment.setCreationDate(Instant.now()); } return CoreInstance.doPrivileged(session, s -> { String path = getCommentContainerPath(s, parentId); DocumentModel commentModel = s.createDocumentModel(path, COMMENT_NAME, COMMENT_DOC_TYPE); Comments.commentToDocumentModel(comment, commentModel); if (comment instanceof ExternalEntity) { commentModel.addFacet(EXTERNAL_ENTITY_FACET); Comments.externalEntityToDocumentModel((ExternalEntity) comment, commentModel); } commentModel.setPropertyValue(COMMENT_ANCESTOR_IDS, (Serializable) computeAncestorIds(s, parentId)); commentModel = s.createDocument(commentModel); notifyEvent(s, CommentEvents.COMMENT_ADDED, s.getDocument(docRef), commentModel); return Comments.newComment(commentModel); }); }