Skip to content
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

#2241 fix bug: when running with a fat jar, need to read entries with openConnection #2952

Merged
merged 5 commits into from
Jan 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions util/src/main/java/io/kubernetes/client/util/ModelMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;

import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLDecoder;
Expand Down Expand Up @@ -485,14 +486,26 @@ private static List<String> getClassNamesFromPackage(ClassLoader classLoader, St

private static void processJarPackage(URL packageURL, String packageName, String pkg, ArrayList<String> names) throws IOException {
String jarFileName = URLDecoder.decode(packageURL.getFile(), "UTF-8");
jarFileName = jarFileName.substring(5, jarFileName.indexOf("!"));
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.error("Loading classes from jar with error packageURL: {}", jarFileName);
logger.error("Loading classes from jar with error packageURL: {}", packageURL);

nit: looks like we might want to dump the packageURL here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same with packageURL

return;
}
logger.info("Loading classes from jar {}", jarFileName);
try (JarFile jf = new JarFile(jarFileName)) {
Enumeration<JarEntry> jarEntries = jf.entries();
while (jarEntries.hasMoreElements()) {
processJarEntry(jarEntries.nextElement(), packageName, pkg, names);
}
Enumeration<JarEntry> jarEntries = jf.entries();
while (jarEntries.hasMoreElements()) {
processJarEntry(jarEntries.nextElement(), packageName, pkg, names);
}
jf.close();
}

private static void processJarEntry(JarEntry jarEntry, String packageName, String pkg, ArrayList<String> names) {
Expand Down
Loading