RFR: 8318812: LauncherHelper.checkAndLoadMain closes jar file that's about to be re-opened
Christian Stein
cstein at openjdk.org
Wed Feb 14 15:46:05 UTC 2024
On Wed, 14 Feb 2024 11:40:16 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> Please review this PR that makes the launcher helper keep a reference to the executable JAR file active after extracting the name of the main class and returning it as Class instance. Now, when loading classes from the JAR file, it hasn't to be re-opened.
>
> src/java.base/share/classes/sun/launcher/LauncherHelper.java line 593:
>
>> 591: }
>> 592:
>> 593: private static String getMainClassFromJar(String jarname, JarFile jarFile) {
>
> Can you check if the "jarname" parameter can be dropped, the error handling in this method should be able to use jarFile.getName().
`String jarname` is filled by the caller with the value of `String what`, and therefore contains the entire path to the executable JAR file. Using only `jarFile.getName()` will prevent any parent directories from being noted in error messages; which might affect some tests
> src/java.base/share/classes/sun/launcher/LauncherHelper.java line 823:
>
>> 821: // get the class name
>> 822: String cn;
>> 823: // store the jar file
>
> "store the jar file" is a confusing comment to add. I think what you want to say is that the JarFile will put the underlying file in the JarFile/ZipFile cache and this will avoid needing to re-parse the manifest when the JAR file is opened on the class path, triggered by Class.forName.
Updating to use the precise description.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17843#discussion_r1489688919
PR Review Comment: https://git.openjdk.org/jdk/pull/17843#discussion_r1489689891
More information about the core-libs-dev
mailing list