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

时间:2015-06-30 13:54:28

标签: jsf glassfish jndi omnifaces

I replaced all of my JNDI lookups with JNDI.lookup() method because it seemed convenient, dealt with dynamic return types, etc. All was great...but now I just noticed that the checked exceptions that I had to catch before are no longer there.

I assumed this was because it would have just returned null if the JNDI variable didn't exist but it doesn't. It now just throws an unchecked exception.

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

I created a bug for this on the omnifaces website: https://github.com/omnifaces/omnifaces/issues/141

Not sure if this is intended behavior or not.

1 个答案:

答案 0 :(得分:1)

  

有没有办法只为非存在的变量返回null?

它为NameNotFoundException执行此操作。这个问题不是在OmniFaces中,而是在环境中,在您的特定情况下是GlassFish 4.1。它意外地将NameNotFoundException包裹在另一个NamingException中,从而导致基础NameNotFoundException漏洞并绕过return null条件。

根据Exceptions#is() this comment实用程序方法帮助解决了这个问题。它将在OmniFaces 2.2中提供。