NullAway icon indicating copy to clipboard operation
NullAway copied to clipboard

getFunctionalInterfaceMethod() doesn't check super-interfaces

Open mintern opened this issue 9 years ago • 5 comments

On the latest master (5177099f7d75182ca0f41d466ef8478f7596cb9e). Here's a patch to produce a failing test:

diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java b/nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java
index 43419a6..e318ff0 100644
--- a/nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java
+++ b/nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java
@@ -134,4 +134,9 @@ public class NullAwayTest {
     public void rxSupportNegativeCases() {
         compilationHelper.addSourceFile("NullAwayRxSupportNegativeCases.java").doTest();
     }
+
+    @Test
+    public void functionalMethodSuperInterface() {
+        compilationHelper.addSourceFile("NullAwaySuperFunctionalInterface.java").doTest();
+    }
 }
diff --git a/nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwaySuperFunctionalInterface.java b/nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwaySuperFunctionalInterface.java
index e69de29..5d69c07 100644
--- a/nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwaySuperFunctionalInterface.java
+++ b/nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwaySuperFunctionalInterface.java
@@ -0,0 +1,20 @@
+package com.uber.nullaway.testdata;
+
+public class NullAwaySuperFunctionalInterface {
+
+    public void foo() {
+        go(() -> {});
+    }
+
+    private void go(Foo foo) {
+        foo.call();
+    }
+
+    @FunctionalInterface
+    private static interface Foo extends Bar {} 
+
+    @FunctionalInterface
+    private static interface Bar {
+        void call();
+    }
+}

Here's the relevant portion of the error stacktrace:

java.lang.AssertionError: An unhandled exception was thrown by the Error Prone static analysis plugin.
     Please report this at https://github.com/google/error-prone/issues/new and include the following:
  
     error-prone version: 2.1.1
     Stack Trace:
     java.lang.RuntimeException: could not find functional interface method in 
  	at com.uber.nullaway.NullabilityUtil.getFunctionalInterfaceMethod(NullabilityUtil.java:87)
  	at com.uber.nullaway.NullAway.matchLambdaExpression(NullAway.java:422)
        ...

mintern avatar Sep 15 '17 00:09 mintern

Nice catch! Working on merging a fix into master now. Thanks!

lazaroclapp avatar Sep 15 '17 01:09 lazaroclapp

@mintern would it be helpful to you if we cut a new release with this fix?

msridhar avatar Sep 16 '17 00:09 msridhar

It would, thank you. This is currently preventing us from using NullAway due to our reliance on net.mintern.functions.

mintern avatar Sep 16 '17 00:09 mintern

Thank you for the quick fix!

mintern avatar Sep 16 '17 00:09 mintern

Thanks for the report! Version 0.1.3 has been released.

msridhar avatar Sep 16 '17 03:09 msridhar