Uploaded image for project: 'Clover'
  1. Clover
  2. CLOV-1398

Java 1.8 Exceptions not being propagated correctly

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: High High
    • 3.2.2
    • 3.2.0
    • Instrumentation
    • None

      I have the following test stub (src/main/java)

      public final class TestStub {
          TestStub() {
              throw new IllegalArgumentException();
          }
      
          public static void getHandler() {
              new HashMap<>().computeIfAbsent(String.class, t -> new TestStub());
          }
      }
      

      And the following test (src/test/java)

      public class FooTest {
      
          @Test(expected = IllegalArgumentException.class)
          public void test0() {
              TestStub.getHandler();
          }
      }
      

      Using maven It runs fine using "clean install" however using clover I get the following exception

      java.lang.reflect.UndeclaredThrowableException
      	at com.sun.proxy.$Proxy12.apply(Unknown Source)
      	at java.util.HashMap.computeIfAbsent(HashMap.java:1118)
      	at org.cakeframework.internal.container.TestStub.getHandler(TestStub.java:26)
      	at org.cakeframework.internal.container.FooTest.test0(FooTest.java:29)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:483)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:19)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
      	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
      	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
      	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
      Caused by: java.lang.reflect.InvocationTargetException
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:483)
      	at org.cakeframework.internal.container.TestStub$__CLR3_2_0wqwqhpd53be5$1.invoke(TestStub.java:20)
      	... 28 more
      Caused by: java.lang.IllegalArgumentException
      	at org.cakeframework.internal.container.TestStub.<init>(TestStub.java:22)
      	at org.cakeframework.internal.container.TestStub.lambda$getHandler$6(TestStub.java:26)
      	at org.cakeframework.internal.container.TestStub$$Lambda$13/1227074340.apply(Unknown Source)
      	... 33 more
      

      If I replace with a standard anonymous class implementing java.util.function.Function it runs fine

            [CLOV-1398] Java 1.8 Exceptions not being propagated correctly

            Right, a block lambda is a quick fix. Thanks for the tip.

            Deleted Account (Inactive) added a comment - Right, a block lambda is a quick fix. Thanks for the tip.

            Hi Kasper, thanks a lot for your report. It seems to be a bug in our proxy class intercepting a lambda function call. I have increased a priority to Crictical and scheduled for the nearest bug fix release (Clover 3.2.1, planned for January).

            I guess that the following workaround should work as well:

            public static void getHandler() {
                    new HashMap<>().computeIfAbsent(String.class, t -> { return new TestStub(); } );
            }
            

            i.e. replace the expression-like lambda into the block lambda (in curly braces).

            Marek Parfianowicz added a comment - Hi Kasper, thanks a lot for your report. It seems to be a bug in our proxy class intercepting a lambda function call. I have increased a priority to Crictical and scheduled for the nearest bug fix release (Clover 3.2.1, planned for January). I guess that the following workaround should work as well: public static void getHandler() { new HashMap<>().computeIfAbsent( String .class, t -> { return new TestStub(); } ); } i.e. replace the expression-like lambda into the block lambda (in curly braces).

              mparfianowicz Marek Parfianowicz
              4d85d3f9-8aa3-417a-bb6f-61e186be8e94 Deleted Account (Inactive)
              Affected customers:
              0 This affects my team
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: