8039438: Some tests depend on internal API sun.misc.IOUtils
authorshurailine
Mon, 21 Apr 2014 13:12:22 -0700
changeset 24036 16da2a111dd3
parent 24035 c4b9572b80e0
child 24037 49aa856e6f38
8039438: Some tests depend on internal API sun.misc.IOUtils Summary: Remove dependency on sun.misc.IOUtils.readFully(InputStream, int, boolean) Reviewed-by: alanb, mchung, chegar Contributed-by: Alexandre Iline <alexandre.iline@oracle.com>
jdk/test/java/lang/annotation/AnnotationType/AnnotationTypeRuntimeAssumptionTest.java
jdk/test/java/lang/invoke/lambda/LambdaClassLoaderSerialization.java
jdk/test/java/lang/reflect/Method/InterfaceStatic/StaticInterfaceMethodInWayOfDefault.java
jdk/test/lib/testlibrary/jdk/testlibrary/FileUtils.java
jdk/test/lib/testlibrary/jdk/testlibrary/IOUtils.java
jdk/test/sun/security/tools/jarsigner/EntriesOrder.java
--- a/jdk/test/java/lang/annotation/AnnotationType/AnnotationTypeRuntimeAssumptionTest.java	Mon Apr 21 13:51:08 2014 -0400
+++ b/jdk/test/java/lang/annotation/AnnotationType/AnnotationTypeRuntimeAssumptionTest.java	Mon Apr 21 13:12:22 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -25,15 +25,18 @@
  * @test
  * @summary Test consistent parsing of ex-RUNTIME annotations that
  *          were changed and separately compiled to have CLASS retention
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.IOUtils
+ * @run main AnnotationTypeRuntimeAssumptionTest
  */
 
-import sun.misc.IOUtils;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 
+import jdk.testlibrary.IOUtils;
+
 import static java.lang.annotation.RetentionPolicy.CLASS;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
@@ -137,7 +140,7 @@
                 String altPath = altName.replace('.', '/').concat(".class");
                 try (InputStream is = getResourceAsStream(altPath)) {
                     if (is != null) {
-                        byte[] bytes = IOUtils.readFully(is, -1, true);
+                        byte[] bytes = IOUtils.readFully(is);
                         // patch class bytes to contain original name
                         for (int i = 0; i < bytes.length - 2; i++) {
                             if (bytes[i] == '_' &&
@@ -160,7 +163,7 @@
                 String path = name.replace('.', '/').concat(".class");
                 try (InputStream is = getResourceAsStream(path)) {
                     if (is != null) {
-                        byte[] bytes = IOUtils.readFully(is, -1, true);
+                        byte[] bytes = IOUtils.readFully(is);
                         return defineClass(name, bytes, 0, bytes.length);
                     }
                     else {
--- a/jdk/test/java/lang/invoke/lambda/LambdaClassLoaderSerialization.java	Mon Apr 21 13:51:08 2014 -0400
+++ b/jdk/test/java/lang/invoke/lambda/LambdaClassLoaderSerialization.java	Mon Apr 21 13:12:22 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -22,11 +22,14 @@
  */
 
 /*
-@test
-@bug 8004970
-@summary Lambda serialization in the presence of class loaders
-@author Peter Levart
-*/
+ * @test
+ * @bug 8004970
+ * @summary Lambda serialization in the presence of class loaders
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.IOUtils
+ * @run main LambdaClassLoaderSerialization
+ * @author Peter Levart
+ */
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -37,6 +40,8 @@
 import java.io.Serializable;
 import java.util.Arrays;
 
+import jdk.testlibrary.IOUtils;
+
 public class LambdaClassLoaderSerialization {
 
     public interface SerializableRunnable extends Runnable, Serializable {}
@@ -125,7 +130,7 @@
             String path = name.replace('.', '/').concat(".class");
             try (InputStream is = getResourceAsStream(path)) {
                 if (is != null) {
-                    byte[] bytes = readFully(is);
+                    byte[] bytes = IOUtils.readFully(is);
                     return defineClass(name, bytes, 0, bytes.length);
                 } else {
                     throw new ClassNotFoundException(name);
@@ -135,30 +140,5 @@
                 throw new ClassNotFoundException(name, e);
             }
         }
-
-        static byte[] readFully(InputStream is) throws IOException {
-            byte[] output = {};
-            int pos = 0;
-            while (true) {
-                int bytesToRead;
-                if (pos >= output.length) { // Only expand when there's no room
-                    bytesToRead = output.length + 1024;
-                    if (output.length < pos + bytesToRead) {
-                        output = Arrays.copyOf(output, pos + bytesToRead);
-                    }
-                } else {
-                    bytesToRead = output.length - pos;
-                }
-                int cc = is.read(output, pos, bytesToRead);
-                if (cc < 0) {
-                    if (output.length != pos) {
-                        output = Arrays.copyOf(output, pos);
-                    }
-                    break;
-                }
-                pos += cc;
-            }
-            return output;
-        }
     }
 }
--- a/jdk/test/java/lang/reflect/Method/InterfaceStatic/StaticInterfaceMethodInWayOfDefault.java	Mon Apr 21 13:51:08 2014 -0400
+++ b/jdk/test/java/lang/reflect/Method/InterfaceStatic/StaticInterfaceMethodInWayOfDefault.java	Mon Apr 21 13:12:22 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -27,6 +27,9 @@
  * @summary Test that a static method on an interface doesn't hide a default
  *          method with the same name and signature in a separate compilation
  *          scenario.
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.IOUtils
+ * @run main StaticInterfaceMethodInWayOfDefault
  */
 
 import java.io.IOException;
@@ -35,7 +38,7 @@
 import java.lang.reflect.Method;
 import java.util.concurrent.Callable;
 
-import sun.misc.IOUtils;
+import jdk.testlibrary.IOUtils;
 
 public class StaticInterfaceMethodInWayOfDefault {
     public interface A_v1 {
@@ -144,7 +147,7 @@
                 String altPath = altName.replace('.', '/').concat(".class");
                 try (InputStream is = getResourceAsStream(altPath)) {
                     if (is != null) {
-                        byte[] bytes = IOUtils.readFully(is, -1, true);
+                        byte[] bytes = IOUtils.readFully(is);
                         // patch class bytes to contain original name
                         for (int i = 0; i < bytes.length - 2; i++) {
                             if (bytes[i] == '_' &&
@@ -167,7 +170,7 @@
                 String path = name.replace('.', '/').concat(".class");
                 try (InputStream is = getResourceAsStream(path)) {
                     if (is != null) {
-                        byte[] bytes = IOUtils.readFully(is, -1, true);
+                        byte[] bytes = IOUtils.readFully(is);
                         return defineClass(name, bytes, 0, bytes.length);
                     }
                     else {
--- a/jdk/test/lib/testlibrary/jdk/testlibrary/FileUtils.java	Mon Apr 21 13:51:08 2014 -0400
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/FileUtils.java	Mon Apr 21 13:12:22 2014 -0700
@@ -191,4 +191,3 @@
         return excs;
     }
 }
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/IOUtils.java	Mon Apr 21 13:12:22 2014 -0700
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2014, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.testlibrary;
+
+/**
+ * Defines useful I/O methods.
+ */
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+
+public final class IOUtils {
+
+    /*
+     * Prevent instantiation.
+     */
+    private IOUtils() {}
+
+    /**
+     * Read all bytes from <code>in</code>
+     * until EOF is detected.
+     * @param in input stream, must not be null
+     * @return bytes read
+     * @throws IOException Any IO error.
+     */
+    public static byte[] readFully(InputStream is) throws IOException {
+        byte[] output = {};
+        int pos = 0;
+        while (true) {
+            int bytesToRead;
+            if (pos >= output.length) { // Only expand when there's no room
+                bytesToRead = output.length + 1024;
+                if (output.length < pos + bytesToRead) {
+                    output = Arrays.copyOf(output, pos + bytesToRead);
+                }
+            } else {
+                bytesToRead = output.length - pos;
+            }
+            int cc = is.read(output, pos, bytesToRead);
+            if (cc < 0) {
+                if (output.length != pos) {
+                    output = Arrays.copyOf(output, pos);
+                }
+                break;
+            }
+            pos += cc;
+        }
+        return output;
+    }
+}
--- a/jdk/test/sun/security/tools/jarsigner/EntriesOrder.java	Mon Apr 21 13:51:08 2014 -0400
+++ b/jdk/test/sun/security/tools/jarsigner/EntriesOrder.java	Mon Apr 21 13:12:22 2014 -0700
@@ -25,6 +25,9 @@
  * @test
  * @bug 8031572
  * @summary jarsigner -verify exits with 0 when a jar file is not properly signed
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.IOUtils
+ * @run main EntriesOrder
  */
 
 import java.io.FileInputStream;
@@ -39,6 +42,8 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
+import jdk.testlibrary.IOUtils;
+
 public class EntriesOrder {
 
     public static void main(String[] args) throws Exception {
@@ -106,7 +111,7 @@
                 Enumeration<JarEntry> jes = jf.entries();
                 while (jes.hasMoreElements()) {
                     JarEntry je = jes.nextElement();
-                    sun.misc.IOUtils.readFully(jf.getInputStream(je), -1, true);
+                    IOUtils.readFully(jf.getInputStream(je));
                     Certificate[] certs = je.getCertificates();
                     if (certs != null && certs.length > 0) {
                         cc++;
@@ -138,7 +143,7 @@
                 while (true) {
                     JarEntry je = jis.getNextJarEntry();
                     if (je == null) break;
-                    sun.misc.IOUtils.readFully(jis, -1, true);
+                    IOUtils.readFully(jis);
                     Certificate[] certs = je.getCertificates();
                     if (certs != null && certs.length > 0) {
                         cc++;