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

Handling of error types in supertypes

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • None

      This is generally related to JDK-8055219, which discussed handling of ErrorType in javax.lang.model.util.Types.

      I think it would be valuable for the specification of Types#directSupertypes and TypeElement#getInterfacese to discuss how ErrorType is handled.

      Consider an example like:

      import java.util.List;
      class T implements List<String>, NoSuch {}

      Calling Types#directSupertypes on T omits the ErrorType:

      directSupertypes(T) = [java.lang.Object, java.util.List<java.lang.String>]

      on the other hand, TypeElement#getInterfaces includes the ErrorType:

      getInterfaces() = java.util.List<java.lang.String>,NoSuch

      I found it surprising that they weren't consistent, but I also don't have concerns wtih the current behaviour, mostly it wasn't clear to me what to expect and I think it would be valuable for the specification to address that the behaviour is.

      ---

      import java.util.Set;
      import javax.annotation.processing.AbstractProcessor;
      import javax.annotation.processing.RoundEnvironment;
      import javax.annotation.processing.SupportedAnnotationTypes;
      import javax.lang.model.SourceVersion;
      import javax.lang.model.element.TypeElement;
      import javax.tools.Diagnostic;

      @SupportedAnnotationTypes("*")
      public class P extends AbstractProcessor {
        @Override
        public SourceVersion getSupportedSourceVersion() {
          return SourceVersion.latestSupported();
        }

        private boolean first = true;

        @Override
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
          if (!first) {
            return false;
          }
          first = false;
          TypeElement e = processingEnv.getElementUtils().getTypeElement("T");
          processingEnv
              .getMessager()
              .printMessage(
                  Diagnostic.Kind.ERROR,
                  String.format("%s.getInterfaces() = %s", e, e.getInterfaces()),
                  e);

          processingEnv
              .getMessager()
              .printMessage(
                  Diagnostic.Kind.ERROR,
                  String.format(
                      "directSupertypes(%s) = %s",
                      e.asType(), processingEnv.getTypeUtils().directSupertypes(e.asType())),
                  e);
          return false;
        }
      }

            Unassigned Unassigned
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: