[ 
https://issues.apache.org/jira/browse/UIMA-5961?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16874984#comment-16874984
 ] 

Marshall Schor commented on UIMA-5961:
--------------------------------------

Hi, thanks very much for the test case.  I was able to reproduce it, and found 
out what is happening.  Here's the story:
 # The throw happens in the Pear. 
 # At the time of the throw, an exception object is prepared with all of the 
things needed to generate the message, but the message isn't generated then.
 # The throw causes the stack to be unwound up to a catch point, which in this 
case, happens to be outside the pear.
 ## During the unwinding, the class loaders, thread local contexts, 
uima-contexts, are unwound back to their states before entering the pear.
 # Finally a logging call calls "toString" on the exception, which, in turn, 
finally causes the message to attempt to be localized.  However, at that point 
the pear context isn't available, so you get that can't-localize failure.

A temporary workaround is to localize the message in the exception before 
leaving the pear context.  This only works due to an implementation detail in 
Java's built-in localization.  It turns out that the bundle lookups are cached, 
so once found, they are not looked up again in the classloaders, the cached 
value is used.

The workaround in the test is to replace:
{code:java}
    public void process(JCas jcas) throws AnalysisEngineProcessException {

        Object[] objects = new Object[] { "ARGUMENT" };
        throw new AnalysisEngineProcessException(MESSAGE_BUNDLE, "TEST_KEY", 
objects);
    }
{code}
 with 
{code:java}
    public void process(JCas jcas) throws AnalysisEngineProcessException {

        Object[] objects = new Object[] { "ARGUMENT" };
        try {
          throw new AnalysisEngineProcessException(MESSAGE_BUNDLE, "TEST_KEY", 
objects);
        } catch (AnalysisEngineProcessException e) {
          System.out.println("exception: " + e.toString());  // anything that 
calls e.toString() will 
             // cause the message internationalization to occur in the pear 
context
          throw e;  // will now leave the pear context
        }
    }
{code}
I'm thinking about how to fix this in the framework;  I'm thinking that some 
early bundle lookup triggering might be good to do, but I'm not sure if I 
should depend on Java's caching of this - will need to read javadocs, etc.

> InternationalizedException getLocalizedMessage fails in pear
> ------------------------------------------------------------
>
>                 Key: UIMA-5961
>                 URL: https://issues.apache.org/jira/browse/UIMA-5961
>             Project: UIMA
>          Issue Type: Bug
>    Affects Versions: 2.10.3SDK
>            Reporter: Matthias Koch
>            Assignee: Marshall Schor
>            Priority: Major
>             Fix For: 2.10.4SDK
>
>         Attachments: UIMA-5961.diff, peartest.zip
>
>
> localized message does not work in the case of pears. The classloader stored 
> in the internationalizedException is wrong. The bundle cant be found in this 
> classloader.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to