This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 216450 - Jar file locked when opened in editor
Summary: Jar file locked when opened in editor
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 7.2
Hardware: PC Windows XP
: P2 normal (vote)
Assignee: Tomas Hurka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-06 18:01 UTC by bht
Modified: 2012-10-12 10:05 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bht 2012-08-06 18:01:03 UTC
How to reproduce:

- Copy a jar file e.g. your jdk dir\lib\dt.jar to a temp location
- Open the temporary copy of dt.jar in the IDE
- In the explorer window, expand and open javax.swing.BoxBeanInfo.class in the editor
- Close the file in the editor
- Close dt.jar in the explorer window
- In Windows Explorer, delete the temporary copy of dt.jar

Expected behavior:
The file should be deleted

Actual behaviour:
Error deleting File or Folder
Cannot delete dt: It is being used by another person or program.
Close any programs that might be using the file and try again.

The problem can be solve by closing the IDE.

Just an idea what could cause this:

Closing a stream may not be sufficient to close a file. If the URL opened has scheme "jar",
Java SE, once it opens the JAR to resolve such a URL, leaves the JAR open by default even after the stream has been closed. 

instead of using url.openStream, e.g. in JarURLConnection, use

final URLConnection cnx = url.openConnection(url);
cnx.setUseCaches(false);
in = cnx.getInputStream();

(and of course close the stream).
Comment 1 Tomas Zezula 2012-08-08 13:37:26 UTC
I've tried:
1) Copied a jar file to /tmp
2) In the Favorites window I've opened the jar and opened a class for it
3) Closed the classfile and collapsed the jar
4) lsof returns the file as opened
Comment 2 Jaroslav Tulach 2012-08-10 16:56:56 UTC
Well, collapsing a view of a JAR file has no relation with "closing". The JAR is still in use and it is OK from Windows to reject its deletion.
Comment 3 bht 2012-08-10 18:49:08 UTC
(In reply to comment #2)
> Well, collapsing a view of a JAR file has no relation with "closing". The JAR
> is still in use and it is OK from Windows to reject its deletion.

Technically this may be correct but please how do I get the jar file closed without closing the IDE?
Comment 4 bht 2012-08-10 19:02:07 UTC
The failure to close occurs only after the editor opened a class file contained in it.

If I just open the jar file as an explorer view then that view seems to close it anyway because I can delete it afterwards.

If I however open it with the editor and close it the editor then it appears that the editor opens the jar file again and fails to close it.
Comment 5 Jaroslav Tulach 2012-08-24 15:41:40 UTC
I am not able to find out why the JVM holds a reference to the JAR file. I tried to search all java.io.FileDescriptor instances using OQL - none has the right fd field. I tried all instances of java.util.zip.ZipFile - none has the right name of the file.

The last thing that comes to my mind is to use dtrace on Solaris and see the stacktrace when the JAR is opened...
Comment 6 Tomas Hurka 2012-09-03 12:19:12 UTC
Problem is in
org/netbeans/modules/java/classfile/CodeGenerator$TreeBuilder.visitType(Ljavax/lang/model/element/TypeElement;Ljava/lang/Void;)Lcom/sun/source/tree/Tree
which does not close InputStream passed to ClassFile.read().
Comment 7 Jan Lahoda 2012-09-03 13:14:34 UTC
Thanks for finding the place, and sorry for causing that:
http://hg.netbeans.org/jet-main/rev/0d5c0f1af15b
Comment 8 Quality Engineering 2012-09-04 01:11:46 UTC
Integrated into 'main-golden', will be available in build *201209040001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/0d5c0f1af15b
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #216450: must close the Stream after finished reading from it.
Comment 9 Tomas Hurka 2012-10-03 15:13:32 UTC
Verified in NetBeans Dev 201210020001
Comment 10 Tomas Hurka 2012-10-03 15:17:37 UTC
Transplanted to release72 branch:


changeset:   242457:3154340a61f2                                                                                                                                                     
branch:      release72
parent:      242451:09c238295917
user:        Jan Lahoda <jlahoda@netbeans.org>
date:        Mon Sep 03 15:09:24 2012 +0200
summary:     #216450: must close the Stream after finished reading from it.

changeset:   242458:54a9767139be
branch:      release72
tag:         tip
user:        Tomas Hurka <thurka@netbeans.org>
date:        Wed Oct 03 17:15:25 2012 +0200
summary:     spec. version increased after transplant of bug #216450 (3154340a61f2)
Comment 11 Quality Engineering 2012-10-10 14:18:57 UTC
Integrated into 'releases', will be available in build *201210100934* or newer. Wait for official and publicly available build.
Changeset: http://hg.netbeans.org/releases/rev/3154340a61f2
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #216450: must close the Stream after finished reading from it.
(transplanted from 0d5c0f1af15baf4e21b45b3323d5495d1dc03f68)
Comment 12 Jiri Prox 2012-10-11 14:04:19 UTC
Unfortunately I can still reproduce this.
Steps to reproduce are exactly same as in description.


Product Version: NetBeans IDE Dev (Build 201210030002)
Java: 1.7.0_10-ea; Java HotSpot(TM) 64-Bit Server VM 23.6-b03
System: Windows 7 version 6.1 running on amd64; Cp1250; en_US (nb)
User directory: C:\Users\jprox\AppData\Roaming\NetBeans\dev
Cache directory: C:\Users\jprox\AppData\Local\NetBeans\Cache\dev

and


Product Version: NetBeans IDE 7.2.1 (Build 201210100934)
Java: 1.7.0_10-ea; Java HotSpot(TM) 64-Bit Server VM 23.6-b03
System: Windows 7 version 6.1 running on amd64; Cp1250; en_US (nb)
User directory: C:\Users\jprox\AppData\Roaming\NetBeans\7.2.1
Cache directory: C:\Users\jprox\AppData\Local\NetBeans\Cache\7.2.1
Comment 13 Jiri Prox 2012-10-12 10:04:07 UTC
Sorry, it was my mistake, some other instance of IDE kept the file. The fix is ok