code: public static boolean assertIsSubDirectory(
              final String descriptorOfBase, final File child, final File... baseFiles) {
          File canonicalChild;
          try {
              canonicalChild = child.getCanonicalFile();
          } catch (IOException e) {
              throw new Error("Unable to get the canonical file of '" + child +
                                      "'.  Therefore it is not possible to verify if it is a " +
  
                                      "child of '" + Arrays.toString(baseFiles) + "'.");
          }
          for (File base: baseFiles) {
              File canonicalBase;
              try {
                  canonicalBase = base.getCanonicalFile();
              } catch (IOException e) {
                  throw new Error("Unable to get the canonical file of '" + base +
                                          "'.  Therefore it is not possible to verify if '" + child
                                          + "' is a child of it.");
              }
              File parentFile = canonicalChild;
              while (parentFile != null) {
                  if (canonicalBase.equals(parentFile)) {
                      return true;
                  }
                  parentFile = parentFile.getParentFile();
              }
          }
          LOGGER.warn(
                  "A user attempted to access a file not within the '{}' directories ({}). Attempted access " +
                          "to: {}",
                  descriptorOfBase, Arrays.toString(baseFiles), canonicalChild);
          throw new IllegalFileAccessException(
                  "'" + canonicalChild + "' identifies a file that is not within the '" +
                          descriptorOfBase +
                          "' directories: " + Arrays.toString(baseFiles));
      }
docs: Verify that the file is within the base directory. {@link org.mapfish.print.IllegalFileAccessException}
  will be thrown if the assertion does not hold.
  
  @param descriptorOfBase a simple description of the base file, for example: configuration
  @param child the file to test that is is a child of base.
  @param baseFiles the directories that can legally contain the child.