On Wed, 26 Apr 2023 22:10:20 GMT, Mandy Chung <mch...@openjdk.org> wrote:
> What is the issue of calling `ClassDesc.ofDescriptor` for arrays? Users would have to check the obtained string from a `CONSTANT_Class_info` and call different factory methods, which feels a bit... weird to me, like calling `a == null ? Optional.empty() : Optional.of(a)` instead of `Optional.ofNullable(a)`, and `CONSTANT_Class_info` can be seen as an API provided by the class file as it's defined in the JVMS. > Have you considered `internalName` to return an `Optional`? That might be feasible. I initially fear that this may hurt performance-sensitive operations, but now I think as long as we can make `isArray()` or `isClassOrInterface()` constant-foldable (I don't think `String::startsWith` is optimized that far, so might need to check `charAt(0)`), we can still make obtaining the internal name fast. public Optional<String> internalName() { if (!isClassOrInterface()) // assuming constant-foldable return Optional.of(descriptorString); var internalName = this.internalName; // caching if (internalName != null) return Optional.of(internalName); return Optional.of(this.internalName = descriptorString.substring(1, descriptorString.length() - 1)); } ------------- PR Comment: https://git.openjdk.org/jdk/pull/13598#issuecomment-1524187441