test/jdk/java/net/Socket/ExceptionText.java
changeset 51356 88d9be7f52c5
parent 51236 a90d8198d7e4
child 53503 1ffc0fa0e98b
equal deleted inserted replaced
51355:9fb336cee537 51356:88d9be7f52c5
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @library /test/lib
    26  * @library /test/lib
    27  * @build jdk.test.lib.Utils
    27  * @build jdk.test.lib.Utils
    28  * @bug 8204233 8207846
    28  * @bug 8204233 8207846 8208691
    29  * @summary Add configurable option for enhanced socket IOException messages
    29  * @summary Add configurable option for enhanced socket IOException messages
       
    30  * @run main/othervm
       
    31  *       ExceptionText
    30  * @run main/othervm
    32  * @run main/othervm
    31  *       ExceptionText
    33  *       ExceptionText
    32  *       WITHOUT_Enhanced_Text
    34  *       WITHOUT_Enhanced_Text
    33  * @run main/othervm
    35  * @run main/othervm
    34  *       -Djdk.includeInExceptions=
    36  *       -Djdk.includeInExceptions=
    60 import java.net.InetSocketAddress;
    62 import java.net.InetSocketAddress;
    61 import java.net.Socket;
    63 import java.net.Socket;
    62 import java.nio.channels.AsynchronousSocketChannel;
    64 import java.nio.channels.AsynchronousSocketChannel;
    63 import java.nio.channels.ClosedChannelException;
    65 import java.nio.channels.ClosedChannelException;
    64 import java.nio.channels.SocketChannel;
    66 import java.nio.channels.SocketChannel;
       
    67 import java.security.Security;
    65 import java.util.concurrent.ExecutionException;
    68 import java.util.concurrent.ExecutionException;
    66 import jdk.test.lib.Utils;
    69 import jdk.test.lib.Utils;
    67 
    70 
    68 public class ExceptionText {
    71 public class ExceptionText {
    69 
    72 
    70     enum TestTarget {SOCKET, CHANNEL, ASYNC_CHANNEL};
    73     enum TestTarget {SOCKET, CHANNEL, ASYNC_CHANNEL};
    71 
    74 
    72     public static void main(String args[]) throws Exception {
    75     public static void main(String args[]) throws Exception {
    73         String passOrFail = args[0];
    76         if (args.length == 0) {
    74         boolean expectEnhancedText;
    77             testSecProp();
    75         if (passOrFail.equals("expectEnhancedText")) {
       
    76             expectEnhancedText = true;
       
    77         } else {
    78         } else {
    78             expectEnhancedText = false;
    79             String passOrFail = args[0];
       
    80             boolean expectEnhancedText;
       
    81             if (passOrFail.equals("expectEnhancedText")) {
       
    82                 expectEnhancedText = true;
       
    83             } else {
       
    84                 expectEnhancedText = false;
       
    85             }
       
    86             test(expectEnhancedText);
    79         }
    87         }
    80         test(expectEnhancedText);
       
    81     }
    88     }
    82 
    89 
    83     static final InetSocketAddress dest  = Utils.refusingEndpoint();
    90     static final InetSocketAddress dest  = Utils.refusingEndpoint();
    84     static final String PORT = ":" + Integer.toString(dest.getPort());
    91     static final String PORT = ":" + Integer.toString(dest.getPort());
    85     static final String HOST = dest.getHostString();
    92     static final String HOST = dest.getHostString();
       
    93 
       
    94     static void testSecProp() {
       
    95         String incInExc = Security.getProperty("jdk.includeInExceptions");
       
    96         if (incInExc != null) {
       
    97             throw new RuntimeException("Test failed: default value of " +
       
    98                 "jdk.includeInExceptions security property is not null: " +
       
    99                 incInExc);
       
   100         }
       
   101     }
    86 
   102 
    87     static void test(boolean withProperty) {
   103     static void test(boolean withProperty) {
    88         // Socket
   104         // Socket
    89         IOException e = getException(TestTarget.SOCKET);
   105         IOException e = getException(TestTarget.SOCKET);
    90         checkResult(e, withProperty);
   106         checkResult(e, withProperty);