users@hk2.java.net

Re: RuntimeException silently turned into Nullpointer Exception

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Fri, 03 Jan 2014 01:11:30 -0500

On 03/01/2014 12:58 AM, buko wrote:
>
> Discovered another case where hk2 is silently suppressing an
> exception/hiding it behind another exception. Each time this happens
> it's pretty frustrating because a good chunk of time must be spent
> debugging the container trying to figure out what, if anything it's doing.
>
> In this case I created a Factory implementation that throws a
> RuntimeException from the Factory#provide() method. (It's not clear,
> BTW, why Factory#provide() doesn't allow an exception to be thrown.)
> The exception boils up to Cache#compute(final K key). The
> catch(ExecutionException ex) block then rethrows the exception to
> SingletonContext#findOrCreate catch(RuntimeException re) block. This
> method rethrows the exception in a MultiException and calls
> RuntimeException.getCause(). MultiException(Throwable th) ctor
> requires that Throwable not be null but it does not check that
> condition. It just assumes it and the result is a NullPointerException
> that very effectively hides the underlying exception. If
> MultiException simply did a check it might raise a more informative
> error that preserves the stack trace. It's also not clear why
> SingletonContext#findOrCreate doesn't preserve the runtimeException
> and instead chooses to unwrap it by calling RuntimeException.getCause().
>
> One issue to get around this would be better logging. hk2 seems to do
> little logging that doesn't provide much insight into what's happening
> or what went wrong.

Very good detective work! I suggest filing a bug report and sharing it
with the mailing list: https://java.net/jira/browse/HK2

Gili