Bug 543604 - [9] Error when hovering a HashMap

The bug was observed under the following conditions:

1. Debug a snippet with a map variable on Java 9 or above JRE.
2. Enable "Show Logical Structure" in the variables view.
3. Expand a local variable or a parameter of type java.util.Map or
inheriting, either in the debug hover in the Java source editor or in
the Variables view.
4. Observe an error text instead of content.

The error is caused by JDT debug attempting to compile a snippet as
follows:

package java.util;
abstract class Map___ implements java.util.Map {
void ___run() throws Throwable {
return entrySet().toArray();
}
}

This snippet is constructed in order to validate whether the expression
"return entrySet().toArray();" compiles in the context of the current
breakpoint.

On Java 9 and above, this snippet is not legal. java.util is already
contained in the JRE libraries; its not possible to define a package
like this and compile it without extra compile arguments (in particular
--patch-module).

To fix this problem, we add a special compile mode to JDT core, used by
JDT debug. When in this mode, the JDT compiler will ignore split package
problems. The compiled expression "return entrySet().toArray();" is then
used for evaluation against the underlying java.util.Map, which does
work with JRE 9+.

Change-Id: Iaaf3edde97e5006aecc8792df9da789b8eddbfce
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
6 files changed
tree: 417840d69162c4914a2bb51c97f4d3146a0d3e05
  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.internal.tools/
  16. org.eclipse.jdt.core.tests.builder/
  17. org.eclipse.jdt.core.tests.compiler/
  18. org.eclipse.jdt.core.tests.model/
  19. org.eclipse.jdt.core.tests.performance/
  20. tests-pom/
  21. .gitignore
  22. CONTRIBUTING
  23. LICENSE
  24. NOTICE
  25. pom.xml
  26. 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) v1.0