Index: CloneableEditorSupport.java =================================================================== RCS file: /cvs/openide/src/org/openide/text/CloneableEditorSupport.java,v retrieving revision 1.119 diff -u -r1.119 CloneableEditorSupport.java --- CloneableEditorSupport.java 11 Mar 2004 14:01:18 -0000 1.119 +++ CloneableEditorSupport.java 12 Mar 2004 14:40:12 -0000 @@ -137,12 +137,6 @@ /** position manager */ private PositionRef.Manager positionManager; - /* [pnejedly] This lock is shared by PositionRef.Manager and this class - * to prevent PR.M modifications while the document is just loaded - * or freed. See #40766. - */ - Object docStateLock = new Object(); - /** The string which will be appended to the name of top component * when top component becomes modified */ // protected String modifiedAppendix = " *"; // NOI18N @@ -409,9 +403,8 @@ // where another threads may operate already if (!runningInAtomicLock) { runningInAtomicLock = true; - synchronized (docStateLock) { // [pnejedly] See #40766 - NbDocument.runAtomic(docToLoad, this); - } + NbDocument.runAtomic(docToLoad, this); + // Add undoable listener after atomic change has finished synchronized (getLock()) { if (doc == docToLoad) { // if document still valid @@ -1468,7 +1461,6 @@ /** Clears all data from memory. */ private void closeDocument () { - synchronized(docStateLock) { // [pnejedly] See #40766 synchronized (getLock()) { while (true) { switch (documentStatus) { @@ -1487,7 +1479,6 @@ } } } - } } /** Is called under getLock () to close the document. @@ -1773,6 +1764,8 @@ return listener; } + // [pnejedly]: helper for 40766 test + void howToReproduceDeadlock40766(boolean beforeLock) {} /** Default editor kit. @@ -1808,8 +1801,7 @@ } } - // [pnejedly]: helper for 40766 test - void howToReproduceDeadlock40766(boolean beforeLock) {} + /** The listener that this support uses to communicate with Index: PositionRef.java =================================================================== RCS file: /cvs/openide/src/org/openide/text/PositionRef.java,v retrieving revision 1.54 diff -u -r1.54 PositionRef.java --- PositionRef.java 11 Mar 2004 09:43:54 -0000 1.54 +++ PositionRef.java 12 Mar 2004 14:40:12 -0000 @@ -194,6 +194,8 @@ /** the document for this manager or null if the manager is not in memory */ transient private StyledDocument doc; + /** document that this thread should use */ + private static ThreadLocal DOCUMENT = new ThreadLocal (); static final long serialVersionUID =-4374030124265110801L; @@ -273,6 +275,20 @@ doc = null; } + /** Gets the document this object should work on. + * @return docoument or null + */ + private StyledDocument getDoc () { + Object d = DOCUMENT.get (); + if (d instanceof StyledDocument) { + return (StyledDocument)d; + } + if (d == this) { + return null; + } + return this.doc; + } + /** Puts/gets positions to/from memory. It also provides full * pass sweep of the data structure (inlined in the code). * @param toMemory puts positions to memory if true, @@ -363,10 +379,7 @@ pos.kind.toMemory(pos.insertAfter)); } */ - // [pnejedly] needed to prevent doc variable modification while adding position, #40766 - synchronized(support.docStateLock) { - kind = (Kind)new DocumentRenderer(DocumentRenderer.ADD_POSITION, pos).renderToObject(); - } + kind = (Kind)new DocumentRenderer(DocumentRenderer.ADD_POSITION, pos).renderToObject(); checkQueue(); return kind; @@ -510,7 +523,7 @@ "Illegal PositionKind: " + pos + "[offset=" // NOI18N + offset + ",line=" // NOI18N + line + ",column=" + column + "] in " // NOI18N - + doc + " used by " + support + "." // NOI18N + + getDoc () + " used by " + support + "." // NOI18N ); } @@ -563,7 +576,7 @@ "Illegal OutKind[offset=" // NOI18N + offset + ",line=" // NOI18N + line + ",column=" + column + "] in " // NOI18N - + doc + " used by " + support + "." // NOI18N + + getDoc () + " used by " + support + "." // NOI18N ); } @@ -602,7 +615,7 @@ "Illegal OutKind[offset=" // NOI18N + offset + ",line=" // NOI18N + line + ",column=" + column + "] in " // NOI18N - + doc + " used by " + support + "." // NOI18N + + getDoc () + " used by " + support + "." // NOI18N ); } @@ -624,7 +637,7 @@ if(offset < 0) { throw new IndexOutOfBoundsException( "Illegal OffsetKind[offset=" // NOI18N - + offset + "] in " + doc + " used by " // NOI18N + + offset + "] in " + getDoc () + " used by " // NOI18N + support + "." // NOI18N ); } @@ -658,7 +671,7 @@ if(offset < 0) { throw new IOException( "Illegal OffsetKind[offset=" // NOI18N - + offset + "] in " + doc + " used by " // NOI18N + + offset + "] in " + getDoc () + " used by " // NOI18N + support + "." // NOI18N ); } @@ -683,7 +696,7 @@ throw new IndexOutOfBoundsException( "Illegal LineKind[line=" // NOI18N + line + ",column=" + column + "] in " // NOI18N - + doc + " used by " + support + "." // NOI18N + + getDoc () + " used by " + support + "." // NOI18N ); } @@ -739,7 +752,7 @@ throw new IOException( "Illegal LineKind[line=" // NOI18N + line + ",column=" + column + "] in " // NOI18N - + doc + " used by " + support + "." // NOI18N + + getDoc () + " used by " + support + "." // NOI18N ); } @@ -864,10 +877,18 @@ } void render() { - if (doc != null) { - doc.render(this); - } else { - this.run(); + StyledDocument d = getDoc (); + Object prev = DOCUMENT.get (); + try { + if (d != null) { + DOCUMENT.set (d); + d.render(this); + } else { + DOCUMENT.set (Manager.this); + this.run(); + } + } finally { + DOCUMENT.set (prev); } } @@ -925,7 +946,7 @@ try { int line = argKind.getLine(); int col = argKind.getColumn(); - Element lineRoot = NbDocument.findLineRootElement(doc); + Element lineRoot = NbDocument.findLineRootElement(getDoc ()); if (line < lineRoot.getElementCount()) { Element lineElem = lineRoot.getElement(line); int lineStartOffset = lineElem.getStartOffset(); @@ -942,20 +963,20 @@ } try { - p = NbDocument.createPosition (doc, offset, + p = NbDocument.createPosition (getDoc (), offset, argInsertAfter ? Position.Bias.Forward : Position.Bias.Backward); } catch (BadLocationException e) { - p = doc.getEndPosition (); + p = getDoc ().getEndPosition (); } retObject = (PositionKind)new PositionKind (p); break; } case POSITION_KIND_GET_LINE: { - retInt = NbDocument.findLineNumber(doc, argKind.getOffset()); + retInt = NbDocument.findLineNumber(getDoc (), argKind.getOffset()); break; } case POSITION_KIND_GET_COLUMN: { - retInt = NbDocument.findLineColumn(doc, argKind.getOffset()); + retInt = NbDocument.findLineColumn(getDoc (), argKind.getOffset()); break; } case POSITION_KIND_WRITE: @@ -980,13 +1001,13 @@ case LINE_KIND_TO_MEMORY: { // try to find the right position try { - retObject = NbDocument.createPosition (doc, - NbDocument.findLineOffset (doc, argLine) + argColumn, + retObject = NbDocument.createPosition (getDoc (), + NbDocument.findLineOffset (getDoc (), argLine) + argColumn, argInsertAfter ? Position.Bias.Forward : Position.Bias.Backward); } catch (BadLocationException e) { - retObject = doc.getEndPosition (); + retObject = getDoc ().getEndPosition (); } catch (IndexOutOfBoundsException e) { - retObject = doc.getEndPosition(); + retObject = getDoc ().getEndPosition(); } break; } @@ -1024,7 +1045,7 @@ support.howToReproduceDeadlock40766(false); head.next = new ChainItem(argPos, queue, head.next); - retObject = (doc == null ? + retObject = (getDoc () == null ? argPos.kind : argPos.kind.toMemory(argPos.insertAfter)); }