From 67bff2db55036a175c6ec72f76f1e95be1948130 Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Wed, 7 Oct 2009 17:23:02 +0100 Subject: [PATCH 1/9] 6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces Reviewed-by: alanb --- .../net/MulticastSocket/SetOutgoingIf.java | 212 ++++++++++++------ 1 file changed, 147 insertions(+), 65 deletions(-) diff --git a/jdk/test/java/net/MulticastSocket/SetOutgoingIf.java b/jdk/test/java/net/MulticastSocket/SetOutgoingIf.java index d793f196215..7aa546a5cf3 100644 --- a/jdk/test/java/net/MulticastSocket/SetOutgoingIf.java +++ b/jdk/test/java/net/MulticastSocket/SetOutgoingIf.java @@ -27,7 +27,6 @@ * @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code */ import java.net.*; -import java.util.concurrent.*; import java.util.*; @@ -68,38 +67,61 @@ public class SetOutgoingIf { // We need 2 or more network interfaces to run the test // - List nics = new ArrayList(); + List netIfs = new ArrayList(); + int index = 1; for (NetworkInterface nic : Collections.list(NetworkInterface.getNetworkInterfaces())) { // we should use only network interfaces with multicast support which are in "up" state - if (!nic.isLoopback() && nic.supportsMulticast() && nic.isUp()) - nics.add(nic); + if (!nic.isLoopback() && nic.supportsMulticast() && nic.isUp()) { + NetIf netIf = NetIf.create(nic); + + // now determine what (if any) type of addresses are assigned to this interface + for (InetAddress addr : Collections.list(nic.getInetAddresses())) { + if (addr instanceof Inet4Address) { + netIf.ipv4Address(true); + } else if (addr instanceof Inet6Address) { + netIf.ipv6Address(true); + } + } + if (netIf.ipv4Address() || netIf.ipv6Address()) { + netIf.index(index++); + netIfs.add(netIf); + debug("Using: " + nic); + } + } } - if (nics.size() <= 1) { + if (netIfs.size() <= 1) { System.out.println("Need 2 or more network interfaces to run. Bye."); return; } - // We will send packets to one ipv4, one ipv4-mapped, and one ipv6 + // We will send packets to one ipv4, and one ipv6 // multicast group using each network interface :- // 224.1.1.1 --| - // ::ffff:224.1.1.2 -----> using network interface #1 - // ff02::1:1 --| + // ff02::1:1 --|--> using network interface #1 // 224.1.2.1 --| - // ::ffff:224.1.2.2 -----> using network interface #2 - // ff02::1:2 --| + // ff02::1:2 --|--> using network interface #2 // and so on. // - List groups = new ArrayList(); - for (int i = 0; i < nics.size(); i++) { - InetAddress groupv4 = InetAddress.getByName("224.1." + (i+1) + ".1"); - InetAddress groupv4mapped = InetAddress.getByName("::ffff:224.1." + (i+1) + ".2"); - InetAddress groupv6 = InetAddress.getByName("ff02::1:" + (i+1)); - groups.add(groupv4); - groups.add(groupv4mapped); - groups.add(groupv6); + for (NetIf netIf : netIfs) { + int NetIfIndex = netIf.index(); + List groups = new ArrayList(); - // use a separated thread to send to those 3 groups - Thread sender = new Thread(new Sender(nics.get(i), groupv4, groupv4mapped, groupv6, PORT)); + if (netIf.ipv4Address()) { + InetAddress groupv4 = InetAddress.getByName("224.1." + NetIfIndex + ".1"); + groups.add(groupv4); + } + if (netIf.ipv6Address()) { + InetAddress groupv6 = InetAddress.getByName("ff02::1:" + NetIfIndex); + groups.add(groupv6); + } + + debug("Adding " + groups + " groups for " + netIf.nic().getName()); + netIf.groups(groups); + + // use a separated thread to send to those 2 groups + Thread sender = new Thread(new Sender(netIf, + groups, + PORT)); sender.setDaemon(true); // we want sender to stop when main thread exits sender.start(); } @@ -108,75 +130,135 @@ public class SetOutgoingIf { // from the expected network interface // byte[] buf = new byte[1024]; - for (InetAddress group : groups) { - MulticastSocket mcastsock = new MulticastSocket(PORT); - mcastsock.setSoTimeout(5000); // 5 second - DatagramPacket packet = new DatagramPacket(buf, 0, buf.length); + for (NetIf netIf : netIfs) { + NetworkInterface nic = netIf.nic(); + for (InetAddress group : netIf.groups()) { + MulticastSocket mcastsock = new MulticastSocket(PORT); + mcastsock.setSoTimeout(5000); // 5 second + DatagramPacket packet = new DatagramPacket(buf, 0, buf.length); - mcastsock.joinGroup(new InetSocketAddress(group, PORT), nics.get(groups.indexOf(group) / 3)); + // the interface supports the IP multicast group + debug("Joining " + group + " on " + nic.getName()); + mcastsock.joinGroup(new InetSocketAddress(group, PORT), nic); - try { - mcastsock.receive(packet); - } catch (Exception e) { - // test failed if any exception - throw new RuntimeException(e); + try { + mcastsock.receive(packet); + debug("received packet on " + packet.getAddress()); + } catch (Exception e) { + // test failed if any exception + throw new RuntimeException(e); + } + + // now check which network interface this packet comes from + NetworkInterface from = NetworkInterface.getByInetAddress(packet.getAddress()); + NetworkInterface shouldbe = nic; + if (!from.equals(shouldbe)) { + System.out.println("Packets on group " + + group + " should come from " + + shouldbe.getName() + ", but came from " + + from.getName()); + //throw new RuntimeException("Test failed."); + } + + mcastsock.leaveGroup(new InetSocketAddress(group, PORT), nic); } - - // now check which network interface this packet comes from - NetworkInterface from = NetworkInterface.getByInetAddress(packet.getAddress()); - NetworkInterface shouldbe = nics.get(groups.indexOf(group) / 3); - if (!from.equals(shouldbe)) { - System.out.println("Packets on group " - + group + " should come from " - + shouldbe.getName() + ", but came from " - + from.getName()); - //throw new RuntimeException("Test failed."); - } - - mcastsock.leaveGroup(new InetSocketAddress(group, PORT), nics.get(groups.indexOf(group) / 3)); } } + + private static boolean debug = true; + + static void debug(String message) { + if (debug) + System.out.println(message); + } } class Sender implements Runnable { - private NetworkInterface nic; - private InetAddress group1; - private InetAddress group2; - private InetAddress group3; + private NetIf netIf; + private List groups; private int port; - public Sender(NetworkInterface nic, - InetAddress groupv4, InetAddress groupv4mapped, InetAddress groupv6, - int port) { - this.nic = nic; - group1 = groupv4; - group2 = groupv4mapped; - group3 = groupv6; + public Sender(NetIf netIf, + List groups, + int port) { + this.netIf = netIf; + this.groups = groups; this.port = port; } public void run() { try { MulticastSocket mcastsock = new MulticastSocket(); - mcastsock.setNetworkInterface(nic); + mcastsock.setNetworkInterface(netIf.nic()); + List packets = new LinkedList(); byte[] buf = "hello world".getBytes(); - DatagramPacket packet1 = new DatagramPacket(buf, buf.length, - new InetSocketAddress(group1, port)); - DatagramPacket packet2 = new DatagramPacket(buf, buf.length, - new InetSocketAddress(group2, port)); - DatagramPacket packet3 = new DatagramPacket(buf, buf.length, - new InetSocketAddress(group3, port)); + for (InetAddress group : groups) { + packets.add(new DatagramPacket(buf, buf.length, new InetSocketAddress(group, port))); + } for (;;) { - mcastsock.send(packet1); - mcastsock.send(packet2); - mcastsock.send(packet3); + for (DatagramPacket packet : packets) + mcastsock.send(packet); - Thread.currentThread().sleep(1000); // sleep 1 second + Thread.sleep(1000); // sleep 1 second } } catch (Exception e) { throw new RuntimeException(e); } } } + +@SuppressWarnings("unchecked") +class NetIf { + private boolean ipv4Address; //false + private boolean ipv6Address; //false + private int index; + List groups = Collections.EMPTY_LIST; + private final NetworkInterface nic; + + private NetIf(NetworkInterface nic) { + this.nic = nic; + } + + static NetIf create(NetworkInterface nic) { + return new NetIf(nic); + } + + NetworkInterface nic() { + return nic; + } + + boolean ipv4Address() { + return ipv4Address; + } + + void ipv4Address(boolean ipv4Address) { + this.ipv4Address = ipv4Address; + } + + boolean ipv6Address() { + return ipv6Address; + } + + void ipv6Address(boolean ipv6Address) { + this.ipv6Address = ipv6Address; + } + + int index() { + return index; + } + + void index(int index) { + this.index = index; + } + + List groups() { + return groups; + } + + void groups(List groups) { + this.groups = groups; + } +} + From 1c6255de3e939f1ea70ec8357286f90fdb473749 Mon Sep 17 00:00:00 2001 From: Tim Bell Date: Wed, 7 Oct 2009 13:53:11 -0700 Subject: [PATCH 2/9] 6888888: new javah throws NullPointerException when building in jdk/make/java/nio Use the bootstrap javah during the build until bug-ID 6889255 is fixed Reviewed-by: jjg --- jdk/make/common/shared/Defs-java.gmk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jdk/make/common/shared/Defs-java.gmk b/jdk/make/common/shared/Defs-java.gmk index f9ed6353131..eb63179f6d3 100644 --- a/jdk/make/common/shared/Defs-java.gmk +++ b/jdk/make/common/shared/Defs-java.gmk @@ -165,6 +165,11 @@ else JAVADOC_CMD = $(JAVA_TOOLS_DIR)/javadoc $(JAVA_TOOLS_FLAGS:%=-J%) endif +#always use the bootstrap javah until bug-ID 6889255 is fixed. These +#five lines should be removed as part of that fix: +JAVAH_CMD = $(JAVA_TOOLS_DIR)/javah \ + $(JAVAHFLAGS) + # Override of what javac to use (see deploy workspace) ifdef JAVAC JAVAC_CMD = $(JAVAC) From debdf79d18c773fc2df717ec80364d4e4557e87b Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Wed, 7 Oct 2009 14:04:20 -0700 Subject: [PATCH 3/9] 6480728: Byte.valueOf(byte) returns a cached value but Byte.valueOf(String) 6655735: Integer.toString() and String.valueOf(int) contain slow delegations Reviewed-by: lancea --- jdk/src/share/classes/java/lang/Byte.java | 6 +++--- jdk/src/share/classes/java/lang/Double.java | 2 +- jdk/src/share/classes/java/lang/Float.java | 2 +- jdk/src/share/classes/java/lang/Integer.java | 2 +- jdk/src/share/classes/java/lang/Long.java | 2 +- jdk/src/share/classes/java/lang/Short.java | 6 +++--- jdk/src/share/classes/java/lang/String.java | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/jdk/src/share/classes/java/lang/Byte.java b/jdk/src/share/classes/java/lang/Byte.java index 4725f3278b7..ce5adee7f53 100644 --- a/jdk/src/share/classes/java/lang/Byte.java +++ b/jdk/src/share/classes/java/lang/Byte.java @@ -201,7 +201,7 @@ public final class Byte extends Number implements Comparable { */ public static Byte valueOf(String s, int radix) throws NumberFormatException { - return new Byte(parseByte(s, radix)); + return valueOf(parseByte(s, radix)); } /** @@ -277,7 +277,7 @@ public final class Byte extends Number implements Comparable { if (i < MIN_VALUE || i > MAX_VALUE) throw new NumberFormatException( "Value " + i + " out of range from input " + nm); - return (byte)i; + return valueOf((byte)i); } /** @@ -374,7 +374,7 @@ public final class Byte extends Number implements Comparable { * base 10. */ public String toString() { - return String.valueOf((int)value); + return Integer.toString((int)value); } /** diff --git a/jdk/src/share/classes/java/lang/Double.java b/jdk/src/share/classes/java/lang/Double.java index 8efb241b808..ebc6fd3cada 100644 --- a/jdk/src/share/classes/java/lang/Double.java +++ b/jdk/src/share/classes/java/lang/Double.java @@ -629,7 +629,7 @@ public final class Double extends Number implements Comparable { * @see java.lang.Double#toString(double) */ public String toString() { - return String.valueOf(value); + return toString(value); } /** diff --git a/jdk/src/share/classes/java/lang/Float.java b/jdk/src/share/classes/java/lang/Float.java index eb133016f6b..c86b7bb1f9c 100644 --- a/jdk/src/share/classes/java/lang/Float.java +++ b/jdk/src/share/classes/java/lang/Float.java @@ -551,7 +551,7 @@ public final class Float extends Number implements Comparable { * @see java.lang.Float#toString(float) */ public String toString() { - return String.valueOf(value); + return Float.toString(value); } /** diff --git a/jdk/src/share/classes/java/lang/Integer.java b/jdk/src/share/classes/java/lang/Integer.java index 1c457c548e7..7aa03c07b5b 100644 --- a/jdk/src/share/classes/java/lang/Integer.java +++ b/jdk/src/share/classes/java/lang/Integer.java @@ -746,7 +746,7 @@ public final class Integer extends Number implements Comparable { * base 10. */ public String toString() { - return String.valueOf(value); + return toString(value); } /** diff --git a/jdk/src/share/classes/java/lang/Long.java b/jdk/src/share/classes/java/lang/Long.java index c5fd7ee5e29..2bb6da15923 100644 --- a/jdk/src/share/classes/java/lang/Long.java +++ b/jdk/src/share/classes/java/lang/Long.java @@ -761,7 +761,7 @@ public final class Long extends Number implements Comparable { * base 10. */ public String toString() { - return String.valueOf(value); + return toString(value); } /** diff --git a/jdk/src/share/classes/java/lang/Short.java b/jdk/src/share/classes/java/lang/Short.java index cf1551da8e5..b00e8b25cec 100644 --- a/jdk/src/share/classes/java/lang/Short.java +++ b/jdk/src/share/classes/java/lang/Short.java @@ -170,7 +170,7 @@ public final class Short extends Number implements Comparable { */ public static Short valueOf(String s, int radix) throws NumberFormatException { - return new Short(parseShort(s, radix)); + return valueOf(parseShort(s, radix)); } /** @@ -282,7 +282,7 @@ public final class Short extends Number implements Comparable { if (i < MIN_VALUE || i > MAX_VALUE) throw new NumberFormatException( "Value " + i + " out of range from input " + nm); - return (short)i; + return valueOf((short)i); } /** @@ -379,7 +379,7 @@ public final class Short extends Number implements Comparable { * base 10. */ public String toString() { - return String.valueOf((int)value); + return Integer.toString((int)value); } /** diff --git a/jdk/src/share/classes/java/lang/String.java b/jdk/src/share/classes/java/lang/String.java index e4327434c38..6aaf7684bf3 100644 --- a/jdk/src/share/classes/java/lang/String.java +++ b/jdk/src/share/classes/java/lang/String.java @@ -2995,7 +2995,7 @@ public final class String * @see java.lang.Integer#toString(int, int) */ public static String valueOf(int i) { - return Integer.toString(i, 10); + return Integer.toString(i); } /** @@ -3009,7 +3009,7 @@ public final class String * @see java.lang.Long#toString(long) */ public static String valueOf(long l) { - return Long.toString(l, 10); + return Long.toString(l); } /** From e31cb363017caf0e51912e980a4b8bd15d3e6b18 Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Fri, 9 Oct 2009 09:59:54 +0100 Subject: [PATCH 4/9] 6889552: Sun provider should not require LDAP CertStore to be present Reviewed-by: vinnie, mullan --- .../sun/security/provider/SunEntries.java | 2 +- .../provider/certpath/CertStoreHelper.java | 68 +++++++++++++++++ .../provider/certpath/URICertStore.java | 38 ++++++++-- .../certpath/{ => ldap}/LDAPCertStore.java | 3 +- .../certpath/ldap/LDAPCertStoreHelper.java | 73 +++++++++++++++++++ 5 files changed, 177 insertions(+), 7 deletions(-) create mode 100644 jdk/src/share/classes/sun/security/provider/certpath/CertStoreHelper.java rename jdk/src/share/classes/sun/security/provider/certpath/{ => ldap}/LDAPCertStore.java (99%) create mode 100644 jdk/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStoreHelper.java diff --git a/jdk/src/share/classes/sun/security/provider/SunEntries.java b/jdk/src/share/classes/sun/security/provider/SunEntries.java index 829ded160d1..817afb8329c 100644 --- a/jdk/src/share/classes/sun/security/provider/SunEntries.java +++ b/jdk/src/share/classes/sun/security/provider/SunEntries.java @@ -210,7 +210,7 @@ final class SunEntries { * CertStores */ map.put("CertStore.LDAP", - "sun.security.provider.certpath.LDAPCertStore"); + "sun.security.provider.certpath.ldap.LDAPCertStore"); map.put("CertStore.LDAP LDAPSchema", "RFC2587"); map.put("CertStore.Collection", "sun.security.provider.certpath.CollectionCertStore"); diff --git a/jdk/src/share/classes/sun/security/provider/certpath/CertStoreHelper.java b/jdk/src/share/classes/sun/security/provider/certpath/CertStoreHelper.java new file mode 100644 index 00000000000..a8f234226dc --- /dev/null +++ b/jdk/src/share/classes/sun/security/provider/certpath/CertStoreHelper.java @@ -0,0 +1,68 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package sun.security.provider.certpath; + +import java.net.URI; +import java.util.Collection; +import java.security.NoSuchAlgorithmException; +import java.security.InvalidAlgorithmParameterException; +import java.security.cert.CertStore; +import java.security.cert.X509CertSelector; +import java.security.cert.X509CRLSelector; +import javax.security.auth.x500.X500Principal; +import java.io.IOException; + +/** + * Helper used by URICertStore when delegating to another CertStore to + * fetch certs and CRLs. + */ + +public interface CertStoreHelper { + + /** + * Returns a CertStore using the given URI as parameters. + */ + CertStore getCertStore(URI uri) + throws NoSuchAlgorithmException, InvalidAlgorithmParameterException; + + /** + * Wraps an existing X509CertSelector when needing to avoid DN matching + * issues. + */ + X509CertSelector wrap(X509CertSelector selector, + X500Principal certSubject, + String dn) + throws IOException; + + /** + * Wraps an existing X509CRLSelector when needing to avoid DN matching + * issues. + */ + X509CRLSelector wrap(X509CRLSelector selector, + Collection certIssuers, + String dn) + throws IOException; +} diff --git a/jdk/src/share/classes/sun/security/provider/certpath/URICertStore.java b/jdk/src/share/classes/sun/security/provider/certpath/URICertStore.java index 3c0220bbcf9..b042dd78a9b 100644 --- a/jdk/src/share/classes/sun/security/provider/certpath/URICertStore.java +++ b/jdk/src/share/classes/sun/security/provider/certpath/URICertStore.java @@ -30,6 +30,8 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URI; import java.net.URLConnection; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import java.security.Provider; @@ -120,6 +122,32 @@ class URICertStore extends CertStoreSpi { private CertStore ldapCertStore; private String ldapPath; + /** + * Holder class to lazily load LDAPCertStoreHelper if present. + */ + private static class LDAP { + private static final String CERT_STORE_HELPER = + "sun.security.provider.certpath.ldap.LDAPCertStoreHelper"; + private static final CertStoreHelper helper = + AccessController.doPrivileged( + new PrivilegedAction() { + public CertStoreHelper run() { + try { + Class c = Class.forName(CERT_STORE_HELPER, true, null); + return (CertStoreHelper)c.newInstance(); + } catch (ClassNotFoundException cnf) { + return null; + } catch (InstantiationException e) { + throw new AssertionError(e); + } catch (IllegalAccessException e) { + throw new AssertionError(e); + } + }}); + static CertStoreHelper helper() { + return helper; + } + } + /** * Creates a URICertStore. * @@ -135,9 +163,10 @@ class URICertStore extends CertStoreSpi { this.uri = ((URICertStoreParameters) params).uri; // if ldap URI, use an LDAPCertStore to fetch certs and CRLs if (uri.getScheme().toLowerCase().equals("ldap")) { + if (LDAP.helper() == null) + throw new NoSuchAlgorithmException("LDAP not present"); ldap = true; - ldapCertStore = - LDAPCertStore.getInstance(LDAPCertStore.getParameters(uri)); + ldapCertStore = LDAP.helper().getCertStore(uri); ldapPath = uri.getPath(); // strip off leading '/' if (ldapPath.charAt(0) == '/') { @@ -219,8 +248,7 @@ class URICertStore extends CertStoreSpi { if (ldap) { X509CertSelector xsel = (X509CertSelector) selector; try { - xsel = new LDAPCertStore.LDAPCertSelector - (xsel, xsel.getSubject(), ldapPath); + xsel = LDAP.helper().wrap(xsel, xsel.getSubject(), ldapPath); } catch (IOException ioe) { throw new CertStoreException(ioe); } @@ -340,7 +368,7 @@ class URICertStore extends CertStoreSpi { if (ldap) { X509CRLSelector xsel = (X509CRLSelector) selector; try { - xsel = new LDAPCertStore.LDAPCRLSelector(xsel, null, ldapPath); + xsel = LDAP.helper().wrap(xsel, null, ldapPath); } catch (IOException ioe) { throw new CertStoreException(ioe); } diff --git a/jdk/src/share/classes/sun/security/provider/certpath/LDAPCertStore.java b/jdk/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStore.java similarity index 99% rename from jdk/src/share/classes/sun/security/provider/certpath/LDAPCertStore.java rename to jdk/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStore.java index f7b567bef39..3517245e550 100644 --- a/jdk/src/share/classes/sun/security/provider/certpath/LDAPCertStore.java +++ b/jdk/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStore.java @@ -23,7 +23,7 @@ * have any questions. */ -package sun.security.provider.certpath; +package sun.security.provider.certpath.ldap; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -46,6 +46,7 @@ import java.security.cert.*; import javax.security.auth.x500.X500Principal; import sun.misc.HexDumpEncoder; +import sun.security.provider.certpath.X509CertificatePair; import sun.security.util.Cache; import sun.security.util.Debug; import sun.security.x509.X500Name; diff --git a/jdk/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStoreHelper.java b/jdk/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStoreHelper.java new file mode 100644 index 00000000000..3667022d04d --- /dev/null +++ b/jdk/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStoreHelper.java @@ -0,0 +1,73 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package sun.security.provider.certpath.ldap; + +import java.net.URI; +import java.util.Collection; +import java.security.NoSuchAlgorithmException; +import java.security.InvalidAlgorithmParameterException; +import java.security.cert.CertStore; +import java.security.cert.X509CertSelector; +import java.security.cert.X509CRLSelector; +import javax.security.auth.x500.X500Principal; +import java.io.IOException; + +import sun.security.provider.certpath.CertStoreHelper; + +/** + * LDAP implementation of CertStoreHelper. + */ + +public class LDAPCertStoreHelper + implements CertStoreHelper +{ + public LDAPCertStoreHelper() { } + + @Override + public CertStore getCertStore(URI uri) + throws NoSuchAlgorithmException, InvalidAlgorithmParameterException + { + return LDAPCertStore.getInstance(LDAPCertStore.getParameters(uri)); + } + + @Override + public X509CertSelector wrap(X509CertSelector selector, + X500Principal certSubject, + String ldapDN) + throws IOException + { + return new LDAPCertStore.LDAPCertSelector(selector, certSubject, ldapDN); + } + + @Override + public X509CRLSelector wrap(X509CRLSelector selector, + Collection certIssuers, + String ldapDN) + throws IOException + { + return new LDAPCertStore.LDAPCRLSelector(selector, certIssuers, ldapDN); + } +} From c44758929fcfa1a558bd1944bbe4c0ec63fee438 Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Fri, 9 Oct 2009 10:06:58 +0100 Subject: [PATCH 5/9] 6888552: Allow JNDI to be used when java.applet is not present Reviewed-by: vinnie --- .../sun/naming/internal/ResourceManager.java | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/jdk/src/share/classes/com/sun/naming/internal/ResourceManager.java b/jdk/src/share/classes/com/sun/naming/internal/ResourceManager.java index d02faa63cba..ec46bfdf2c0 100644 --- a/jdk/src/share/classes/com/sun/naming/internal/ResourceManager.java +++ b/jdk/src/share/classes/com/sun/naming/internal/ResourceManager.java @@ -25,11 +25,12 @@ package com.sun.naming.internal; -import java.applet.Applet; import java.io.InputStream; import java.io.IOException; import java.net.URL; import java.lang.ref.WeakReference; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; @@ -112,6 +113,52 @@ public final class ResourceManager { private static final WeakHashMap urlFactoryCache = new WeakHashMap(11); private static final WeakReference NO_FACTORY = new WeakReference(null); + /** + * A class to allow JNDI properties be specified as applet parameters + * without creating a static dependency on java.applet. + */ + private static class AppletParameter { + private static final Class clazz = getClass("java.applet.Applet"); + private static final Method getMethod = + getMethod(clazz, "getParameter", String.class); + private static Class getClass(String name) { + try { + return Class.forName(name, true, null); + } catch (ClassNotFoundException e) { + return null; + } + } + private static Method getMethod(Class clazz, + String name, + Class... paramTypes) + { + if (clazz != null) { + try { + return clazz.getMethod(name, paramTypes); + } catch (NoSuchMethodException e) { + throw new AssertionError(e); + } + } else { + return null; + } + } + + /** + * Returns the value of the applet's named parameter. + */ + static Object get(Object applet, String name) { + // if clazz is null then applet cannot be an Applet. + if (clazz == null || !clazz.isInstance(applet)) + throw new ClassCastException(applet.getClass().getName()); + try { + return getMethod.invoke(applet, name); + } catch (InvocationTargetException e) { + throw new AssertionError(e); + } catch (IllegalAccessException iae) { + throw new AssertionError(iae); + } + } + } // There should be no instances of this class. private ResourceManager() { @@ -143,7 +190,7 @@ public final class ResourceManager { if (env == null) { env = new Hashtable(11); } - Applet applet = (Applet)env.get(Context.APPLET); + Object applet = env.get(Context.APPLET); // Merge property values from env param, applet params, and system // properties. The first value wins: there's no concatenation of @@ -157,7 +204,7 @@ public final class ResourceManager { Object val = env.get(props[i]); if (val == null) { if (applet != null) { - val = applet.getParameter(props[i]); + val = AppletParameter.get(applet, props[i]); } if (val == null) { // Read system property. From eca779ecad50de07607a3ea7e5a0feb66fdacac8 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Fri, 9 Oct 2009 16:11:11 -0700 Subject: [PATCH 6/9] 6797535: Add shared two argument static equals method to the platform Reviewed-by: sherman --- jdk/make/java/java/FILES_java.gmk | 1 + jdk/src/share/classes/java/util/Objects.java | 110 ++++++++++++++++++ .../java/util/Objects/BasicObjectsTest.java | 105 +++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 jdk/src/share/classes/java/util/Objects.java create mode 100644 jdk/test/java/util/Objects/BasicObjectsTest.java diff --git a/jdk/make/java/java/FILES_java.gmk b/jdk/make/java/java/FILES_java.gmk index 2ad599cbe23..d9b7e153d72 100644 --- a/jdk/make/java/java/FILES_java.gmk +++ b/jdk/make/java/java/FILES_java.gmk @@ -258,6 +258,7 @@ JAVA_JAVA_java = \ java/util/ServiceConfigurationError.java \ java/util/Timer.java \ java/util/TimerTask.java \ + java/util/Objects.java \ java/util/UUID.java \ java/util/concurrent/AbstractExecutorService.java \ java/util/concurrent/ArrayBlockingQueue.java \ diff --git a/jdk/src/share/classes/java/util/Objects.java b/jdk/src/share/classes/java/util/Objects.java new file mode 100644 index 00000000000..9d05c314d89 --- /dev/null +++ b/jdk/src/share/classes/java/util/Objects.java @@ -0,0 +1,110 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package java.util; + +/** + * This class consists of {@code static} utility methods for operating + * on objects. These utilities include {@code null}-safe or {@code + * null}-tolerant methods for computing the hash code of an object, + * returning a string for an object, and comparing two objects. + * + * @since 1.7 + */ +public class Objects { + private Objects() { + throw new AssertionError("No java.util.Objects instances for you!"); + } + + /** + * Returns {@code true} if the arguments are equal to each other + * and {@code false} otherwise. + * Consequently, if both arguments are {@code null}, {@code true} + * is returned and if exactly one argument is {@code null}, {@code + * false} is returned. Otherwise, equality is determined by using + * the {@link Object#equals equals} method of the first + * argument. + * + * @param a an object + * @param b an object to be compared with {@code a} for equality + * @return {@code true} if the arguments are equal to each other + * and {@code false} otherwise + * @see Object#equals(Object) + */ + public static boolean equals(Object a, Object b) { + return (a == b) || (a != null && a.equals(b)); + } + + /** + * Returns the hash code of a non-{@code null} argument and 0 for + * a {@code null} argument. + * + * @param o an object + * @return the hash code of a non-{@code null} argument and 0 for + * a {@code null} argument + * @see Object#hashCode + */ + public static int hashCode(Object o) { + return o != null ? o.hashCode() : 0; + } + + /** + * Returns the result of calling {@code toString} for a non-{@code + * null} argument and {@code "null"} for a {@code null} argument. + * + * @param o an object + * @return the result of calling {@code toString} for a non-{@code + * null} argument and {@code "null"} for a {@code null} argument + * @see Object#toString + * @see String#valueOf(Object) + */ + public static String toString(Object o) { + return String.valueOf(o); + } + + /** + * Returns 0 if the arguments are identical and {@code + * c.compare(a, b)} otherwise. + * Consequently, if both arguments are {@code null} 0 + * is returned. + * + *

Note that if one of the arguments is {@code null}, a {@code + * NullPointerException} may or may not be thrown depending on + * what ordering policy, if any, the {@link Comparator Comparator} + * chooses to have for {@code null} values. + * + * @param the type of the objects being compared + * @param a an object + * @param b an object to be compared with {@code a} + * @param c the {@code Comparator} to compare the first two arguments + * @return 0 if the arguments are identical and {@code + * c.compare(a, b)} otherwise. + * @see Comparable + * @see Comparator + */ + public static int compare(T a, T b, Comparator c) { + return (a == b) ? 0 : c.compare(a, b); + } +} diff --git a/jdk/test/java/util/Objects/BasicObjectsTest.java b/jdk/test/java/util/Objects/BasicObjectsTest.java new file mode 100644 index 00000000000..be45b2c92ed --- /dev/null +++ b/jdk/test/java/util/Objects/BasicObjectsTest.java @@ -0,0 +1,105 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6797535 + * @summary Basic tests for methods in java.util.Objects + * @author Joseph D. Darcy + */ + +import java.util.*; + +public class BasicObjectsTest { + public static void main(String... args) { + int errors = 0; + errors += testEquals(); + errors += testHashCode(); + errors += testToString(); + errors += testCompare(); + if (errors > 0 ) + throw new RuntimeException(); + } + + private static int testEquals() { + int errors = 0; + Object[] values = {null, "42", 42}; + for(int i = 0; i < values.length; i++) + for(int j = 0; j < values.length; j++) { + boolean expected = (i == j); + Object a = values[i]; + Object b = values[j]; + boolean result = Objects.equals(a, b); + if (result != expected) { + errors++; + System.err.printf("When equating %s to %s, got %b instead of %b%n.", + a, b, result, expected); + } + } + return errors; + } + + private static int testHashCode() { + int errors = 0; + errors += (Objects.hashCode(null) == 0 ) ? 0 : 1; + String s = "42"; + errors += (Objects.hashCode(s) == s.hashCode() ) ? 0 : 1; + return errors; + } + + private static int testToString() { + int errors = 0; + errors += ("null".equals(Objects.toString(null)) ) ? 0 : 1; + String s = "Some string"; + errors += (s.equals(Objects.toString(s)) ) ? 0 : 1; + return errors; + } + + private static int testCompare() { + int errors = 0; + String[] values = {"e. e. cummings", "zzz"}; + String[] VALUES = {"E. E. Cummings", "ZZZ"}; + errors += compareTest(null, null, 0); + for(int i = 0; i < values.length; i++) { + String a = values[i]; + errors += compareTest(a, a, 0); + for(int j = 0; j < VALUES.length; j++) { + int expected = Integer.compare(i, j); + String b = VALUES[j]; + errors += compareTest(a, b, expected); + } + } + return errors; + } + + private static int compareTest(String a, String b, int expected) { + int errors = 0; + int result = Objects.compare(a, b, String.CASE_INSENSITIVE_ORDER); + if (Integer.signum(result) != Integer.signum(expected)) { + errors++; + System.err.printf("When comparing %s to %s, got %d instead of %d%n.", + a, b, result, expected); + } + return errors; + } +} From 8b993775d5b32f28886d3cc06a7f8977ccd54609 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Tue, 13 Oct 2009 14:08:57 -0700 Subject: [PATCH 7/9] 6648344: (reflect spec) State default of isAccessible for reflective objects Reviewed-by: alanb --- .../java/lang/reflect/AccessibleObject.java | 2 + .../lang/reflect/DefaultAccessibility.java | 69 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 jdk/test/java/lang/reflect/DefaultAccessibility.java diff --git a/jdk/src/share/classes/java/lang/reflect/AccessibleObject.java b/jdk/src/share/classes/java/lang/reflect/AccessibleObject.java index 1f94a4c5a15..a48f6b19867 100644 --- a/jdk/src/share/classes/java/lang/reflect/AccessibleObject.java +++ b/jdk/src/share/classes/java/lang/reflect/AccessibleObject.java @@ -44,6 +44,8 @@ import java.lang.annotation.Annotation; * as Java Object Serialization or other persistence mechanisms, to * manipulate objects in a manner that would normally be prohibited. * + *

