#1821

Await.result throws checked exception but does not declare it

    • Status: Fixed
    • Priority: Highest (1)
    • Component: -
    • Estimate: None/Small/Medium/Large None
    The method
    akka.dispatch.Await.result(Awaitable<T>, Duration)

    throws checked exception java.util.concurrent.TimeoutException but does not declare it when used from Java code. I.e. the following does not compile:
    try {
        akka.dispatch.Await.result(future, duration)
    } catch (java.util.concurrent.TimeoutException e) { // Unreachable catch block for TimeoutException. This exception is never thrown from the try statement body
       // handle exception properly
    }

    However the java.util.concurrent.TimeoutException is indeed thrown when timeout occurs.
  • Followers
     
    Ico-users viktorklang (Assigned To) , Jonas Bonér , Peter Vlugter , piotr.findeisen 
     
    Attachments
    No attachments
    Associations
     
    No associations
    Activity
     
    User picture

          on Feb 14, 2012 @ 02:34pm UTC * By piotr.findeisen

    Description changed from The method <pre><code>akk... to The method <pre><code>akk...
    User picture

          on Feb 14, 2012 @ 02:36pm UTC * By piotr.findeisen

    Description changed from The method <pre><code>akk... to The method <pre><code>akka....
    As a workaround one can write

    try {
        akka.dispatch.Await.result(future, duration)
        if (Boolean.FALSE)  throw new java.util.concurrent.TimeoutException("this will never be thrown");
    } catch (java.util.concurrent.TimeoutException e) {
        ....
    }


    but i bet this is not was intended here
    User picture

          on Feb 14, 2012 @ 02:40pm UTC * By piotr.findeisen

    Btw. is the java.lang.InterruptedException thrown too?
    User picture

          on Feb 14, 2012 @ 02:45pm UTC * By piotr.findeisen

    Summary changed from Await.result throws checked excepception but does not declare it to Await.result throws checked exception but does not declare it
    User picture

          on Feb 14, 2012 @ 02:47pm UTC * By piotr.findeisen

    Hm... maybe it is by design? Apparently TypedActor also features this philosophy:


    java.lang.reflect.UndeclaredThrowableException
    	at $Proxy42.submit(Unknown Source)
           at com.example.ActorConsumer.init(ActorConsumer.java:37)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:300)
    	at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:226)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:498)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:474)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:442)
    	at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1066)
    	at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1040)
    	at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:958)
    Caused by: akka.pattern.AskTimeoutException
    	at akka.pattern.AskSupport$class.ask(AskSupport.scala:75)
    	at akka.pattern.package$.ask(package.scala:43)
    	at akka.actor.TypedActor$TypedActorInvocationHandler.invoke(TypedActor.scala:364)
    	... 16 more
    User picture

          on Feb 16, 2012 @ 09:58am UTC * By Patrik Nordwall

    We have to add
    @throws(classOf[Throwable])
    to the signature. It is not only for the TimeoutException, but the actual future can be completed with a checked exception, that should be possible to catch here. It will be extremely ugly in the caller

        try {
          String result = (String) Await.result(f, Duration.create(1, SECONDS));
        } catch (TimeoutException e) {
          
        } catch (Throwable t) {
    
        }
    User picture

          on Feb 16, 2012 @ 12:36pm UTC * By viktorklang

    Assigned to set to viktorklang
    Status changed from New to Test
    User picture

          on Feb 19, 2012 @ 10:50pm UTC * By viktorklang

    Status changed from Test to Fixed
    User picture

          on Feb 20, 2012 @ 06:09pm UTC * By viktorklang

    Milestone changed from 2.0 to 2.0-RC2
    Time Expenditure
    Loading