docs: @FFDCIgnore({ NoContentException.class, Exception.class })
      public <T> T doReadEntity(Class<T> cls, Type t, Annotation[] anns, boolean closeAfterRead) throws ProcessingException, IllegalStateException {
  
          checkEntityIsClosed();
          //defect 211445, according to javadoc, should close when is not buffered.
          boolean shouldClose = !this.entityBufferred;
  
          if (lastEntity != null && cls.isAssignableFrom(lastEntity.getClass())
              && !(lastEntity instanceof InputStream)) {
              return cls.cast(lastEntity);
          }
  
          MediaType mediaType = getMediaType();
          if (mediaType == null) {
              mediaType = MediaType.WILDCARD_TYPE;
          }
  
          // the stream is available if entity is IS or
          // message contains XMLStreamReader or Reader
          boolean entityStreamAvailable = entityStreamAvailable();
          InputStream entityStream = null;
          if (!entityStreamAvailable) {
              // try create a stream if the entity is String or Number
              entityStream = convertEntityToStreamIfPossible();
              entityStreamAvailable = entityStream != null;
          } else if (entity instanceof InputStream) {
              entityStream = InputStream.class.cast(entity);
          } else {
              Message inMessage = getResponseMessage();
              Reader reader = inMessage.getContent(Reader.class);
              if (reader != null) {
                  entityStream = InputStream.class.cast(new ReaderInputStream(reader));
              }
          }
  
          // we need to check for readers even if no IS is set - the readers may still do it
          List<ReaderInterceptor> readers = outMessage == null ? null : ProviderFactory.getInstance(outMessage).createMessageBodyReaderInterceptor(cls, t, anns, mediaType,
                                                                                                                                                   outMessage, entityStreamAvailable,
                                                                                                                                                   null);
  
          if (readers != null) {
              try {
                  if (entityBufferred) {
                      InputStream.class.cast(entity).reset();
                  }
  
                  Message responseMessage = getResponseMessage();
                  responseMessage.put(Message.PROTOCOL_HEADERS, getHeaders());
  
                  lastEntity = JAXRSUtils.readFromMessageBodyReader(readers, cls, t,
                                                                    anns,
                                                                    entityStream,
                                                                    mediaType,
                                                                    responseMessage);
                  //defect 211445, close the entity after readEntity is called.
                  T tCastLastEntity = castLastEntity();
                  shouldClose = shouldClose && !(tCastLastEntity instanceof Closeable) && !(tCastLastEntity instanceof Source);
                  if (closeAfterRead && shouldClose)
                      close();
                  return tCastLastEntity;
              } catch (NoContentException ex) {
                  //defect 209656, when content is empty, return null instead of throw exception to pass CTS
                  //defect 212788, check if basic type. Basic type throw exception, else return null.
                  if (isBasicType(cls)) {
                      autoClose(cls, true);
                      reportMessageHandlerProblem("MSG_READER_PROBLEM", cls, mediaType, ex);
                  } else {
                      if (closeAfterRead && shouldClose)
                          close();
                      return null;
                  }
              } catch (Exception ex) {
                  autoClose(cls, true);
                  reportMessageHandlerProblem("MSG_READER_PROBLEM", cls, mediaType, ex);
              }
          } else if (entity != null && cls.isAssignableFrom(entity.getClass())) {
              lastEntity = entity;
              return castLastEntity();
          } else if (entityStreamAvailable) {
              reportMessageHandlerProblem("NO_MSG_READER", cls, mediaType, null);
          }
  
          throw new IllegalStateException("The entity is not backed by an input stream, entity class is : "
                                          + (entity != null ? entity.getClass().getName() : cls.getName()));
  
      }