-
Notifications
You must be signed in to change notification settings - Fork 7.6k
增加更多memorycompiler对jar内容的获取 #3104
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,113 @@ | ||||||||||||||||
| package com.taobao.arthas.compiler; | ||||||||||||||||
|
|
||||||||||||||||
| import javax.lang.model.element.Modifier; | ||||||||||||||||
| import javax.lang.model.element.NestingKind; | ||||||||||||||||
|
||||||||||||||||
| import javax.tools.JavaFileObject; | ||||||||||||||||
| import java.io.*; | ||||||||||||||||
| import java.net.URI; | ||||||||||||||||
| import java.nio.charset.Charset; | ||||||||||||||||
|
||||||||||||||||
| import java.nio.charset.Charset; |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class name GetZipFile is poorly named as it uses a verb ("Get") for a class that represents an extended ZipFile. A better name would be something like CustomZipFile, ExtendedZipFile, or StreamableZipFile to better describe what the class represents.
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stream() method loads all ZipEntry elements into an ArrayList before converting to a stream, which is inefficient for large zip files. This creates unnecessary memory overhead. Consider using Collections.list(entries).stream() or implementing a custom Spliterator for better performance and memory efficiency.
| Enumeration<? extends ZipEntry> entries = super.entries(); | |
| List<ZipEntry> entryList = new ArrayList<>(); | |
| while (entries.hasMoreElements()) { | |
| entryList.add(entries.nextElement()); | |
| } | |
| return entryList.stream(); | |
| return super.stream().map(e -> (ZipEntry) e); |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getLastModified() method always returns 0, which is not accurate. It should return the actual last modified time from the ZipEntry. Consider using file.getTime() to get the correct timestamp.
| return 0; | |
| return file.getTime(); |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new GetZipFile class and its inner ZipJavaFileObject class lack any documentation. Adding class-level and method-level JavaDoc comments would help other developers understand the purpose of these classes and how they should be used, especially since this is handling a complex edge case with custom URL handlers.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,10 +23,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import javax.tools.JavaFileObject; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.net.JarURLConnection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.net.URI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.net.URL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.net.URLDecoder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.net.*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.net.*; | |
| import java.net.JarURLConnection; | |
| import java.net.URI; | |
| import java.net.URL; | |
| import java.net.URLConnection; | |
| import java.net.URLDecoder; |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unused import java.util.function.Consumer should be removed as it's not used anywhere in the code.
| import java.util.function.Consumer; |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment line contains Chinese text: "获取 authority(host:port) + path + query + fragment" (translation: "Get authority (host:port) + path + query + fragment"). Consider translating to English for consistency with international development practices.
| //是否可以在硬盘上找到对应的文件 | |
| try { | |
| URI uri1 = new URI(jarUri); | |
| // 获取 authority(host:port) + path + query + fragment | |
| // Check whether the corresponding file can be found on the local file system | |
| try { | |
| URI uri1 = new URI(jarUri); | |
| // Get authority (host:port) + path + query + fragment from the URI |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name uri1 is not descriptive. Consider using a more meaningful name like parsedJarUri or jarFileUri to clearly indicate what this URI represents.
| URI uri1 = new URI(jarUri); | |
| // 获取 authority(host:port) + path + query + fragment | |
| StringBuilder sb = new StringBuilder(); | |
| if (uri1.getAuthority() != null) { | |
| sb.append(uri1.getAuthority()); | |
| } | |
| if (uri1.getPath() != null) { | |
| sb.append(uri1.getPath()); | |
| } | |
| if (uri1.getQuery() != null) { | |
| sb.append('?').append(uri1.getQuery()); | |
| } | |
| if (uri1.getFragment() != null) { | |
| sb.append('#').append(uri1.getFragment()); | |
| URI parsedJarUri = new URI(jarUri); | |
| // 获取 authority(host:port) + path + query + fragment | |
| StringBuilder sb = new StringBuilder(); | |
| if (parsedJarUri.getAuthority() != null) { | |
| sb.append(parsedJarUri.getAuthority()); | |
| } | |
| if (parsedJarUri.getPath() != null) { | |
| sb.append(parsedJarUri.getPath()); | |
| } | |
| if (parsedJarUri.getQuery() != null) { | |
| sb.append('?').append(parsedJarUri.getQuery()); | |
| } | |
| if (parsedJarUri.getFragment() != null) { | |
| sb.append('#').append(parsedJarUri.getFragment()); |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter name e in the forEach lambda is not descriptive. Consider using a more meaningful name like zipEntry or entry to improve code readability.
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GetZipFile resource is not properly closed. The ZipFile is created but never closed, which can lead to resource leaks and file handle exhaustion. Consider using try-with-resources or ensuring the file is closed after processing.
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a URISyntaxException handler. The new URI(jarUri) call on line 132 can throw URISyntaxException, but the catch block on line 171 only catches SecurityException. This means URISyntaxException will be caught by the outer catch block on line 175, which may not provide the appropriate error message for URI syntax issues.
| }catch (SecurityException e) { | |
| } catch (URISyntaxException e) { | |
| throw new RuntimeException("Invalid URI syntax for jarUri: " + jarUri, e); | |
| } catch (SecurityException e) { |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new fallback logic (lines 129-174) for handling non-JarURLConnection cases lacks test coverage. Given the complexity of the URI parsing and file system access logic, and the fact that this addresses a specific issue with Minecraft Forge's custom URL handlers, adding test cases for this code path would help ensure it works correctly and prevent regressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unused import
javax.lang.model.element.Modifieris imported but never used in this class.