Merge
authoramurillo
Mon, 08 Aug 2016 11:04:57 -0700
changeset 40206 8870e08b50bc
parent 40205 12384fff105a (current diff)
parent 40179 b5d59a6f093a (diff)
child 40207 cdd28dfda879
Merge
jdk/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c
--- a/jdk/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c	Mon Aug 08 08:12:20 2016 -0700
+++ b/jdk/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c	Mon Aug 08 11:04:57 2016 -0700
@@ -146,6 +146,7 @@
     snprintf(fn, sizeof fn, "/proc/%d", pid);
     if (stat(fn, &stat_buf) == 0) {
         unix_getUserInfo(env, jinfo, stat_buf.st_uid);
+        JNU_CHECK_EXCEPTION(env);
     }
 
     /*
--- a/jdk/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c	Mon Aug 08 08:12:20 2016 -0700
+++ b/jdk/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c	Mon Aug 08 11:04:57 2016 -0700
@@ -434,7 +434,9 @@
 
     if (nargs >= 1) {
         // Create a String array for nargs-1 elements
-        argsArray = (*env)->NewObjectArray(env, nargs - 1, JNU_ClassString(env), NULL);
+        jclass clazzString = JNU_ClassString(env);
+        CHECK_NULL(clazzString);
+        argsArray = (*env)->NewObjectArray(env, nargs - 1, clazzString, NULL);
         CHECK_NULL(argsArray);
 
         for (i = 0; i < nargs - 1; i++) {
--- a/jdk/test/sun/net/www/protocol/http/HttpInputStream.java	Mon Aug 08 08:12:20 2016 -0700
+++ b/jdk/test/sun/net/www/protocol/http/HttpInputStream.java	Mon Aug 08 11:04:57 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, 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
@@ -23,77 +23,95 @@
 
 /* @test
  * @bug 4937598
- * @summary http://www.clipstream.com vedio does not play; read() problem
+ * @summary http://www.clipstream.com video does not play; read() problem
  */
-import java.util.*;
-import java.io.*;
-import java.net.*;
-import java.text.*;
-
-public class HttpInputStream implements Runnable {
-
-  ServerSocket serverSock;
-
-  public void run() {
-      try {
-          Socket s = serverSock.accept();
-          InputStream in = s.getInputStream();
-          byte b[] = new byte[4096];
-
-          // assume we read the entire http request
-          // (bad assumption but okay for test case)
-          int nread = in.read(b);
-
-          OutputStream o = s.getOutputStream();
-
-          o.write( "HTTP/1.1 200 OK".getBytes() );
-          o.write( "Content-Length: 20".getBytes() );
-          o.write( (byte)'\r' );
-          o.write( (byte)'\n' );
-          o.write( (byte)'\r' );
-          o.write( (byte)'\n' );
-
-          for (int i = 0; i < 20; i++) {
-              o.write((byte)0xff);
-          }
-
-          o.flush();
-          o.close();
-
-      } catch (Exception e) { }
-  }
 
 
-  public HttpInputStream() throws Exception {
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.URL;
 
-     serverSock = new ServerSocket(0);
-     int port = serverSock.getLocalPort();
+public class HttpInputStream {
+
+    private static final int CONTENT_LENGTH = 20;
 
-     Thread thr = new Thread(this);
-     thr.start();
+    static class Server implements AutoCloseable, Runnable {
+
+        final ServerSocket serverSocket;
+        static final byte[] requestEnd = new byte[]{'\r', '\n', '\r', '\n'};
+        static final int TIMEOUT = 10 * 1000;
 
-     Date date = new Date(new Date().getTime()-1440000); // this time yesterday
-     URL url;
-     HttpURLConnection con;
+        Server() throws IOException {
+            serverSocket = new ServerSocket(0);
+        }
 
-     url = new URL("http://localhost:" + String.valueOf(port) +
-                   "/anything");
-     con = (HttpURLConnection)url.openConnection();
+        void readOneRequest(InputStream is) throws IOException {
+            int requestEndCount = 0, r;
+            while ((r = is.read()) != -1) {
+                if (r == requestEnd[requestEndCount]) {
+                    requestEndCount++;
+                    if (requestEndCount == 4) {
+                        break;
+                    }
+                } else {
+                    requestEndCount = 0;
+                }
+            }
+        }
 
-     int ret = con.getResponseCode();
-     byte[] b = new byte[20];
-     InputStream is = con.getInputStream();
-     int i = 0, count = 0;
-     while ((i = is.read()) != -1) {
-         System.out.println("i = "+i);
-         count++;
-     }
-     if (count != 20) {
-         throw new RuntimeException("HttpInputStream.read() failed with 0xff");
-     }
-  }
+        @Override
+        public void run() {
+            try (Socket s = serverSocket.accept()) {
+                s.setSoTimeout(TIMEOUT);
+                readOneRequest(s.getInputStream());
+                try (OutputStream os =
+                             s.getOutputStream()) {
+                    os.write("HTTP/1.1 200 OK".getBytes());
+                    os.write(("Content-Length: " + CONTENT_LENGTH).getBytes());
+                    os.write("\r\n\r\n".getBytes());
+                    for (int i = 0; i < CONTENT_LENGTH; i++) {
+                        os.write(0xff);
+                    }
+                    os.flush();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        @Override
+        public void close() throws IOException {
+            if (!serverSocket.isClosed()) {
+                serverSocket.close();
+            }
+        }
 
-  public static void main(String args[]) throws Exception {
-      new HttpInputStream();
-  }
+        public int getPort() {
+            return serverSocket.getLocalPort();
+        }
+    }
+
+
+    private static int read(InputStream is) throws IOException {
+        int len = 0;
+        while (is.read() != -1) {
+            len++;
+        }
+        return len;
+    }
+
+    public static void main(String args[]) throws IOException {
+        try (Server server = new Server()) {
+            (new Thread(server)).start();
+            URL url = new URL("http://localhost:" + server.getPort() + "/anything");
+            try (InputStream is = url.openConnection().getInputStream()) {
+                if (read(is) != CONTENT_LENGTH) {
+                    throw new RuntimeException("HttpInputStream.read() failed with 0xff");
+                }
+            }
+        }
+    }
 }