Scala Programming Language
  1. Scala Programming Language
  2. SI-7912

Be defensive when calling toString() on object in MatchError.getMessage

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.3
    • Fix Version/s: Scala 2.10.4-RC1
    • Component/s: Misc Library
    • Labels:
      None

      Description

      If Throwable.getMessage throws an exception, no matter whose fault it is, this will make debugging an application that throws such an exception very difficult, because the original exception will be lost when a logger tries to log the exception message. Scalas MatchError.getMessage method will throw an exception if the object that failed to match throws an exception from its toString method. That object of course shouldn't throw an exception from its toString method, but if that object is from a third party library and you just want to debug your application, knowing who to blame is little consolation.

      MatchError.getMessage should therefore be defensive when invoking toString on the object, catching any exceptions caught, and if such an exception was caught, displaying a message like this instead:

      "an instance of class " + obj.getClass.getName

      It could probably also add information about exception caught, eg saying "Additionally, an exception was thrown when the toString() method was invoked: ...", but this is not strictly necessary.

        Issue Links

          Activity

          Show
          Jason Zaugg added a comment - https://github.com/scala/scala/pull/3249

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              James Roper
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development