src/java.base/share/classes/java/net/AbstractPlainDatagramSocketImpl.java
changeset 48737 7c12219870fd
parent 47216 71c04702a3d5
child 55081 dd321e3596c0
--- a/src/java.base/share/classes/java/net/AbstractPlainDatagramSocketImpl.java	Fri Feb 02 10:32:59 2018 -0800
+++ b/src/java.base/share/classes/java/net/AbstractPlainDatagramSocketImpl.java	Fri Feb 02 14:17:07 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,11 +26,11 @@
 
 import java.io.FileDescriptor;
 import java.io.IOException;
-import java.security.AccessController;
-import sun.net.ResourceManager;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.Set;
-import java.util.HashSet;
-import java.util.Collections;
+
+import sun.net.ResourceManager;
 import sun.security.action.GetPropertyAction;
 
 /**
@@ -115,6 +115,7 @@
         fd = new FileDescriptor();
         try {
             datagramSocketCreate();
+            SocketCleanable.register(fd);
         } catch (SocketException ioe) {
             ResourceManager.afterUdpClose();
             fd = null;
@@ -265,6 +266,7 @@
      */
     protected void close() {
         if (fd != null) {
+            SocketCleanable.unregister(fd);
             datagramSocketClose();
             ResourceManager.afterUdpClose();
             fd = null;
@@ -275,11 +277,6 @@
         return (fd == null) ? true : false;
     }
 
-    @SuppressWarnings("deprecation")
-    protected void finalize() {
-        close();
-    }
-
     /**
      * set a value - since we only support (setting) binary options
      * here, o must be a Boolean