Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7281

IOGroovyMethods.withStream should use the stream type as the ClosureParam, not simply InputStream

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.0
    • 2.4.2
    • groovy-jdk
    • None
    • Patch

    Description

      IOGroovyMethods.withStream currently defines the closure parameter as InputStream. If withStream is used on a subclass of InputStream, then that type information isn't available.

      Here's an example that should compile, but does not:

      new ByteArrayInputStream(new byte[5]) .withStream{ final ByteArrayInputStream stream  ->
      }
      

      In IOGroovyMethods, I suggest changing the method declaration from:

      public static <T> T withStream(InputStream stream, @ClosureParams(value=SimpleType.class, options="java.io.InputStream") Closure<T> closure) throws IOException {
      

      to:

      public static <T, U extends InputStream> T withStream(U stream, @ClosureParams(value=FirstParam.class) Closure<T> closure) throws IOException {
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            candrews Craig
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: