protected URL findJarForResource(URL url) throws MalformedURLException {
    log.debug("Find JAR URL: " + url);

    // If the file part of the URL is itself a URL, then that URL probably points to the JAR
    try {
      for (;;) {
        url = new URL(url.getFile());
        log.debug("Inner URL: " + url);
      }
    } catch (MalformedURLException e) {
      // This will happen at some point and serves as a break in the loop
    }

    // Look for the .jar extension and chop off everything after that
    StringBuilder jarUrl = new StringBuilder(url.toExternalForm());
    int index = jarUrl.lastIndexOf(".jar");
    if (index >= 0) {
      jarUrl.setLength(index + 4);
      log.debug("Extracted JAR URL: " + jarUrl);
    }
    else {
      log.debug("Not a JAR: " + jarUrl);
      return null;
    }

    // Try to open and test it
    try {
      URL testUrl = new URL(jarUrl.toString());
      if (isJar(testUrl)) {
        return testUrl;
      }
      else {
        // WebLogic fix: check if the URL's file exists in the filesystem.
        log.debug("Not a JAR: " + jarUrl);
        jarUrl.replace(0, jarUrl.length(), testUrl.getFile());
        File file = new File(jarUrl.toString());

        // File name might be URL-encoded
        if (!file.exists()) {
          try {
            file = new File(URLEncoder.encode(jarUrl.toString(), "UTF-8"));
          } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Unsupported encoding?  UTF-8?  That's unpossible.");
          }
        }

        if (file.exists()) {
          log.debug("Trying real file: " + file.getAbsolutePath());
          testUrl = file.toURI().toURL();
          if (isJar(testUrl)) {
            return testUrl;
          }
        }
      }
    } catch (MalformedURLException e) {
      log.warn("Invalid JAR URL: " + jarUrl);
    }

    log.debug("Not a JAR: " + jarUrl);
    return null;
  }
Attempts to deconstruct the given URL to find a JAR file containing the resource referenced
by the URL. That is, assuming the URL references a JAR entry, this method will return a URL
that references the JAR file containing the entry. If the JAR cannot be located, then this
method returns null.

@param url The URL of the JAR entry.
@return The URL of the JAR file, if one is found. Null if not.
@throws MalformedURLException
src/main/java/org/apache/ibatis/io/DefaultVFS.java