11/*
2- * Copyright (c) 2001, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2001, 2024 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
4444/* URL jar file is a common JarFile subtype used for JarURLConnection */
4545public class URLJarFile extends JarFile {
4646
47- /*
48- * Interface to be able to call retrieve() in plugin if
49- * this variable is set.
50- */
51- private static URLJarFileCallBack callback = null ;
52-
5347 /* Controller of the Jar File's closing */
5448 private URLJarFileCloseController closeController = null ;
5549
5650 private Manifest superMan ;
5751 private Attributes superAttr ;
5852 private Map <String , Attributes > superEntries ;
5953
60- static JarFile getJarFile (URL url ) throws IOException {
61- return getJarFile (url , null );
62- }
63-
6454 static JarFile getJarFile (URL url , URLJarFileCloseController closeController ) throws IOException {
6555 if (isFileURL (url )) {
6656 Runtime .Version version = "runtime" .equals (url .getRef ())
@@ -72,23 +62,6 @@ static JarFile getJarFile(URL url, URLJarFileCloseController closeController) th
7262 }
7363 }
7464
75- /*
76- * Changed modifier from private to public in order to be able
77- * to instantiate URLJarFile from sun.plugin package.
78- */
79- public URLJarFile (File file ) throws IOException {
80- this (file , null );
81- }
82-
83- /*
84- * Changed modifier from private to public in order to be able
85- * to instantiate URLJarFile from sun.plugin package.
86- */
87- public URLJarFile (File file , URLJarFileCloseController closeController ) throws IOException {
88- super (file , true , ZipFile .OPEN_READ | ZipFile .OPEN_DELETE );
89- this .closeController = closeController ;
90- }
91-
9265 private URLJarFile (File file , URLJarFileCloseController closeController , Runtime .Version version )
9366 throws IOException {
9467 super (file , true , ZipFile .OPEN_READ | ZipFile .OPEN_DELETE , version );
@@ -188,63 +161,39 @@ private synchronized boolean isSuperMan() throws IOException {
188161 */
189162 @ SuppressWarnings ("removal" )
190163 private static JarFile retrieve (final URL url , final URLJarFileCloseController closeController ) throws IOException {
191- /*
192- * See if interface is set, then call retrieve function of the class
193- * that implements URLJarFileCallBack interface (sun.plugin - to
194- * handle the cache failure for JARJAR file.)
195- */
196- if (callback != null )
197- {
198- return callback .retrieve (url );
199- }
200-
201- else
202- {
203-
204- JarFile result = null ;
205- Runtime .Version version = "runtime" .equals (url .getRef ())
206- ? JarFile .runtimeVersion ()
207- : JarFile .baseVersion ();
208-
209- /* get the stream before asserting privileges */
210- try (final InputStream in = url .openConnection ().getInputStream ()) {
211- result = AccessController .doPrivileged (
212- new PrivilegedExceptionAction <>() {
213- public JarFile run () throws IOException {
214- Path tmpFile = Files .createTempFile ("jar_cache" , null );
164+ JarFile result = null ;
165+ Runtime .Version version = "runtime" .equals (url .getRef ())
166+ ? JarFile .runtimeVersion ()
167+ : JarFile .baseVersion ();
168+
169+ /* get the stream before asserting privileges */
170+ try (final InputStream in = url .openConnection ().getInputStream ()) {
171+ result = AccessController .doPrivileged (
172+ new PrivilegedExceptionAction <>() {
173+ public JarFile run () throws IOException {
174+ Path tmpFile = Files .createTempFile ("jar_cache" , null );
175+ try {
176+ Files .copy (in , tmpFile , StandardCopyOption .REPLACE_EXISTING );
177+ JarFile jarFile = new URLJarFile (tmpFile .toFile (), closeController , version );
178+ tmpFile .toFile ().deleteOnExit ();
179+ return jarFile ;
180+ } catch (Throwable thr ) {
215181 try {
216- Files .copy (in , tmpFile , StandardCopyOption .REPLACE_EXISTING );
217- JarFile jarFile = new URLJarFile (tmpFile .toFile (), closeController , version );
218- tmpFile .toFile ().deleteOnExit ();
219- return jarFile ;
220- } catch (Throwable thr ) {
221- try {
222- Files .delete (tmpFile );
223- } catch (IOException ioe ) {
224- thr .addSuppressed (ioe );
225- }
226- throw thr ;
182+ Files .delete (tmpFile );
183+ } catch (IOException ioe ) {
184+ thr .addSuppressed (ioe );
227185 }
186+ throw thr ;
228187 }
229- });
230- } catch (PrivilegedActionException pae ) {
231- throw (IOException ) pae .getException ();
232- }
233-
234- return result ;
188+ }
189+ });
190+ } catch (PrivilegedActionException pae ) {
191+ throw (IOException ) pae .getException ();
235192 }
236- }
237193
238- /*
239- * Set the call back interface to call retrieve function in sun.plugin
240- * package if plugin is running.
241- */
242- public static void setCallBack (URLJarFileCallBack cb )
243- {
244- callback = cb ;
194+ return result ;
245195 }
246196
247-
248197 private class URLJarFileEntry extends JarEntry {
249198 private final JarEntry je ;
250199
0 commit comments