java icon indicating copy to clipboard operation
java copied to clipboard

ModelMapper.processJarPackage nested JAR files read error

Open lmxsoft opened this issue 8 months ago • 4 comments
trafficstars

Describe the bug When processing a JAR package, the code fails to correctly handle nested JAR files. Specifically, when the packageURL is a nested JAR URL, the jarFileName is incorrectly decoded, leading to a failure in creating the JarFile object.

Here is the problematic code:

  private static void processJarPackage(URL packageURL, String packageName, String pkg, ArrayList<String> names) throws IOException {
    String jarFileName = URLDecoder.decode(packageURL.getFile(), "UTF-8");
    JarFile jf = null;
    // jar: client in repository; nested: client in a fat jar
    if (jarFileName.startsWith("jar:") || jarFileName.startsWith("nested:")) {
      jf = ((JarURLConnection) packageURL.openConnection()).getJarFile();
    }
    // file: client is a file in target (unit test)
    if (jarFileName.startsWith("file:") ) {
      jarFileName = jarFileName.substring(5, jarFileName.indexOf("!"));
      jf = new JarFile(jarFileName);
    }
    if (jf == null) {
      logger.error("Loading classes from jar with error packageURL: {}", jarFileName);
      return;
    }
    logger.info("Loading classes from jar {}", jarFileName);
    Enumeration<JarEntry> jarEntries = jf.entries();
    while (jarEntries.hasMoreElements()) {
      processJarEntry(jarEntries.nextElement(), packageName, pkg, names);
    }
    jf.close();
  }

For example, given the following URL:

Url packageURL = new Url("jar:file:/app/app.jar!/BOOT-INF/lib/java-client.jar!/io.kubenrnetes.client.openapi.models.V1Job");
String jarFileName = URLDecoder.decode(packageURL.getFile(), "UTF-8");

The jarFileName will be decoded as: ”file:/app/app.jar!/BOOT-INF/lib/java-client.jar!/io.kubenrnetes.openapi.models.V1Job” This causes the JarFile to fail to initialize. Proposed Fix:

Change:

String jarFileName = URLDecoder.decode(packageURL.getFile(), "UTF-8"); to:

String jarFileName = URLDecoder.decode(packageURL.toString(), "UTF-8"); Client Version

Client Version e.g. 23.0.0

lmxsoft avatar Mar 18 '25 14:03 lmxsoft

What is the exception that you are seeing?

brendandburns avatar Mar 19 '25 14:03 brendandburns

您好!您的邮件已收到!我查阅后,尽快回复您!

lmxsoft avatar Mar 19 '25 14:03 lmxsoft

“jar:nested:/D:/xxxxxx/backend/target/api.jar/!BOOT-INF/lib/client-java-api-19.0.1.jar!/io/kubernetes/client/openapi/models” will be same problem。

fulizhe avatar May 20 '25 10:05 fulizhe

您好!您的邮件已收到!我查阅后,尽快回复您!

lmxsoft avatar May 20 '25 10:05 lmxsoft

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Aug 18 '25 11:08 k8s-triage-robot

您好!您的邮件已收到!我查阅后,尽快回复您!

lmxsoft avatar Aug 18 '25 11:08 lmxsoft

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Sep 17 '25 11:09 k8s-triage-robot

您好!您的邮件已收到!我查阅后,尽快回复您!

lmxsoft avatar Sep 17 '25 11:09 lmxsoft

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Oct 17 '25 11:10 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar Oct 17 '25 11:10 k8s-ci-robot

您好!您的邮件已收到!我查阅后,尽快回复您!

lmxsoft avatar Oct 17 '25 11:10 lmxsoft