Bug 562436 - ASTParser.createBindings fails if Editor opens concurrently

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>
1 file changed
tree: a08f38e2bc9a2dc6d647c6b0d853e9760edba4ab
  1. modules/
  2. org.eclipse.jdt.annotation/
  3. org.eclipse.jdt.annotation_v1/
  4. org.eclipse.jdt.apt.core/
  5. org.eclipse.jdt.apt.pluggable.core/
  6. org.eclipse.jdt.apt.pluggable.tests/
  7. org.eclipse.jdt.apt.tests/
  8. org.eclipse.jdt.apt.ui/
  9. org.eclipse.jdt.compiler.apt/
  10. org.eclipse.jdt.compiler.apt.tests/
  11. org.eclipse.jdt.compiler.tool/
  12. org.eclipse.jdt.compiler.tool.tests/
  13. org.eclipse.jdt.core/
  14. org.eclipse.jdt.core.ecj.validation/
  15. org.eclipse.jdt.core.formatterapp/
  16. org.eclipse.jdt.core.internal.tools/
  17. org.eclipse.jdt.core.tests.builder/
  18. org.eclipse.jdt.core.tests.compiler/
  19. org.eclipse.jdt.core.tests.model/
  20. org.eclipse.jdt.core.tests.performance/
  21. org.eclipse.jdt.tests.latestBREE/
  22. tests-pom/
  23. .gitignore
  24. CONTRIBUTING
  25. LICENSE
  26. NOTICE
  27. pom.xml
  28. README.md
README.md

JDT Core

This is the core part of Eclipse's Java development tools. It contains the non-UI support for compiling and working with Java code, including the following:

  • an incremental or batch Java compiler that can run standalone or as part of the Eclipse IDE
  • Java source and class file indexer and search infrastructure
  • a Java source code formatter
  • APIs for code assist, access to the AST and structured manipulation of Java source.

For more information and important links, refer to the [JDT wiki page] 1 or the [JDT project overview page] 2.

License

Eclipse Public License (EPL) v2.0