Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response.protocolVersoin may be null causing NPEs #2314

Open
edudar opened this issue Jan 29, 2024 · 0 comments
Open

Response.protocolVersoin may be null causing NPEs #2314

edudar opened this issue Jan 29, 2024 · 0 comments

Comments

@edudar
Copy link
Contributor

edudar commented Jan 29, 2024

Response constructor does not indicate that protocolVersion can be null (I think it'd be good to use at least some version of @Nullable instead of a comment)

  private Response(Builder builder) {
    ...
    this.reason = builder.reason; // nullable
    this.headers = caseInsensitiveCopyOf(builder.headers);
    this.body = builder.body; // nullable
    this.protocolVersion = builder.protocolVersion;
  }

and it's used with no null checks here

  @Override
  public String toString() {
    StringBuilder builder =
        new StringBuilder(protocolVersion.toString()).append(" ").append(status);
    ...
  }

It can be null, however:

feign.okhttp.OkHttpClient {
  toFeignResponse() {
    return feign.Response.builder()
        .protocolVersion(enumForName(ProtocolVersion.class, response.protocol()))
  }

here, enumForName may return null, causing NPE down the line.

  public static <T extends Enum<?>> T enumForName(Class<T> enumClass, Object object) {
    String name = (nonNull(object)) ? object.toString() : null;
    for (T enumItem : enumClass.getEnumConstants()) {
      if (enumItem.name().equalsIgnoreCase(name) || enumItem.toString().equalsIgnoreCase(name)) {
        return enumItem;
      }
    }
    return null;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant