Uploaded image for project: 'UIMA'
  1. UIMA
  2. UIMA-633

Class loading issue with ResourceBundle when using the UIMAClassloader

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2
    • 2.2.1
    • Core Java Framework
    • None

    Description

      currently we have the issue with UIMA components that custom messages in exception cannot be resolved when the UIMAClassloader is used to load the custom component. This is the case when using the PEAR runtime. To work around this issue we say that the custom components can throw own exception class that is derived from the UIMA exception classes. This should work because we thought that the method ResourceBundle.|getBundle(baseName, locale) |use the Classloader of the current object to resolve the messages. That's also what the JavaDoc says:
      "Gets a resource bundle using the specified base name and locale, and the caller's class loader.
      Calling this method is equivalent to calling |getBundle(baseName, locale, this.getClass().getClassLoader())| ...."

      But unfortunately this is not true in any case. So it does also not work for out UIMA case.
      If we have the custom exception example below, let's see what happens.

      public MyException extends AnnotatorPrcoessException {

      public MyException (String aMessageKey, Object[] aArguments)

      { super("myExceptionMessages", aMessageKey, aArguments); }

      }

      when the exception message is localized, the method getLocalizedMessage() is called on the MyException object. The getLocalizedMessage() method is not implemented in the MyException class, it is inherited from the InternationalizedException class.
      public String getLocalizedMessage()

      { .... ResourceBundle.getBundle(bundleName, locale); .... }

      If getLocalizedMessage() method is called, the getBundle(bundleName, locale) method resolves the classloader that is used to resolve the bundleName. In our case the classloader of the class InternationalizedException is used here since there the getLocalizedMessage() method is defined. But this is in case of the UIMAClassloader usage not the classloader of the MyException object that should be used here, at least if we trust the JavaDocs. To solve this issue we can easily hand over the MyException object classloader to the getBundle() method like:

      ResourceBundle.getBundle(bundleName, locale, this.getClass().getClassloader());

      The fix is done in the InternationalizedException class so it work for all derived exceptions.

      Attachments

        Activity

          People

            mbaessler Michael Baessler
            mbaessler Michael Baessler
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: