Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-5124

Make APIException(String) behave localized

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Should
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Complexity:
      Low

      Description

      In a former issue (see linked issue) non-localized usage of APIException like these

      throw new APIException("Location is required");
      

      where error messages were hard-coded was replaced by using message keys.

      Since the APIException(String) constructor does not treat the given string as a message key the constructor which also expects a parameter object was used. Leading to code like this

      throw new APIException("Location.name.required", (Object[]) null);
      

      Looking at the merge commit there are 141 occurrences where there is actually no need to pass a parameter array to the localized message but due to the behavior of the APIException(String) there is no other way around this.

      SOLUTION:

      change the APIException(String) implementation to

      super(Context.getMessageSourceService().getMessage(message, null, message, Context.getLocale()));
      

      this will lookup the message string in message properties and if not found default to the message string.

      Like this it should not affect existing non-localized usage but enable cleaner use of localized messages without the need for parametrization.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              teleivo Ivo Ulrich
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: