Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8246041

ImageIO.read(url) does not close TCP connections when the url does not exist

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Linux CentOS

      A DESCRIPTION OF THE PROBLEM :
      When the URL cannot be accessed, the bufferedimage read method directly throws an exception and does not execute into finally istream.close ()

      Related bugs are https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8214503

      REGRESSION : Last worked in version 8u251

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The TestCode is:
      package com.vivo.controller;

      import org.junit.Test;

      import javax.imageio.ImageIO;
      import java.awt.image.BufferedImage;
      import java.io.File;
      import java.net.URL;
      import java.util.concurrent.ExecutorService;
      import java.util.concurrent.Executors;

      public class TestReadFile {

          @Test
          public void testRead() throws InterruptedException {
              ExecutorService ex = Executors.newFixedThreadPool(100);
              for (int i = 0; i < 1000; i++) {
                  ex.execute(task());
              }
              Thread.sleep(100000);
          }

          /**
           */
          private static Runnable task() {
              return new Runnable() {
                  @Override
                  public void run() {
                      // domain must exists,but file doesnot.
                      String vivofsUrl = "https://vivobbs.xx.yy.zz/wiwNWYCFW9ieGbWq/20181129/3a2adfde12cd328d81f965088890eeffff.jpg";

                      File file = null;

                      BufferedImage image = null;

                      try {
                          file = File.createTempFile("abc", "jpg");

                          URL url1 = new URL(vivofsUrl);
                          image = ImageIO.read(url1);

                      } catch (Throwable e) {
                          e.printStackTrace();
                      } finally {
                          if (null != file) {
                              file.delete();
                          }
                          if (null != image) {
                              image.flush();
                              image = null;
                          }

                      }
                  }
              };
          }

      }


      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jdv Jayathirth D V
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: