[NEW BUG] jdk.internal.module.Checks seems to miss a check for 'var'

Christoph Dreis christoph.dreis at freenet.de
Fri Mar 22 11:30:11 UTC 2019


Hi,

I recently stumbled upon jdk.internal.module.Checks and was wondering if you
could help me understanding if I face a bug. The mentioned class has a
private static field containing a list of reserved keywords. When checking
the list for completeness, I noticed that "var" seems to be missing here and
I wonder if it should be added. I found two relevant links in the spec
regarding that:

The first one being the list of keywords:
https://docs.oracle.com/javase/specs/jls/se11/html/jls-3.html#jls-3.9
      "var is not a keyword, but rather an identifier with special meaning
as the type of a local variable declaration"

And secondly the section about identifiers
https://docs.oracle.com/javase/specs/jls/se11/html/jls-3.html#jls-3.8
     "Type identifiers are used in certain contexts involving the
declaration or use of types. For example, the name of a class must be a
TypeIdentifier, so it is illegal to declare a class named var."

Especially the last one got me thinking. Imagine a call like the following:

	Checks.isClassName("var")

This will currently return true, while it should return false, shouldn't it?

I attached a patch for what I think should be implemented. And if my
assumption turns out to be correct, I'd be more than happy if this is
sponsored and earns a "contributed-by". If this is already known or an
incorrect assumption, I'm very sorry for bothering you guys.

Cheers,
Christoph

========= PATCH ==========
diff -r 96c45aa61056
src/java.base/share/classes/jdk/internal/module/Checks.java
--- a/src/java.base/share/classes/jdk/internal/module/Checks.java       Fri
Mar 22 13:42:45 2019 +0530
+++ b/src/java.base/share/classes/jdk/internal/module/Checks.java       Fri
Mar 22 12:24:27 2019 +0100
@@ -242,6 +242,7 @@
             "true",
             "false",
             "null",
+            "var",
             "_"
     );
 }



More information about the core-libs-dev mailing list