Skip to content

Why EncodeException's message is not nullable in 1st constructor but nullable in 2nd constructor? #2973

@vvy

Description

@vvy
  /**
   * @param message the reason for the failure.
   */
  public EncodeException(String message) {
    super(-1, checkNotNull(message, "message"));
  }

  /**
   * @param message possibly null reason for the failure.
   * @param cause the cause of the error.
   */
  public EncodeException(String message, Throwable cause) {
    super(-1, message, checkNotNull(cause, "cause"));
  }

It seems like that EncodeException's message is not null in 1st constructor,
BUT, when a exception with null message is throw (eg. new NegativeArraySizeException() ), you will get a null message EncodeException, such as below codes in RequestTemplateFactoryResolver.

    protected RequestTemplate resolve(Object[] argv, RequestTemplate mutable,
                                      Map<String, Object> variables) {
      Object body = argv[metadata.bodyIndex()];
      checkArgument(body != null, "Body parameter %s was null", metadata.bodyIndex());
      try {
        encoder.encode(body, metadata.bodyType(), mutable);
      } catch (EncodeException e) {
        throw e;
      } catch (RuntimeException e) {
        throw new EncodeException(e.getMessage(), e);
      }
      return super.resolve(argv, mutable, variables);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions