google / google/guice

NPE in ProvisionException

Open
#540 5 comments 0 reactions 0 assignees View on GitHub
imported
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

_From [mathieu.carbou](https://code.google.com/u/112785376815810724272/) on September 23, 2010 11:49:55_

How to reproduce:

throw new ProvisionException(null, new RuntimeException());

Exception:

Exception in thread "main" java.lang.NullPointerException: message
        at com.google.inject.internal.util.Preconditions.checkNotNull(Preconditions.java:200)
        at com.google.inject.spi.Message.<init>(Message.java:52)
        at com.google.inject.ProvisionException.<init>(ProvisionException.java:46)

Use case:
When working on mycila-guice (Guice's extensions), I need to sometimes rethrow the targe texception of a reflection call like below. But the message can be null. The ProvisionException crashes.

Thus, we are forced to prevent it by doing a String.valueOf(...)

try {
...
} catch (InvocationTargetException e) {
    throw new ProvisionException(String.valueOf(e.getTargetException().getMessage()), e.getTargetException());
}

_Original issue: http://code.google.com/p/google-guice/issues/detail?id=540_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.