From 9fb31973757a3ad4509c024ea50e77295c61cf89 Mon Sep 17 00:00:00 2001 From: Jared Jacobs Date: Fri, 10 Feb 2017 15:11:48 -0800 Subject: 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 --- src/core/lombok/Lombok.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/core/lombok/Lombok.java') diff --git a/src/core/lombok/Lombok.java b/src/core/lombok/Lombok.java index 310b57e3..ae375637 100644 --- a/src/core/lombok/Lombok.java +++ b/src/core/lombok/Lombok.java @@ -48,12 +48,11 @@ public class Lombok { */ public static RuntimeException sneakyThrow(Throwable t) { if (t == null) throw new NullPointerException("t"); - Lombok.sneakyThrow0(t); - return null; + return Lombok.sneakyThrow0(t); } @SuppressWarnings("unchecked") - private static void sneakyThrow0(Throwable t) throws T { + private static RuntimeException sneakyThrow0(Throwable t) throws T { throw (T)t; } -- cgit From 5a2fe6e61caf9024be29568b0b053f163c6f899e Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Tue, 9 Jan 2018 13:10:18 +0100 Subject: use T instead of RuntimeException --- src/core/lombok/Lombok.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/lombok/Lombok.java') diff --git a/src/core/lombok/Lombok.java b/src/core/lombok/Lombok.java index ae375637..d86b6d1c 100644 --- a/src/core/lombok/Lombok.java +++ b/src/core/lombok/Lombok.java @@ -52,7 +52,7 @@ public class Lombok { } @SuppressWarnings("unchecked") - private static RuntimeException sneakyThrow0(Throwable t) throws T { + private static T sneakyThrow0(Throwable t) throws T { throw (T)t; } -- cgit