Skip to content

Commit

Permalink
add null check for when CDI is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-confino committed Oct 2, 2024
1 parent e368739 commit b3bab87
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public CDI<Object> getCDI() {
}

//If we can't get CDI from the thread context metadata, fallback to matching the TCCL against apps.
if (cdi == null) {
if (runtimeFactory != null && cdi == null) {
Collection<Application> applications = runtimeFactory.getApplications();

ClassLoader tccl = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> {
Expand All @@ -194,17 +194,24 @@ public CDI<Object> getCDI() {
for (Application application : applications) {
if (application.getClassLoader().equals(tccl)
|| classLoadingService.isThreadContextClassLoaderForAppClassLoader(tccl, application.getClassLoader())) {
WebSphereCDIDeployment deploymnet = cdiContainer.getDeployment(application);
cdi = deploymnet.getCDI();
deployment = cdiContainer.getDeployment(application);
//We found the correct app but it has no deployment, this happens if CDI is disabled.
if (deployment != null) {
cdi = deployment.getCDI();
}
break;
}
}
}

if (cdi == null) {
if (deployment == null) {
throw new IllegalStateException("Could not find deployment");
}

if (cdi == null) {
throw new IllegalStateException("Could not find CDI");
}

return cdi;
}

Expand Down

0 comments on commit b3bab87

Please sign in to comment.