Skip to content

ModelMapper.processJarPackage nested JAR files read error #3981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lmxsoft opened this issue Mar 18, 2025 · 2 comments
Open

ModelMapper.processJarPackage nested JAR files read error #3981

lmxsoft opened this issue Mar 18, 2025 · 2 comments

Comments

@lmxsoft
Copy link

lmxsoft commented Mar 18, 2025

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

@brendandburns
Copy link
Contributor

What is the exception that you are seeing?

@lmxsoft
Copy link
Author

lmxsoft commented Mar 19, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants