mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 18:18:48 +00:00
Avoid "possible NPE" warnings for throw Lombok.sneakyThrow(e)
Currently, the following code triggers a warning in IntelliJ.
(I'm using the current version, 2016.3.4.)
throw Lombok.sneakyThrow(e);
> Dereference of 'Lombok.sneakyThrow(e)' may produce 'java.lang.NullPointerException'.
This change eliminates the warning.
All tests pass. I ran:
ant setupJavaOpenJDK6TestEnvironment
ant test
ant setupJavaOpenJDK7TestEnvironment
ant test
ant setupJavaOracle7TestEnvironment
ant test
ant setupJavaOracle8TestEnvironment
ant test
This commit is contained in:
1 parent
7516a51b37
commit
9fb3197375
1 file changed
+2
-3
@@ -48,12 +48,11 @@ public class Lombok {
|
||||
*/
|
||||
public static RuntimeException sneakyThrow(Throwable t) {
|
||||
if (t == null) throw new NullPointerException("t");
|
||||
Lombok.<RuntimeException>sneakyThrow0(t);
|
||||
return null;
|
||||
return Lombok.<RuntimeException>sneakyThrow0(t);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T extends Throwable> void sneakyThrow0(Throwable t) throws T {
|
||||
private static <T extends Throwable> RuntimeException sneakyThrow0(Throwable t) throws T {
|
||||
throw (T)t;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user