code: private static boolean checkCaseCanonical(final File file, String pathToTest) throws PrivilegedActionException {
          // The canonical path returns the actual path on the file system so get this
          String onDiskCanonicalPath = AccessController.doPrivileged(new PrivilegedExceptionAction<String>() {
              /** {@inheritDoc} */
              @Override
              public String run() throws IOException {
                  return file.getCanonicalPath();
              }
          });
          onDiskCanonicalPath = onDiskCanonicalPath.replace("\\", "/");
  
          // The trailing / on a file name is optional so add it if this is a directory
          final String expectedEnding;
          if (onDiskCanonicalPath.endsWith("/")) {
              if (pathToTest.endsWith("/")) {
                  expectedEnding = pathToTest;
              } else {
                  expectedEnding = pathToTest + "/";
              }
          } else {
              if (pathToTest.endsWith("/")) {
                  expectedEnding = pathToTest.substring(0, pathToTest.length() - 1);
              } else {
                  expectedEnding = pathToTest;
              }
          }
          if (expectedEnding.isEmpty()) {
              // Nothing to compare so case must match
              return true;
          }
  
          return onDiskCanonicalPath.endsWith(expectedEnding);
      }
docs: Test that the path to a file matches a specified path.
  
  The test does a case sensitive string comparison of the canonical path
  of the file with the specified path, restricting the form of the
  path which may be used for the test.
  
  Trailing slashes on either the file or the path are ignored.
  
  @param file The file which is to be tested.
  @param trailingPath The path which is to be tested.
  
  @return True or false telling if the path reaches the file.
  
  @throws PrivilegedActionException Thrown if the caller does not
  have privileges to access the file or its ascending path.