Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-253

MathRuntimeException and MathException are both thread-hostile.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0
    • Labels:
      None

      Description

      MathRuntimeException and MathException are both thread-hostile.

      They have a mutable static field cachedResources which is used in performing translations.

      If two threads use different locales - which is highly likely in the case of non-US locales, as some methods use Locale.US - then they may get corrupt or incorrect output.

      If a cache is really desired, it could either be ThreadLocal, or volatile, but it that case the translate method needs to fetch the value once (and update it once if necessary).

      As it stands, the method can check the resource, find it is OK, then fetch it again to use it, by which time it might have changed. Further, one thread may set the variable, and another thread may see a partially constructed Resources object (it's not final).

        Attachments

          Activity

            People

            • Assignee:
              luc Luc Maisonobe
              Reporter:
              sebb@apache.org Sebb
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: