#377 osgi optional service not handled in attempt/recover


I am currently using freemarker v2.3.19 with camel and osgi. I am passing some optional osgi services into my template. I wrap any uses of these services inside an attempt/recover in case they are not available. Unfortunately, the attempt/recover fails to handle them when they are unavailable. The problem traces to the SimpleMethodModel class, inside the exec function. When the invocation fails, the catch block tries to build a TemplateModelException. However, line 130/131:

throw new TemplateModelException("Method " + getMember() +
" threw an exception when invoked on " + object, e);

results in a ServiceUnavailableException. This occurs because it tries to get a toString() on object to generate the error message, and that throws the exception. This results in a ServiceUnavailableException coming out of te function instead of a TeplateModelException, and it does not get handled by the attempt/recover, or anything else.

It seems the SimpleModelException should be handling everything and the intent would be only a TemplateModelException comes out, so that attempt/recover logic can handle that exception. However, in this particular case, where object.toString() generates an exception, this functionality breaks down.



  • Dániel Dékány

    Failing toString()... That means that exception constructors should use something like WhateverUtils.safeToString(obj) everywhere. Yeah, in principle that would be the correct way of building exception messages, but who does that? /-: Should FreeMarker do that? I don't know... Or maybe it's #attempt that should be configurable to catch some extra exception classes.

  • Dániel Dékány

    • status: open --> closed-fixed
    • Group: -->
  • Dániel Dékány

    Fixed in 2.3.20.


Log in to post a comment.