/**
   * @param fileName the name of the file to find
   * @param checkClassPath if <code>true</code>, the class path is first searched for the file,
   *     otherwise the class path is not searched unless it's one of the explicit paths in the cache
   *     search directories
   * @return a handle to the requested file if it exists in the cache, otherwise null
   * @throws IllegalArgumentException if <code>fileName</code> is null
   */
  public java.net.URL findFile(String fileName, boolean checkClassPath) {
    if (fileName == null) {
      String message = Logging.getMessage("nullValue.FilePathIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (checkClassPath) {
      java.net.URL url = this.getClass().getClassLoader().getResource(fileName);
      if (url != null) return url;

      // Check for a thread context class loader. This allows the file store to find resources in a
      // case
      // in which different parts of the application are handled by different class loaders.
      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
      if (tccl != null) {
        url = tccl.getResource(fileName);
        if (url != null) return url;
      }
    }

    for (StoreLocation location : this.readLocations) {
      java.io.File dir = location.getFile();
      if (!dir.exists()) continue;

      java.io.File file = new java.io.File(makeAbsolutePath(dir, fileName));
      if (file.exists()) {
        try {
          if (location.isMarkWhenUsed()) markFileUsed(file);
          else markFileUsed(file.getParentFile());

          return file.toURI().toURL();
        } catch (java.net.MalformedURLException e) {
          Logging.logger()
              .log(
                  Level.SEVERE,
                  Logging.getMessage("FileStore.ExceptionCreatingURLForFile", file.getPath()),
                  e);
        }
      }
    }

    return null;
  }