Migrate descriptor parsing from generics to BytecodeDescriptor

XMLWordPrintable

    • Type: CSR
    • Resolution: Unresolved
    • Priority: P4
    • 26
    • Component/s: core-libs
    • None
    • behavioral
    • low
    • Hide
      These are invalid signature strings that would have been filtered by bytecode generators. They originally caused exceptions and users are anticipated to fix them eagerly instead of depend on the exceptional behaviors. Users who handled the `ClassCastException` or `MalformedParameterizedTypeException` likely already handled the newly thrown `GenericSignatureFormatError` or `TypeNotPresentException` too.
      Show
      These are invalid signature strings that would have been filtered by bytecode generators. They originally caused exceptions and users are anticipated to fix them eagerly instead of depend on the exceptional behaviors. Users who handled the `ClassCastException` or `MalformedParameterizedTypeException` likely already handled the newly thrown `GenericSignatureFormatError` or `TypeNotPresentException` too.
    • Java API
    • Implementation

      Summary

      Migrate the field and method descriptor parsing from the generic signature parser to the descriptor parser used by java.lang.invoke package.

      Problem

      The existing generic signature parser is currently in minimal maintenance, and will likely retire when new signature format is introduced.

      The generic parser is also unaware of the difference between descriptor strings and generic signatures:

      • Ljava/util/Optional<*>; is the class or interface java.util.Optional with a wildcard type argument in generics; it is a class or interface with the simple name Optional<?> in descriptors.
      • TT; is a type variable named T in generics; this is not a valid descriptor string.
      • L<Stuff>; is not valid in generics; this is a class or interface named <Stuff> in descriptors.

      Solution

      Migrate to the descriptor parser used by java.lang.invoke, which is widely tested and maintained and largely behaviorally compatible, and is better for dedicated descriptor parsing.

      They both throw TypeNotPresentException for valid class or interface names that are not present; the IllegalArgumentException thrown by the descriptor parser can be converted back to a GenericSignatureFormatError as thrown by the existing generic parser.

      Specification

      None. This is purely behavioral.

      There are some significant behavioral changes:

      1. Some valid generic signature strings like TT; that caused ClassCastException are now rejected with a GenericSignatureFormatError;
      2. Some valid generic signature strings like Ljava/util/Optional<*>; that caused ClassCastException are now accepted but may cause TypeNotPresentException;
      3. Some invalid generic signature stirngs like L<Stuff>; that caused GenericSignatureFormatError are now accepted but may cause TypeNotPresentException;
      4. Some valid generic signature strings like Ljava/lang/Object<*>; that caused MalformedParameterizedTypeException are now accepted but may cause TypeNotPresentException.

            Assignee:
            Chen Liang
            Reporter:
            Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: