Skip to content

Commit

Permalink
Improve the serviceability of JsonbComponentInstanceCreatorFactory.
Browse files Browse the repository at this point in the history
Previously the handling of ReflectiveOperationException in JsonbComponentInstanceCreatorFactory.getBeanManager() would check if the exception had a cause. Then it would incorrectly log the message from the top level exception. This would result in the ReflectiveOperationException catch block logging:

[12/16/20 12:35:43:049 EST] 0000001c id=00000000 org.eclipse.yasson.spi.JsonbComponentInstanceCreator         3 null
[12/16/20 12:35:43:053 EST] 0000001c id=00000000 org.eclipse.yasson.spi.JsonbComponentInstanceCreator         3 CDI environment is not available.

The null message from the top level ReflectiveOperationException is not helpful when debugging an issue.

After patching the code to dump the original exception, an integrator of yasson will now see the full contents of the original exception. This makes is much easier to debug issues such as a CDI integration issue.

Signed-off-by: Nathan Mittlestat <nmittles@us.ibm.com>
  • Loading branch information
nmittles committed Dec 22, 2020
1 parent b305dfa commit bb0993c
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.Level;
import java.util.logging.Logger;

import jakarta.json.bind.JsonbException;
Expand Down Expand Up @@ -134,10 +135,7 @@ private static Object getBeanManager(BeanManagerProvider command) throws ClassNo
throw e;
} catch (ReflectiveOperationException e) {
//likely no CDI container is running or bean manager JNDI lookup fails.
if (e.getCause() != null) {
LOGGER.finest(e.getMessage());
}
LOGGER.finest(Messages.getMessage(MessageKeys.NO_CDI_ENVIRONMENT));
LOGGER.log(Level.FINEST, Messages.getMessage(MessageKeys.NO_CDI_ENVIRONMENT), e);
return null;
}
}
Expand Down

0 comments on commit bb0993c

Please sign in to comment.