Uploaded image for project: 'Daffodil'
  1. Daffodil
  2. DAFFODIL-2287

JApi throws checked exceptions without declaring

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.5.0
    • 4.0.0
    • API
    • None

    Description

      Java assumes that all exceptions thrown by a function are either declared in the function signature, or extend RuntimeException. As such, the compiler will prevent users from catching a checked exception which is not declared in the function signature.

      The Java API defines a parse function which does not declare any exceptions. However, this function can throw a NotYetImplementedException (and possibly other exceptions).

      If a Java user attempts to catch this exception, the compiler will complain because NotYetImplementedException is a checked exception, so Java believes it cannot be thrown.

      I suspect that this issue occurs in other places in out Java API.

      The simplest solution is to make all Scala exceptions RuntimeExceptions. Since Scala does not have checked exceptions, this is no loss to the Scala users, and will allow Java users to treat them as normal unchecked exceptions.

      The more correct solution is to go throw the java API and add throws annotations, such as:

      @throws(classOf[NotYetImplementedException])

      In the meantime, users can work around this by catching Exception, and doing an explicit instanceOf test themselves.

      Attachments

        Activity

          People

            slawrence Steve Lawrence
            brandon.sloane Brandon Sloane
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: