Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 340427

Summary: JarBasedJSFResource locks JARs
Product: [WebTools] Java Server Faces Reporter: Yury Kats <yurykats>
Component: CoreAssignee: Ian Trimble <ian.trimble>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: raghunathan.srinivasan
Version: 3.2.3Flags: raghunathan.srinivasan: iplog+
Target Milestone: 3.3 M7   
Hardware: PC   
OS: Windows XP   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=240394
Whiteboard:
Attachments:
Description Flags
primefaces jar
none
Patch none

Description Yury Kats CLA 2011-03-18 10:10:29 EDT
Created attachment 191507 [details]
primefaces jar

A customer of an adopter product reported a problem with JSF jar files in workspace being locked. This, in turns, causes problems with project deletion and refactoring -- neither of the operations is possible because jsf jars can not be deleted.

In the scenario the customer imports an existing project with JSF jars in WEB-INF/lib. Once import completes, some of the jars are locked and can not be deleted. An example of such jar would be primefaces-2.2.1 (attached here). I believe, from my investigation, that the jar needs to have /resources/ folder in it, to cause the lock.

My debugging shows the following:

org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.FaceletTagIndex#DefaultProjectTaglibDescriptorFactory creates various locators/resolvers in its create() method.

I've commented them out one by one and found that the jars are locked only when the following is created:
            resourceLocators
                    .add(new JarBasedJSFResourceLocator(Collections.EMPTY_LIST,
                            new CopyOnWriteArrayList<ILocatorChangeListener>(),
                            new DefaultJarLocator(Collections
                                    .singletonList(new AlwaysMatcher()),
                                    new JavaCoreMediator()),
                            new ContentTypeResolver()));

Looking deeper into JarBasedJSFResourceLocator, the jar seems to be locked only when the following is executed inside its processJar method:

            tagLibsFound.add(new JarBasedJSFResource(
                    libRes, jarUrl, _contentTypeResolver));

It would seem that something in that JarBasedJSFResource class holds on to the Jar and thus prevents it from being closed.

Looking at JarBasedJSFResource I found this method:

    public boolean isAccessible()
    {
        JarFile jarFile = null;
        try
        {
            jarFile = getJarFile();
            if (jarFile != null)
            {
                final ZipEntry entry = getZipEntry(jarFile);
                return entry != null;
            }
        } finally
        {
            if (jarFile != null)
            {
//                try
//                {
//                    // TODO
////                    jarFile.close();
//                } /*catch (IOException e)
//                {
//                    // fall-through.
//                }*/
            }
        }
        return false;
    }

In here the JarFile is created, but never closed! 

I can't tell why jarFile.close() was commented out with a TODO comment, but it certainly causes the JAR file to be locked. Once I uncommented jarFile.close(), the jars were no longer locked.
Comment 1 Yury Kats CLA 2011-03-18 10:14:08 EDT
Created attachment 191508 [details]
Patch
Comment 2 Yury Kats CLA 2011-03-18 10:14:48 EDT
Patch is attached.

Please consider for quick turn around. Thanks.
Comment 3 Raghunathan Srinivasan CLA 2011-03-18 14:06:06 EDT
Thanks for the patch.Do you need this for 3.2.4 also?
Comment 4 Yury Kats CLA 2011-03-18 14:07:06 EDT
(In reply to comment #3)
> Do you need this for 3.2.4 also?

Yes.
Comment 5 Ian Trimble CLA 2011-03-18 14:53:50 EDT
The patch looks good. I can find no reason why we would not close the JarFile instance. All related test suites run green.

Fix submitted to HEAD (3.3) at 2011/03/18 11:52AM PDT.
Comment 6 Raghunathan Srinivasan CLA 2011-03-18 19:57:24 EDT
Patch applied and released on 3.2.4
Comment 7 Raghunathan Srinivasan CLA 2011-03-18 20:24:57 EDT
Released to 3.3 and 3.2.4 streams
Comment 8 Yury Kats CLA 2011-03-18 20:27:08 EDT
Thanks!