java.lang.constant.ClassDesc and TypeDescriptor for hidden class??
mandy.chung at oracle.com
Wed Apr 15 16:53:32 UTC 2020
On 4/15/20 3:37 AM, forax at univ-mlv.fr wrote:
> Given that it's a field descriptor, it that can be passed to a library
> like ASM and the bug will be "hidden" until you get a VerifyError far
> from where the problem has occurred and with an error message people
> will not understand because it's not described in the JVMS.
> The class descriptor of an hidden class doesn't exist from the JVM
> spec POV.
BTW, the result string is *not* a field descriptor but rather a human
readable string. The proposal is to change `TypeDescriptor` say that
it has a field/method descriptor iff it can be described nominally.
There may have `TypeDescriptor` objects that cannot be described
nominally and in which case `descriptorString` produces a human-readable
but unresolvable string. This does not propose to change JVMS nor
define a valid type descriptor for hidden class.
The only unpleasant property for this proposal is that `Class`
implements TypeDescriptor and TypeDescriptor.OfField but not all `Class`
objects have field descriptors.
Existing libraries that have the assumption that Class always has a type
descriptor will need update to support hidden classes in any of the
options. Option (a) just saves the effort for the libraries as JDK does
it for them but only applicable to the library that depends on
`Class::descriptorString` which I expect not many such existing libraries.
OTOH I expect that ASM should never return a Type object for a hidden
class. For example Type::getType(Class<?> c) may simply throw an
exception if c is a hidden class.
I assume that Type::getObjectType and Type::getType(String
typeDescriptor) and Type::getMethodType(String methodDescriptor) already
validates if the given descriptor string is a valid field/method
descriptor and throws IAE?
Indeed ASM will need some update to support hidden classes as its name
cannot be referenced in the bytecode. Similarly for other libraries.
More information about the valhalla-dev