getPermittedSubclasses() on j.l.rClass returning an array of ClassDesc

Dan Smith daniel.smith at oracle.com
Sat May 9 19:59:08 UTC 2020


> On May 9, 2020, at 8:53 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
> 
> It's not just that it is _inconvenient_ to return the Class, "because of class loading."  It may not be _possible_, as the class may not be there, but we would still like to be able to reflect what the class says.  

My two cents: it really does seem like this is a different API, a lower-level view into the contents of a class file.

There are lots of ways that a class might be usable while not being fully "reflectable", in the sense that certain reflection methods will fail. These failures might include missing classes or inconsistent attributes involving any of: annotations, inner classes, descriptors, signatures, and nestmates.

The core reflection API has historically been happy to ignore those corner cases. Instead, it's designed for the typical situation where everything is consistent and available. You're somewhat uncomfortable with this design choice, which is fair, but maybe a better long-term path to getting to a less brittle API is to design a new, lower-level API, rather than trying to slowly introduce a new way of doing things into java.lang.Class.


More information about the amber-spec-observers mailing list