Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8321415

ClassSignature should have superclass and superinterfaces as ClassTypeSig

    XMLWordPrintable

Details

    • source, binary
    • low
    • Class-File API is in Preview, which allows source/binary incompatible changes to the API. If users are simply accessing the signatures via the ClassTypeSig interface without using factory methods, the same code may be source-compatible.
    • Java API
    • SE

    Description

      Summary

      Represent the superclass and superinterfaces in ClassTypeSig with ClassTypeSig and List<ClassTypeSig>.

      Problem

      In JVMS 4.7.9.1, the superclass and superinterfaces of a class signature is required to be class signatures. Yet Class-File API uses a RefTypeSig, allowing potentially invalid signatures, like using an array class as a superclass.

      Solution

      Change the superclass and superinterfaces in ClassTypeSig from RefTypeSig and List<RefTypeSig> to ClassTypeSig and List<ClassTypeSig>.

      Specification

      --- a/src/java.base/share/classes/java/lang/classfile/ClassSignature.java
      +++ b/src/java.base/share/classes/java/lang/classfile/ClassSignature.java
      @@ -42,10 +42,10 @@ public sealed interface ClassSignature
           List<Signature.TypeParam> typeParameters();
      
           /** {@return the instantiation of the superclass in this signature} */
      -    Signature.RefTypeSig superclassSignature();
      +    Signature.ClassTypeSig superclassSignature();
      
           /** {@return the instantiation of the interfaces in this signature} */
      -    List<Signature.RefTypeSig> superinterfaceSignatures();
      +    List<Signature.ClassTypeSig> superinterfaceSignatures();
      
           /** {@return the raw signature string} */
           String signatureString();
      @@ -55,8 +55,8 @@ public sealed interface ClassSignature
            * @param superclassSignature the superclass
            * @param superinterfaceSignatures the interfaces
            */
      -    public static ClassSignature of(Signature.RefTypeSig superclassSignature,
      -                                    Signature.RefTypeSig... superinterfaceSignatures) {
      +    public static ClassSignature of(Signature.ClassTypeSig superclassSignature,
      +                                    Signature.ClassTypeSig... superinterfaceSignatures) {
               return of(List.of(), superclassSignature, superinterfaceSignatures);
           }
      
      @@ -67,8 +67,8 @@ public static ClassSignature of(Signature.RefTypeSig superclassSignature,
            * @param superinterfaceSignatures the interfaces
            */
           public static ClassSignature of(List<Signature.TypeParam> typeParameters,
      -                                    Signature.RefTypeSig superclassSignature,
      -                                    Signature.RefTypeSig... superinterfaceSignatures) {
      +                                    Signature.ClassTypeSig superclassSignature,
      +                                    Signature.ClassTypeSig... superinterfaceSignatures) {
               return new SignaturesImpl.ClassSignatureImpl(
                       requireNonNull(typeParameters),
                       requireNonNull(superclassSignature),

      Attachments

        Issue Links

          Activity

            People

              liach Chen Liang
              liach Chen Liang
              Adam Sotona
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: