Source:
public Boolean invoke(@Nonnull File parentFile, @Nonnull VirtualChannel channel) throws IOException, InterruptedException { if (new File(potentialChildRelativePath).isAbsolute()) { throw new IllegalArgumentException("Only a relative path is supported, the given path is absolute: " + potentialChildRelativePath); } Path parentAbsolutePath = Util.fileToPath(parentFile.getAbsoluteFile()); Path parentRealPath; try { parentRealPath = parentAbsolutePath.toRealPath(); } catch(NoSuchFileException e) { return false; } String remainingPath = potentialChildRelativePath; Path currentFilePath = parentFile.toPath(); while (!remainingPath.isEmpty()) { Path directChild = this.getDirectChild(currentFilePath, remainingPath); Path childUsingFullPath = currentFilePath.resolve(remainingPath); Path rel = directChild.toAbsolutePath().relativize(childUsingFullPath.toAbsolutePath()); remainingPath = rel.toString(); File childFileSymbolic = Util.resolveSymlinkToFile(directChild.toFile()); if (childFileSymbolic == null) { currentFilePath = directChild; } else { currentFilePath = childFileSymbolic.toPath(); } Path currentFileAbsolutePath = currentFilePath.toAbsolutePath(); try{ Path child = currentFileAbsolutePath.toRealPath(); if (!child.startsWith(parentRealPath)) { return false; } } catch (NoSuchFileException e) { try { Path child = currentFileAbsolutePath.normalize(); Path parent = parentAbsolutePath.normalize(); return child.startsWith(parent); } catch (InvalidPathException e2) { throw new IOException(e2); } } catch(FileSystemException e){ return false; } } return true; }

Target:
public Boolean invoke(@Nonnull File parentFile, @Nonnull VirtualChannel channel) throws IOException, InterruptedException { if (new File(potentialChildRelativePath).isAbsolute()) { throw new IllegalArgumentException("Only a relative path is supported, the given path is absolute: " + potentialChildRelativePath); } Path parentAbsolutePath = Util.fileToPath(parentFile.getAbsoluteFile()); Path parentRealPath; try { parentRealPath = parentAbsolutePath.toRealPath(); } catch(NoSuchFileException e) { return false; } String remainingPath = potentialChildRelativePath; Path currentFilePath = parentFile.toPath(); while (!remainingPath.isEmpty()) { Path directChild = this.getDirectChild(currentFilePath, remainingPath); Path childUsingFullPath = currentFilePath.resolve(remainingPath); String childUsingFullPathAbs = childUsingFullPath.toAbsolutePath().toString(); String directChildAbs = directChild.toAbsolutePath().toString(); if (childUsingFullPathAbs.length() == directChildAbs.length()) { remainingPath = ""; } else { remainingPath = childUsingFullPathAbs.substring(directChildAbs.length() + 1); } File childFileSymbolic = Util.resolveSymlinkToFile(directChild.toFile()); if (childFileSymbolic == null) { currentFilePath = directChild; } else { currentFilePath = childFileSymbolic.toPath(); } Path currentFileAbsolutePath = currentFilePath.toAbsolutePath(); try{ Path child = currentFileAbsolutePath.toRealPath(); if (!child.startsWith(parentRealPath)) { return false; } } catch (NoSuchFileException e) { Path child = currentFileAbsolutePath.normalize(); Path parent = parentAbsolutePath.normalize(); return child.startsWith(parent); } catch(FileSystemException e) { LOGGER.log(Level.WARNING, String.format("Problem during call to the method toRealPath on %s", currentFileAbsolutePath), e); return false; } } return true; }