JDK-6587593 : (sl) Service provider lookup causes JAR files to be locked on Windows
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_nt
  • CPU: generic
  • Submitted: 2007-07-31
  • Updated: 2018-07-17
  • Resolved: 2018-07-17
Related Reports
Relates :  
Relates :  
Description
The WAR file attached to the bug report at

  https://glassfish.dev.java.net/issues/show_bug.cgi?id=2375
  ("Autodeploying multiple times causes OutOfMemoryError in PermGen")

contains the following resources:

misto2544: jar -tvf TableTest.war
     0 Tue Jul 31 15:29:22 PDT 2007 META-INF/
   104 Tue Jul 31 15:29:20 PDT 2007 META-INF/MANIFEST.MF
     0 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/
     0 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/classes/
     0 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/classes/test/
     0 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/lib/
  1150 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/classes/test/Bean.class
   829 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/classes/test/Data.class
  4070 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/classes/test/Expand.class
  1169 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/classes/test/ExpandTag.class
   753 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/faces-config.xml
1262524 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/lib/ajax4jsf.jar
188671 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/lib/commons-beanutils-1.7.0.jar
559366 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/lib/commons-collections-3.1.jar
168446 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/lib/commons-digester-1.6.jar
 38015 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/lib/commons-logging-1.0.4.jar
   715 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/sun-web.xml
  1260 Tue Jul 31 15:29:20 PDT 2007 WEB-INF/test.tld
  1865 Tue Jul 31 15:29:22 PDT 2007 WEB-INF/web.xml
   452 Tue Jul 31 15:29:22 PDT 2007 index.jsp
  1283 Tue Jul 31 15:29:22 PDT 2007 table.jsp

The bundled (in /WEB-INF/lib)

  ajax4jsf.jar

provides a service implementation for

  javax.imageio.spi.ImageWriterSpi

by bundling a resource:

  META-INF/services/javax.imageio.spi.ImageWriterSpi

with these contents:

  org.ajax4jsf.framework.util.image.imageio.gif.GIFImageWriterSpi

where

  org.ajax4jsf.framework.util.image.imageio.gif.GIFImageWriterSpi

is bundled inside

  ajax4jsf.jar

The service provider lookup implemented by sun.misc.Service prevents ajax4jsf.jar from being released (causing it to be locked on Windows) when the bundling TableTest.war is undeployed.

Comments
This issue is JDK 8 and older. There are no current plans to backport the changes to disable the JAR file caching in the older releases so closing this bug.
17-07-2018

ServiceLoader does not use the JAR file cache in JDK 9 so I will add "9-na" to this issue.
01-06-2017

EVALUATION The suggested fix, to both java.util.ServiceLoader and sun.misc.Service, addresses the problem.
14-02-2008

SUGGESTED FIX In the impl of sun.misc.Service.parse(): private static Iterator parse(Class service, URL u, Set returned) throws ServiceConfigurationError { InputStream in = null; BufferedReader r = null; ArrayList names = new ArrayList(); try { in = u.openStream(); r = new BufferedReader(new InputStreamReader(in, "utf-8")); int lc = 1; while ((lc = parseLine(service, u, r, lc, names, returned)) >= 0); } catch (IOException x) { fail(service, ": " + x); } finally { try { if (r != null) r.close(); if (in != null) in.close(); } catch (IOException y) { fail(service, ": " + y); } } return names.iterator(); } change this line: in = u.openStream(); to: URLConnection uc = u.openConnection(); uc.setUseCaches(false); in = uc.getInputStream();
31-07-2007