By default, a reflected object is not accessible. + * * @see Field * @see Method * @see Constructor diff --git a/jdk/test/java/lang/reflect/DefaultAccessibility.java b/jdk/test/java/lang/reflect/DefaultAccessibility.java new file mode 100644 index 00000000000..0f74d044ef6 --- /dev/null +++ b/jdk/test/java/lang/reflect/DefaultAccessibility.java @@ -0,0 +1,69 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6648344 + * @summary Test that default accessibility is false + * @author Joseph D. Darcy + */ + +import java.lang.reflect.*; + +public class DefaultAccessibility { + private DefaultAccessibility() { + super(); + } + + private static int f = 42; + + public static void main(String... args) throws Exception { + Class daClass = (new DefaultAccessibility()).getClass(); + + int elementCount = 0; + for(Constructor ctor : daClass.getDeclaredConstructors()) { + elementCount++; + if (ctor.isAccessible()) + throw new RuntimeException("Unexpected accessibility for constructor " + + ctor); + } + + for(Method method : daClass.getDeclaredMethods()) { + elementCount++; + if (method.isAccessible()) + throw new RuntimeException("Unexpected accessibility for method " + + method); + } + + for(Field field : daClass.getDeclaredFields()) { + elementCount++; + if (field.isAccessible()) + throw new RuntimeException("Unexpected accessibility for field " + + field); + } + + if (elementCount < 3) + throw new RuntimeException("Expected at least three members; only found " + + elementCount); + } +} From f276d82e07b44c4a14f2e2814777b1606991bab1 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Tue, 13 Oct 2009 17:34:48 -0700 Subject: [PATCH 8/9] 6349921: (enum) Include links from java.lang.Enum to EnumSet and EnumMap Reviewed-by: martin --- jdk/src/share/classes/java/lang/Enum.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/jdk/src/share/classes/java/lang/Enum.java b/jdk/src/share/classes/java/lang/Enum.java index 5df8146c1d4..30ae3d8697b 100644 --- a/jdk/src/share/classes/java/lang/Enum.java +++ b/jdk/src/share/classes/java/lang/Enum.java @@ -40,10 +40,17 @@ import java.io.ObjectStreamException; * Edition, §8.9. * + *

Note that when using an enumeration type as the type of a set + * or as the type of the keys in a map, specialized and efficient + * {@linkplain java.util.EnumSet set} and {@linkplain + * java.util.EnumMap map} implementations are available. + * * @param The enum type subclass * @author Josh Bloch * @author Neal Gafter * @see Class#getEnumConstants() + * @see java.util.EnumSet + * @see java.util.EnumMap * @since 1.5 */ public abstract class Enum> From 581d01d8c4e037c0fae2b1271af8b6bcd59fb364 Mon Sep 17 00:00:00 2001 From: Sean Mullan Date: Wed, 14 Oct 2009 09:36:31 -0400 Subject: [PATCH 9/9] 6885667: CertPath/CertPathValidatorTest/bugs/bug6383078 fails on jdk6u18/b02, jdk7/pit/b73 and passes on b72 Wrap all OCSP exceptions in CertPathValidatorException so that we can fallback to CRLs, if enabled. Reviewed-by: dgu, xuelei --- .../classes/sun/security/provider/certpath/OCSP.java | 4 ++++ .../sun/security/provider/certpath/OCSPChecker.java | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jdk/src/share/classes/sun/security/provider/certpath/OCSP.java b/jdk/src/share/classes/sun/security/provider/certpath/OCSP.java index 2665de6d680..dfdd846c5b8 100644 --- a/jdk/src/share/classes/sun/security/provider/certpath/OCSP.java +++ b/jdk/src/share/classes/sun/security/provider/certpath/OCSP.java @@ -64,6 +64,8 @@ public final class OCSP { private static final Debug debug = Debug.getInstance("certpath"); + private static final int CONNECT_TIMEOUT = 15000; // 15 seconds + private OCSP() {} /** @@ -176,6 +178,8 @@ public final class OCSP { debug.println("connecting to OCSP service at: " + url); } HttpURLConnection con = (HttpURLConnection)url.openConnection(); + con.setConnectTimeout(CONNECT_TIMEOUT); + con.setReadTimeout(CONNECT_TIMEOUT); con.setDoOutput(true); con.setDoInput(true); con.setRequestMethod("POST"); diff --git a/jdk/src/share/classes/sun/security/provider/certpath/OCSPChecker.java b/jdk/src/share/classes/sun/security/provider/certpath/OCSPChecker.java index 6f72c7ec185..499a5912aca 100644 --- a/jdk/src/share/classes/sun/security/provider/certpath/OCSPChecker.java +++ b/jdk/src/share/classes/sun/security/provider/certpath/OCSPChecker.java @@ -25,7 +25,6 @@ package sun.security.provider.certpath; -import java.io.IOException; import java.math.BigInteger; import java.util.*; import java.security.AccessController; @@ -335,10 +334,11 @@ class OCSPChecker extends PKIXCertPathChecker { (issuerCert, currCertImpl.getSerialNumberObject()); response = OCSP.check(Collections.singletonList(certId), uri, responderCert, pkixParams.getDate()); - } catch (IOException ioe) { - // should allow this to pass if network failures are acceptable + } catch (Exception e) { + // Wrap all exceptions in CertPathValidatorException so that + // we can fallback to CRLs, if enabled. throw new CertPathValidatorException - ("Unable to send OCSP request", ioe); + ("Unable to send OCSP request", e); } RevocationStatus rs = (RevocationStatus) response.getSingleResponse(certId);