Uploaded image for project: 'Tika'
  1. Tika
  2. TIKA-1719

Utilize try-with-resources where it is trivial

    XMLWordPrintableJSON

Details

    • Patch

    Description

      The following type of resource usages:

          AutoCloseable resource = ...;
          try {
              // do something with resource
          } finally {
              resource.close();
          }
      
          AutoCloseable resource = null;
          try {
              resource = ...;
              // do something with resource
          } finally {
              if (resource != null) {
                  resource.close();
              }
          }
      

      and similar constructs can be trivially replaced with Java 7's try-with-resource statement:

          try (AutoCloseable resource = ...) {
              // do something with resource
          }
      

      This brings more concise code with less chance of causing resource leaks.

      Attachments

        1. TIKA-1719.patch
          270 kB
          Yaniv Kunda

        Activity

          People

            jukkaz Jukka Zitting
            kunda Yaniv Kunda
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: