Skip to content
Permalink
Browse files
GERONIMO-6753 fix NPE on the CDI extension for produced checks. Bean …
…manager can't resolve the bean because we are using the producer class instead of the Healthcheck type
  • Loading branch information
jeanouii committed Sep 24, 2019
1 parent 1332321 commit 46a9a437656f7df7b1933e138760a3a858efe667
Showing 1 changed file with 20 additions and 13 deletions.
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,7 +34,6 @@
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessBean;
import javax.enterprise.util.AnnotationLiteral;

import org.apache.geronimo.microprofile.common.registry.HealthChecksRegistry;
import org.eclipse.microprofile.health.Health;
import org.eclipse.microprofile.health.HealthCheck;
@@ -63,6 +62,7 @@ void findChecks(@Observes final ProcessBean<?> bean) {
if (!bean.getBean().getTypes().contains(HealthCheck.class)) {
return;
}
// deprecated - use @Liveness or @Readiness
if (bean.getAnnotated().isAnnotationPresent(Health.class)) {
beans.add(bean.getBean());
}
@@ -76,17 +76,20 @@ void findChecks(@Observes final ProcessBean<?> bean) {

void start(@Observes final AfterDeploymentValidation afterDeploymentValidation, final BeanManager beanManager) {
liveness = livenessBeans.stream()
.map(it -> lookup(it, beanManager))
.collect(toList());
.map(it -> lookup(it, beanManager))
.collect(toList());

readiness = readinessBeans.stream()
.map(it -> lookup(it, beanManager))
.collect(toList());
.map(it -> lookup(it, beanManager))
.collect(toList());

// per spec, checks has everything including liveness and readiness
checks = Stream.concat(Stream.concat(
beans.stream()
.map(it -> lookup(it, beanManager)),
liveness.stream()),
readiness.stream())
beans.stream().map(it -> lookup(it, beanManager)),
liveness.stream()),
readiness.stream())
.collect(toList());

started = true;
}

@@ -128,8 +131,12 @@ public boolean isReady() {
}

private HealthCheck lookup(final Bean<?> bean, final BeanManager manager) {
final Class<?> type = bean.getBeanClass() == null ? HealthCheck.class : bean.getBeanClass();
final Set<Bean<?>> beans = manager.getBeans(type, bean.getQualifiers().toArray(new Annotation[0]));
// if this is not an instance of HealthCheck, then it's a producer (not sure it's enough)
final Class<?> type = bean.getBeanClass() == null || !HealthCheck.class.isAssignableFrom(bean.getBeanClass())
? HealthCheck.class
: bean.getBeanClass();
final Set<Annotation> qualifiers = bean.getQualifiers();
final Set<Bean<?>> beans = manager.getBeans(type, qualifiers.toArray(new Annotation[qualifiers.size()]));
final Bean<?> resolvedBean = manager.resolve(beans);
final CreationalContext<Object> creationalContext = manager.createCreationalContext(null);
if (!manager.isNormalScope(resolvedBean.getScope())) {

0 comments on commit 46a9a43

Please sign in to comment.