< prev index next >

src/java.base/share/classes/sun/net/util/SocketExceptions.java

Print this page




  27 
  28 import java.io.IOException;
  29 import java.lang.reflect.Constructor;
  30 import java.net.InetSocketAddress;
  31 import java.security.AccessController;
  32 import java.security.PrivilegedAction;
  33 import java.security.Security;
  34 
  35 public final class SocketExceptions {
  36     private SocketExceptions() {}
  37 
  38     /**
  39      * Security or system property which specifies categories of
  40      * (potentially sensitive) information that may be included
  41      * in exception text. This class only defines one category:
  42      * "hostInfo" which represents the hostname and port number
  43      * of the remote peer relating to a socket exception.
  44      * The property value is a comma separated list of
  45      * case insignificant category names.
  46      */
  47     private static final String enhancedTextPropname = "jdk.net.includeInExceptions";
  48 
  49     private static final boolean enhancedExceptionText = initTextProp();
  50 
  51     private static boolean initTextProp() {
  52         return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
  53             public Boolean run() {
  54                 String val = System.getProperty(enhancedTextPropname);
  55                 if (val == null) {
  56                     val = Security.getProperty(enhancedTextPropname);
  57                     if (val == null)
  58                         return false;
  59                 }
  60                 String[] tokens = val.split(",");
  61                 for (String token : tokens) {
  62                     if (token.equalsIgnoreCase("hostinfo"))
  63                         return true;
  64                 }
  65                 return false;
  66             }
  67         });
  68     }
  69 
  70 
  71     /**
  72      * Utility which takes an exception and returns either the same exception
  73      * or a new exception of the same type with the same stack trace
  74      * and detail message enhanced with addressing information from the
  75      * given InetSocketAddress.
  76      *
  77      * If the system/security property "jdk.net.enhanceExceptionText" is not
  78      * set or is false, then the original exception is returned.
  79      *
  80      * Only specific IOException subtypes are supported.
  81      */
  82     public static IOException of(IOException e, InetSocketAddress address) {




  27 
  28 import java.io.IOException;
  29 import java.lang.reflect.Constructor;
  30 import java.net.InetSocketAddress;
  31 import java.security.AccessController;
  32 import java.security.PrivilegedAction;
  33 import java.security.Security;
  34 
  35 public final class SocketExceptions {
  36     private SocketExceptions() {}
  37 
  38     /**
  39      * Security or system property which specifies categories of
  40      * (potentially sensitive) information that may be included
  41      * in exception text. This class only defines one category:
  42      * "hostInfo" which represents the hostname and port number
  43      * of the remote peer relating to a socket exception.
  44      * The property value is a comma separated list of
  45      * case insignificant category names.
  46      */
  47     private static final String enhancedTextPropname = "jdk.includeInExceptions";
  48 
  49     private static final boolean enhancedExceptionText = initTextProp();
  50 
  51     private static boolean initTextProp() {
  52         return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
  53             public Boolean run() {
  54                 String val = System.getProperty(enhancedTextPropname);
  55                 if (val == null) {
  56                     val = Security.getProperty(enhancedTextPropname);
  57                     if (val == null)
  58                         return false;
  59                 }
  60                 String[] tokens = val.split(",");
  61                 for (String token : tokens) {
  62                     if (token.trim().equalsIgnoreCase("hostinfo"))
  63                         return true;
  64                 }
  65                 return false;
  66             }
  67         });
  68     }
  69 
  70 
  71     /**
  72      * Utility which takes an exception and returns either the same exception
  73      * or a new exception of the same type with the same stack trace
  74      * and detail message enhanced with addressing information from the
  75      * given InetSocketAddress.
  76      *
  77      * If the system/security property "jdk.net.enhanceExceptionText" is not
  78      * set or is false, then the original exception is returned.
  79      *
  80      * Only specific IOException subtypes are supported.
  81      */
  82     public static IOException of(IOException e, InetSocketAddress address) {


< prev index next >