8198931: remove java.xml.bind module dependency for com/sun/jndi tests
authorxyin
Sun, 04 Mar 2018 18:46:07 -0800
changeset 49127 73385a708426
parent 49126 f29637bb390e
child 49128 97288886180c
8198931: remove java.xml.bind module dependency for com/sun/jndi tests Reviewed-by: lancea
test/jdk/com/sun/jndi/dns/AttributeTests/GetAny.java
test/jdk/com/sun/jndi/dns/lib/DNSServer.java
test/jdk/com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java
--- a/test/jdk/com/sun/jndi/dns/AttributeTests/GetAny.java	Sun Mar 04 17:05:29 2018 -0500
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAny.java	Sun Mar 04 18:46:07 2018 -0800
@@ -26,8 +26,7 @@
  * @bug 8195976
  * @summary Tests that we can get the attributes of a DNS entry using special
  *          qualifiers.
- * @modules java.xml.bind
- *          java.base/sun.security.util
+ * @modules java.base/sun.security.util
  * @library ../lib/
  * @build DNSTestUtils DNSServer DNSTracer
  * @run main GetAny
--- a/test/jdk/com/sun/jndi/dns/lib/DNSServer.java	Sun Mar 04 17:05:29 2018 -0500
+++ b/test/jdk/com/sun/jndi/dns/lib/DNSServer.java	Sun Mar 04 18:46:07 2018 -0800
@@ -23,7 +23,6 @@
 
 import sun.security.util.HexDumpEncoder;
 
-import javax.xml.bind.DatatypeConverter;
 import java.io.IOException;
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
@@ -196,7 +195,7 @@
      * Add an DNS encoding to the cache (by request message key).
      */
     private void addToCache(String hexString) {
-        byte[] encoding = DatatypeConverter.parseHexBinary(hexString);
+        byte[] encoding = parseHexBinary(hexString);
         if (encoding.length < DNS_HEADER_SIZE) {
             throw new RuntimeException("Invalid DNS message : " + hexString);
         }
@@ -261,4 +260,43 @@
 
         return payload;
     }
+
+    public static byte[] parseHexBinary(String s) {
+
+        final int len = s.length();
+
+        // "111" is not a valid hex encoding.
+        if (len % 2 != 0) {
+            throw new IllegalArgumentException(
+                    "hexBinary needs to be even-length: " + s);
+        }
+
+        byte[] out = new byte[len / 2];
+
+        for (int i = 0; i < len; i += 2) {
+            int h = hexToBin(s.charAt(i));
+            int l = hexToBin(s.charAt(i + 1));
+            if (h == -1 || l == -1) {
+                throw new IllegalArgumentException(
+                        "contains illegal character for hexBinary: " + s);
+            }
+
+            out[i / 2] = (byte) (h * 16 + l);
+        }
+
+        return out;
+    }
+
+    private static int hexToBin(char ch) {
+        if ('0' <= ch && ch <= '9') {
+            return ch - '0';
+        }
+        if ('A' <= ch && ch <= 'F') {
+            return ch - 'A' + 10;
+        }
+        if ('a' <= ch && ch <= 'f') {
+            return ch - 'a' + 10;
+        }
+        return -1;
+    }
 }
--- a/test/jdk/com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java	Sun Mar 04 17:05:29 2018 -0500
+++ b/test/jdk/com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java	Sun Mar 04 18:46:07 2018 -0800
@@ -26,11 +26,10 @@
  * @bug 8196770
  * @summary Verify capability to add a new entry to the directory using the
  *          ADD operation.
- * @modules java.xml.bind
- *          java.naming/com.sun.jndi.ldap
+ * @modules java.naming/com.sun.jndi.ldap
  * @library ../../lib/ /javax/naming/module/src/test/test/
  * @build LDAPServer LDAPTestUtils
- * @run main AddNewEntry
+ * @run main/othervm AddNewEntry
  */
 
 import javax.naming.NamingEnumeration;