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.

View | Details | Raw Unified | Return to bug 116891
Collapse All | Expand All

(-)openide/fs/src/org/openide/filesystems/FileLock.java (-28 lines)
Lines 18-28 Link Here
18
 */
18
 */
19
package org.openide.filesystems;
19
package org.openide.filesystems;
20
20
21
import java.io.ByteArrayOutputStream;
22
import java.util.logging.Level;
23
import java.util.logging.Logger;
24
21
25
26
/** Represents an acquired lock on a <code>FileObject</code>.
22
/** Represents an acquired lock on a <code>FileObject</code>.
27
* Typical usage includes locking the file in the editor on first
23
* Typical usage includes locking the file in the editor on first
28
* modification, and then using this object to ensure exclusive access when
24
* modification, and then using this object to ensure exclusive access when
Lines 55-64 Link Here
55
51
56
    /** Determines if lock is locked or if it was released. */
52
    /** Determines if lock is locked or if it was released. */
57
    private boolean locked = true;
53
    private boolean locked = true;
58
    private Throwable lockedBy;
59
54
60
    public FileLock() {
55
    public FileLock() {
61
        assert (lockedBy = new Throwable()) != null;
62
    }
56
    }
63
57
64
    // ===============================================================================
58
    // ===============================================================================
Lines 94-119 Link Here
94
    public boolean isValid() {
88
    public boolean isValid() {
95
        return locked;
89
        return locked;
96
    }
90
    }
97
98
    /** Finalize this object. Calls {@link #releaseLock} to release the lock if the program
99
    * for some reason failed to.
100
    */
101
    public void finalize() {
102
        assert (!isValid()) : assertMessageForInvalidLocks();
103
        releaseLock();
104
    }
91
    }
105
106
    private String assertMessageForInvalidLocks() {
107
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
108
109
        if (lockedBy != null) {
110
            Logger.getLogger(FileLock.class.getName()).log(Level.WARNING, null,
111
                              new Exception("Not released lock for file: " +
112
                                            toString() +
113
                                            " (traped in finalizer)").initCause(lockedBy));//NOI18N
114
        }
115
116
        releaseLock();
117
        return bos.toString();
118
    }
119
}
(-)openide/fs/src/org/openide/filesystems/FileObject.java (-8 / +10 lines)
Lines 633-650 Link Here
633
    * @exception IllegalArgumentException if <code>this</code> is not a folder
633
    * @exception IllegalArgumentException if <code>this</code> is not a folder
634
    */
634
    */
635
    public FileObject getFileObject(String relativePath) {
635
    public FileObject getFileObject(String relativePath) {
636
        if (relativePath.startsWith("/")) {
636
        if ("".equals(relativePath)) { //NOI18N
637
            return this;
638
        }
639
        if (relativePath.length() > 0 && relativePath.charAt(0) == '/') {
637
            relativePath = relativePath.substring(1);
640
            relativePath = relativePath.substring(1);
638
        }
641
        }
639
640
        FileObject myObj = this;
642
        FileObject myObj = this;
641
        StringTokenizer st = new StringTokenizer(relativePath, "/");
643
        String[] paths = relativePath.split ("/");
642
644
        for (String nameExt : paths) {
643
        while ((myObj != null) && st.hasMoreTokens()) {
645
            if (myObj == null) {
644
            String nameExt = st.nextToken();
646
                break;
645
            myObj = myObj.getFileObject(nameExt, null);
646
        }
647
        }
647
648
            myObj = myObj.getFileObject (nameExt, null);
649
        }
648
        return myObj;
650
        return myObj;
649
    }
651
    }
650
652
(-)openide/fs/src/org/openide/filesystems/XMLFileSystem.java (-4 / +26 lines)
Lines 1107-1114 Link Here
1107
        private static final int ATTR_CODE = "attr".hashCode(); // NOI18N
1107
        private static final int ATTR_CODE = "attr".hashCode(); // NOI18N
1108
        private ResourceElem rootElem;
1108
        private ResourceElem rootElem;
1109
        private boolean validate = false;
1109
        private boolean validate = false;
1110
        Stack<ResourceElem> resElemStack = new Stack<ResourceElem>();
1110
        UnsyncStack<ResourceElem> resElemStack = new UnsyncStack<ResourceElem>();
1111
        Stack<String> elementStack = new Stack<String>();
1111
        UnsyncStack<String> elementStack = new UnsyncStack<String>();
1112
        URL urlContext;
1112
        URL urlContext;
1113
        private Map dtdMap;
1113
        private Map dtdMap;
1114
        private ResourceElem topRE;
1114
        private ResourceElem topRE;
Lines 1260-1270 Link Here
1260
1260
1261
        public void startDocument() throws SAXException {
1261
        public void startDocument() throws SAXException {
1262
            super.startDocument();
1262
            super.startDocument();
1263
            resElemStack = new Stack<ResourceElem>();
1263
            resElemStack = new UnsyncStack<ResourceElem>();
1264
            resElemStack.push(rootElem);
1264
            resElemStack.push(rootElem);
1265
            topRE = rootElem;
1265
            topRE = rootElem;
1266
1266
1267
            elementStack = new Stack<String>();
1267
            elementStack = new UnsyncStack<String>();
1268
            elementStack.push("<root>"); // NOI18N
1268
            elementStack.push("<root>"); // NOI18N
1269
        }
1269
        }
1270
1270
Lines 1274-1277 Link Here
1274
            elementStack.pop();
1274
            elementStack.pop();
1275
        }
1275
        }
1276
    }
1276
    }
1277
    
1278
    //Replaces use of java.util.Stack, which is synchronized
1279
    private static final class UnsyncStack<T> extends ArrayList<T> {
1280
        public void push (T t) {
1281
            super.add (0, t);
1277
}
1282
}
1283
        
1284
        public T pop () {
1285
            if (isEmpty()) {
1286
                return null;
1287
            } else {
1288
                T result = get(0);
1289
                remove (0);
1290
                return result;
1291
            }
1292
        }
1293
        
1294
        public T peek() {
1295
            return isEmpty() ? null : get(0);
1296
        }
1297
        
1298
    }
1299
}

Return to bug 116891