Ambiguity in specification around variables of reference types

Robbe Pincket robbepincket at live.be
Thu Aug 11 22:39:29 UTC 2022


Hi

I came across "4.12.2. Variables of Reference Type" today and I had
a small concern. The way the section is worded it feels a bit like
some of the rules override some of the other rules.

* A variable of a class type T can hold a null reference or a reference
  to an instance of class T or of any class that is a subclass of T.
* A variable of type Object can hold a null reference or a reference to
  any object, whether it is an instance of a class or an array.

Now one can argue that the first rule doesn't (explicitly) exclude
that variables can hold references to arrays, but then it also
wouldn't exclude the case where a variable of the type Integer can't
hold a String. As such it feels fair to say that the references listed
are all the valid references it can store, and that the later rule is
overriding the specification of the earlier rule.

However this raises another issue

* If T is a reference type, then a variable of type "array of T" can
  hold a null reference or a reference to any array of
  type "array of S" such that type S is a subclass or
  subinterface of type T.
* A variable of type Object[] can hold a reference to an array of any
  reference type.

If we were to say that here the second rule overrides the first rule,
then it would be illegal for a variable of the type `Object[]` to
contain null.


Greetings
Robbe Pincket
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jls-jvms-spec-comments/attachments/20220811/959a07e1/attachment-0001.htm>


More information about the jls-jvms-spec-comments mailing list