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

Types.asElement() returns null for ErrorType

XMLWordPrintable

      The specs for the utility method javax.lang.model.util.Types.asElement(TypeMirror) says:
      -----------------------------------------------------------------------------------
      Returns the element corresponding to a type.
      The type may be a DeclaredType or TypeVariable.
      Returns null if the type is not one with a corresponding element.
      -----------------------------------------------------------------------------------

      However the method returns null if invoked with the ErrorType instance.

      Such behavior looks contradicting to the specs because:
      1. ErrorType extends DeclaredType
      2. ErrorType does have a corresponding element which can be retrieved using:

              if (typeMirror.getKind() == TypeKind.ERROR) {
                  element = ((ErrorType) typeMirror).asElement();
              }

            jjg Jonathan Gibbons
            ashusher Alexander Shusherov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: