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

Types.directSupertypes() incorrectly returns java.lang.Object as the super type of interfaces

XMLWordPrintable

    • b08
    • Verified

      According to the Java spec and Class.getSuperclass(), interfaces don't have java.lang.Object as their super class.

      Types.directSupertypes( TypeMirror of an interface ) incorrectly returns java.lang.Object as the direct super type.

      ------ Processor------
      import java.util.*;
      import javax.annotation.processing.*;
      import javax.lang.model.element.*;
      import javax.lang.model.type.*;
      import javax.lang.model.util.*;
      import static javax.lang.model.SourceVersion.*;
      import static javax.lang.model.type.TypeKind.*;

      @SupportedAnnotationTypes("*")
      @SupportedSourceVersion(RELEASE_7)
      public class Processor extends AbstractProcessor {
          public void init(ProcessingEnvironment penv) {
              super.init(penv);
          }
          public boolean process(Set<? extends TypeElement> typeElementSet,
                  RoundEnvironment renv) {
              for ( TypeElement typeElement : typeElementSet )
              {
                Set<? extends Element> elements = renv.getElementsAnnotatedWith( typeElement );
                for ( Element element : elements )
                {
                  TypeMirror type = element.asType();
                  System.out.println( "Type: " + type.toString() );
                  List<? extends TypeMirror> supers = processingEnv.getTypeUtils().directSupertypes( type );

                  for ( TypeMirror superClass : supers )
                    System.out.println( "Super class: " + superClass.toString() );
                }
              }
              return true ;
          }
      }
      -------------- Interface ---
      @SuppressWarnings("all")
      class Interface1 {}
      --------------------
      javac -classpath . Processor.java
      javac -classpath . -processor Processor Interface1.java

      Will print:
      Type: Interface1
      Super class: java.lang.Object

            pgovereau Paul Govereau (Inactive)
            kbronkho Keimpe Bronkhorst (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: