Skip to content
Permalink
Browse files
unwrap InvocationTargetException
Otherwise we will get a java.lang.reflect.UndeclaredThrowableException
  • Loading branch information
struberg committed Apr 28, 2021
1 parent 7e873bd commit f4ae25ccb44f58d1229221f1f93553ebc7d0b553
Showing 1 changed file with 11 additions and 0 deletions.
@@ -27,6 +27,7 @@
import javax.enterprise.inject.spi.Extension;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -110,6 +111,16 @@ public BeanManager getBeanManager() {
try {
return (BeanManager) CDI_GET_BEAN_MANAGER_METHOD.invoke(CDI_CURRENT_METHOD.invoke(null));
} catch (Exception e) {
if (e instanceof IllegalStateException) {
// all fine, that just means that no CDI container is available right now.
// Maybe we only have the spec jar in the classpath, but no container is started?
return null;
}
if (e instanceof InvocationTargetException && e.getCause() instanceof IllegalStateException) {
// same as above
return null;
}

throw new BatchRuntimeException("unable to resolve BeanManager");
}
}

0 comments on commit f4ae25c

Please sign in to comment.