什么是 omnifaces JNDI.lookup 没有 NamingException 的已检查异常?

What does omnifaces JNDI.lookup not have a checked exception for NamingException?

我用 JNDI.lookup() 方法替换了我所有的 JNDI 查找,因为它看起来很方便,处理动态 return 类型等。一切都很好......但现在我只是注意到我之前必须捕获的已检查异常不再存在。

我假设这是因为如果 JNDI 变量不存在但它不存在,它会 returned null。它现在只是抛出一个未经检查的异常。

知道为什么吗?有没有一种方法可以 return 为不存在的变量设置 null?

我在 omnifaces 网站上为此创建了一个错误:https://github.com/omnifaces/omnifaces/issues/141

不确定这是否是有意为之的行为。

Is there a way of just returning null for non-existant variables instead?

NameNotFoundException 这样做。问题不在 OmniFaces 中,而在环境中,在您的特定情况下是 GlassFish 4.1。它意外地将 NameNotFoundException 包裹在另一个 NamingException 中,从而导致底层 NameNotFoundException 滑过并绕过 return null 条件。

这已在 Exceptions#is() utility method as per this comment 的帮助下得到修复。它将在 OmniFaces 2.2 中可用。