diff options
author | Simeon Andreev | 2020-05-06 13:33:21 +0000 |
---|---|---|
committer | Andrey Loskutov | 2020-06-09 19:41:37 +0000 |
commit | 4660e32eca67ecb827126d309213e16a72cf15c4 (patch) | |
tree | a08f38e2bc9a2dc6d647c6b0d853e9760edba4ab | |
parent | 66e28a4cdde7ad38f8bbf4da340b280bc8930555 (diff) | |
download | eclipse.jdt.core-4660e32eca67ecb827126d309213e16a72cf15c4.tar.gz eclipse.jdt.core-4660e32eca67ecb827126d309213e16a72cf15c4.tar.xz eclipse.jdt.core-4660e32eca67ecb827126d309213e16a72cf15c4.zip |
Bug 562436 - ASTParser.createBindings fails if Editor opens concurrentlyI20200609-1800
CompilationUnit.getContents() and CompilationUnit.discardWorkingCopy()
can be called concurrently, causing the getContents() method to throw an
exception. This in turn can cause ASTParser.createBindings() to fail.
In particular, its possible for CompilationUnit.getContents() to
retrieve an open buffer via BufferManager.getBuffer(). This buffer can
then be closed, before CompilationUnit.getContents() calls
IBuffer.getCharacters(). As a result, getCharacters() returns null and
CompilationUnit.getContents() throws an exception.
With this change CompilationUnit.getContents() resorts to reading the
compilation unit file directly, in case the compilation unit buffer was
closed after obtaining it, but before the buffers characters were
retrieved.
Change-Id: I01772e638bf4160defc63196629a710f214181c5
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
-rw-r--r-- | org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java index e30ae7ac69..cbdaac5bf6 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java @@ -659,7 +659,11 @@ public ICompilationUnit getCompilationUnit() { @Override public char[] getContents() { IBuffer buffer = getBufferManager().getBuffer(this); - if (buffer == null) { + char[] contents = null; + if (buffer != null) { + contents = buffer.getCharacters(); + } + if (buffer == null || (!isWorkingCopy() && contents == null && buffer.isClosed())) { // no need to force opening of CU to get the content // also this cannot be a working copy, as its buffer is never closed while the working copy is alive IFile file = (IFile) getResource(); @@ -686,7 +690,6 @@ public char[] getContents() { return CharOperation.NO_CHAR; } } - char[] contents = buffer.getCharacters(); if (contents == null) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=129814 if (JavaModelManager.getJavaModelManager().abortOnMissingSource.get() == Boolean.TRUE) { IOException ioException = new IOException(Messages.buffer_closed); |