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

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

On a second thought, the patched posted is not safe as it is used for
package name checks as well.

And while var is not a type-identifier, it is still an identifier. So it
should be possible to name your package "var" if I'm not mistaken.

The question remains. Should we change anything here in the Checks class?

> 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
> 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
> 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
> 	Checks.isClassName("var")
> This will currently return true, while it should return false, shouldn't
> 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
> Mar 22 13:42:45 2019 +0530
> +++ b/src/java.base/share/classes/jdk/internal/module/Checks.java
> Mar 22 12:24:27 2019 +0100
> @@ -242,6 +242,7 @@
>              "true",
>              "false",
>              "null",
> +            "var",
>              "_"
>      );
>  }

More information about the core-libs-dev mailing list