eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
690 stars 351 forks source link

NullPointerException throws in org.glassfish.jersey.model.internal.ComponentBag #5064

Open tracy0x01 opened 2 years ago

tracy0x01 commented 2 years ago

Hi, we have a healthcheck failed caused by this NullPointerException:

client .target(buildHealthCheckUri()) .request() ..

then NullPointerException throws in org.glassfish.jersey.model.internal.ComponentBag: public static final Predicate<ContractProvider> BINDERS_ONLY = model -> model.getContracts().contains(Binder.class);

called by this:

public Set<Object> getInstances(final Predicate<ContractProvider> filter) {

    return instancesView.stream()
                        .filter(input -> {
                            final ContractProvider model = getModel(input.getClass());
                            return filter.test(model);
                        })
                        .collect(Collectors.toCollection(LinkedHashSet::new));
}

Jersey 2.35 Java 11

image

jansupol commented 2 years ago

Interesting...

From model.getContracts() either model.getContracts() is null, which it cannot be, it must be Collections.emptyMap() the worst. Or model is null, which it cannot be, because instancesView is built from the models...

can you substract a reproducer from your code?

tracy0x01 commented 2 years ago

That occasionally occurs in production environments. And I can't reproduce in my local env. It's a simple use case, the code is like below, and the NullPointerException throws in request()

public boolean healthcheck() {
    Response response = null;
    try {
      response =
          client
              .target(buildHealthCheckUri())
              .request()
              .property(ClientProperties.READ_TIMEOUT, 5000)
              .get();
      return response.getStatus() == 200;
    } finally {
      if (response != null) {
        response.close();
      }
    }
    return false;
  }
tracy0x01 commented 2 years ago

hi @jansupol do we have any chance to reproduce and fix this? I still can't reproduce it. 😢