diff --git a/make/java/java/FILES_java.gmk b/make/java/java/FILES_java.gmk index 2ad599cbe235749e97c5128835fc249191bce42c..d9b7e153d727147a3d9f48991d103b4f29f582a6 100644 --- a/make/java/java/FILES_java.gmk +++ b/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/src/share/classes/com/sun/naming/internal/ResourceManager.java b/src/share/classes/com/sun/naming/internal/ResourceManager.java index d02faa63cba77f075caa5ffbd1c7656e0fed028c..ec46bfdf2c013b65474a5d0f1818ebb2b6d1e937 100644 --- a/src/share/classes/com/sun/naming/internal/ResourceManager.java +++ b/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. diff --git a/src/share/classes/java/io/FilePermission.java b/src/share/classes/java/io/FilePermission.java index 88c98fbddf3948868f03aebfcefd0b59c96cc4cb..aeab68b7907b75abaacfd681cff1255257e3c997 100644 --- a/src/share/classes/java/io/FilePermission.java +++ b/src/share/classes/java/io/FilePermission.java @@ -209,7 +209,17 @@ public final class FilePermission extends Permission implements Serializable { cpath = AccessController.doPrivileged(new PrivilegedAction() { public String run() { try { - return sun.security.provider.PolicyFile.canonPath(cpath); + String path = cpath; + if (cpath.endsWith("*")) { + // call getCanonicalPath with a path with wildcard character + // replaced to avoid calling it with paths that are + // intended to match all entries in a directory + path = path.substring(0, path.length()-1) + "-"; + path = new File(path).getCanonicalPath(); + return path.substring(0, path.length()-1) + "*"; + } else { + return new File(path).getCanonicalPath(); + } } catch (IOException ioe) { return cpath; } diff --git a/src/share/classes/java/lang/Enum.java b/src/share/classes/java/lang/Enum.java index 5df8146c1d44ac57a0e7211f6aff912627f494d8..30ae3d8697b50c6b25b5d065cbe8b1b8abb8a1f1 100644 --- a/src/share/classes/java/lang/Enum.java +++ b/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> diff --git a/src/share/classes/java/lang/reflect/AccessibleObject.java b/src/share/classes/java/lang/reflect/AccessibleObject.java index 1f94a4c5a154ca6c9a600ebf6b1254193d5613fc..a48f6b19867f6eed7e39225a8bbc0978f141caf6 100644 --- a/src/share/classes/java/lang/reflect/AccessibleObject.java +++ b/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/src/share/classes/java/util/Objects.java b/src/share/classes/java/util/Objects.java new file mode 100644 index 0000000000000000000000000000000000000000..9d05c314d891d82a076b2ee612c3bbb516e4ed8c --- /dev/null +++ b/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/src/share/classes/java/util/jar/JarVerifier.java b/src/share/classes/java/util/jar/JarVerifier.java index 54954413e59993576c20f38f76099ebdaf905327..099cf7abbb4058970ced181acd988c06ed2bfef3 100644 --- a/src/share/classes/java/util/jar/JarVerifier.java +++ b/src/share/classes/java/util/jar/JarVerifier.java @@ -293,10 +293,8 @@ class JarVerifier { } sfv.process(sigFileSigners); - } catch (sun.security.pkcs.ParsingException pe) { - if (debug != null) debug.println("processEntry caught: "+pe); - // ignore and treat as unsigned } catch (IOException ioe) { + // e.g. sun.security.pkcs.ParsingException if (debug != null) debug.println("processEntry caught: "+ioe); // ignore and treat as unsigned } catch (SignatureException se) { diff --git a/src/share/classes/sun/misc/FloatingDecimal.java b/src/share/classes/sun/misc/FloatingDecimal.java index f0316ff56315b4c917817c0bfedd961e9d9754f9..279dd6180fe1392ede11a3f147c31ae925374cb9 100644 --- a/src/share/classes/sun/misc/FloatingDecimal.java +++ b/src/share/classes/sun/misc/FloatingDecimal.java @@ -730,7 +730,7 @@ public class FloatingDecimal{ * Thus we will need more than one digit if we're using * E-form */ - if ( decExp <= -3 || decExp >= 8 ){ + if ( decExp < -3 || decExp >= 8 ){ high = low = false; } while( ! low && ! high ){ @@ -783,7 +783,7 @@ public class FloatingDecimal{ * Thus we will need more than one digit if we're using * E-form */ - if ( decExp <= -3 || decExp >= 8 ){ + if ( decExp < -3 || decExp >= 8 ){ high = low = false; } while( ! low && ! high ){ @@ -847,7 +847,7 @@ public class FloatingDecimal{ * Thus we will need more than one digit if we're using * E-form */ - if ( decExp <= -3 || decExp >= 8 ){ + if ( decExp < -3 || decExp >= 8 ){ high = low = false; } while( ! low && ! high ){ diff --git a/src/share/classes/sun/net/httpserver/ExchangeImpl.java b/src/share/classes/sun/net/httpserver/ExchangeImpl.java index f15a3d0d57390f3235f4ce9a2936eb968181bbaa..ccb9151b69c1623961e934275661ac87d43778d1 100644 --- a/src/share/classes/sun/net/httpserver/ExchangeImpl.java +++ b/src/share/classes/sun/net/httpserver/ExchangeImpl.java @@ -31,6 +31,7 @@ import java.nio.channels.*; import java.net.*; import javax.net.ssl.*; import java.util.*; +import java.util.logging.Logger; import java.text.*; import sun.net.www.MessageHeader; import com.sun.net.httpserver.*; @@ -204,6 +205,21 @@ class ExchangeImpl { tmpout.write (bytes(statusLine, 0), 0, statusLine.length()); boolean noContentToSend = false; // assume there is content rspHdrs.set ("Date", df.format (new Date())); + + /* check for response type that is not allowed to send a body */ + + if ((rCode>=100 && rCode <200) /* informational */ + ||(rCode == 204) /* no content */ + ||(rCode == 304)) /* not modified */ + { + if (contentLen != -1) { + Logger logger = server.getLogger(); + String msg = "sendResponseHeaders: rCode = "+ rCode + + ": forcing contentLen = -1"; + logger.warning (msg); + } + contentLen = -1; + } if (contentLen == 0) { if (http10) { o.setWrappedStream (new UndefLengthOutputStream (this, ros)); diff --git a/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java b/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java index f1a60f85fe3befb948444b47464f96ba9b92a9a6..c872526e59758fffd514406d7fd59da13057369e 100644 --- a/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java +++ b/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java @@ -1180,6 +1180,10 @@ public class HttpURLConnection extends java.net.HttpURLConnection { inputStream = http.getInputStream(); respCode = getResponseCode(); + if (respCode == -1) { + disconnectInternal(); + throw new IOException ("Invalid Http response"); + } if (respCode == HTTP_PROXY_AUTH) { if (streaming()) { disconnectInternal(); diff --git a/src/share/classes/sun/security/provider/PolicyFile.java b/src/share/classes/sun/security/provider/PolicyFile.java index 324e745f375de18ba043494a1896a4fbff4a6ed5..ed4757d3cff21e7e7ded1b42d29a31b7f24a0a3e 100644 --- a/src/share/classes/sun/security/provider/PolicyFile.java +++ b/src/share/classes/sun/security/provider/PolicyFile.java @@ -1832,8 +1832,9 @@ public class PolicyFile extends java.security.Policy { return canonCs; } - // public for java.io.FilePermission - public static String canonPath(String path) throws IOException { + // Wrapper to return a canonical path that avoids calling getCanonicalPath() + // with paths that are intended to match all entries in the directory + private static String canonPath(String path) throws IOException { if (path.endsWith("*")) { path = path.substring(0, path.length()-1) + "-"; path = new File(path).getCanonicalPath(); diff --git a/src/share/classes/sun/security/provider/SunEntries.java b/src/share/classes/sun/security/provider/SunEntries.java index 829ded160d18c5f739c045ed8c27a6940da49f9c..817afb8329cb2f50e0359dcb919d786673aac986 100644 --- a/src/share/classes/sun/security/provider/SunEntries.java +++ b/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/src/share/classes/sun/security/provider/certpath/CertStoreHelper.java b/src/share/classes/sun/security/provider/certpath/CertStoreHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..a8f234226dc64728d4efb13f14ee10a1ed8ae2fb --- /dev/null +++ b/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/src/share/classes/sun/security/provider/certpath/OCSP.java b/src/share/classes/sun/security/provider/certpath/OCSP.java index 2665de6d6801c05cd8231b9c4090d5ffa69046af..dfdd846c5b879022dd8e33cd228f3d073f9880bf 100644 --- a/src/share/classes/sun/security/provider/certpath/OCSP.java +++ b/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/src/share/classes/sun/security/provider/certpath/OCSPChecker.java b/src/share/classes/sun/security/provider/certpath/OCSPChecker.java index 6f72c7ec185dc9e2fe5c80889dd75ff52fe52b8e..499a5912aca40022c639e1c42139cc8a91262418 100644 --- a/src/share/classes/sun/security/provider/certpath/OCSPChecker.java +++ b/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); diff --git a/src/share/classes/sun/security/provider/certpath/URICertStore.java b/src/share/classes/sun/security/provider/certpath/URICertStore.java index 3c0220bbcf94e1c5e575583515dcd6bb55ed3d7f..b042dd78a9bb6ecc2bee356dfed09584d60c8470 100644 --- a/src/share/classes/sun/security/provider/certpath/URICertStore.java +++ b/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/src/share/classes/sun/security/provider/certpath/LDAPCertStore.java b/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStore.java similarity index 99% rename from src/share/classes/sun/security/provider/certpath/LDAPCertStore.java rename to src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStore.java index f7b567bef397c0d83e7cebe2da37f9eecf6bb555..3517245e550453512236b7b582d390d2bc059bc1 100644 --- a/src/share/classes/sun/security/provider/certpath/LDAPCertStore.java +++ b/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/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStoreHelper.java b/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStoreHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..3667022d04db0f58b66693f16ee610cc76a2194c --- /dev/null +++ b/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); + } +} diff --git a/src/solaris/classes/sun/nio/fs/SolarisAclFileAttributeView.java b/src/solaris/classes/sun/nio/fs/SolarisAclFileAttributeView.java index c576f968197b90d9a96b25db0dc89cc70f3705a5..202efdad8cfecde0d87578b74067b75de232570e 100644 --- a/src/solaris/classes/sun/nio/fs/SolarisAclFileAttributeView.java +++ b/src/solaris/classes/sun/nio/fs/SolarisAclFileAttributeView.java @@ -104,11 +104,11 @@ class SolarisAclFileAttributeView int uid; if (user.isSpecial()) { uid = -1; - if (who.getName().equals(UnixUserPrincipals.SPECIAL_OWNER.getName())) + if (who == UnixUserPrincipals.SPECIAL_OWNER) flags |= ACE_OWNER; - else if (who.getName().equals(UnixUserPrincipals.SPECIAL_GROUP.getName())) - flags |= ACE_GROUP; - else if (who.getName().equals(UnixUserPrincipals.SPECIAL_EVERYONE.getName())) + else if (who == UnixUserPrincipals.SPECIAL_GROUP) + flags |= (ACE_GROUP | ACE_IDENTIFIER_GROUP); + else if (who == UnixUserPrincipals.SPECIAL_EVERYONE) flags |= ACE_EVERYONE; else throw new AssertionError("Unable to map special identifier"); @@ -281,7 +281,7 @@ class SolarisAclFileAttributeView aceFlags.add(AclEntryFlag.DIRECTORY_INHERIT); if ((flags & ACE_NO_PROPAGATE_INHERIT_ACE) > 0) aceFlags.add(AclEntryFlag.NO_PROPAGATE_INHERIT); - if ((flags & ACE_INHERIT_ONLY_ACE ) > 0) + if ((flags & ACE_INHERIT_ONLY_ACE) > 0) aceFlags.add(AclEntryFlag.INHERIT_ONLY); // build the ACL entry and add it to the list diff --git a/test/com/sun/net/httpserver/bugs/B6886436.java b/test/com/sun/net/httpserver/bugs/B6886436.java new file mode 100644 index 0000000000000000000000000000000000000000..2653ae7be858172408cd1e19709267c59a037468 --- /dev/null +++ b/test/com/sun/net/httpserver/bugs/B6886436.java @@ -0,0 +1,93 @@ +/* + * 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 6886436 + * @summary + */ + +import com.sun.net.httpserver.*; + +import java.util.*; +import java.util.concurrent.*; +import java.util.logging.*; +import java.io.*; +import java.net.*; + +public class B6886436 { + + public static void main (String[] args) throws Exception { + Logger logger = Logger.getLogger ("com.sun.net.httpserver"); + ConsoleHandler c = new ConsoleHandler(); + c.setLevel (Level.WARNING); + logger.addHandler (c); + logger.setLevel (Level.WARNING); + Handler handler = new Handler(); + InetSocketAddress addr = new InetSocketAddress (0); + HttpServer server = HttpServer.create (addr, 0); + HttpContext ctx = server.createContext ("/test", handler); + ExecutorService executor = Executors.newCachedThreadPool(); + server.setExecutor (executor); + server.start (); + + URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html"); + HttpURLConnection urlc = (HttpURLConnection)url.openConnection (); + try { + InputStream is = urlc.getInputStream(); + while (is.read()!= -1) ; + is.close (); + urlc = (HttpURLConnection)url.openConnection (); + urlc.setReadTimeout (3000); + is = urlc.getInputStream(); + while (is.read()!= -1); + is.close (); + + } catch (IOException e) { + server.stop(2); + executor.shutdown(); + throw new RuntimeException ("Test failed"); + } + server.stop(2); + executor.shutdown(); + System.out.println ("OK"); + } + + public static boolean error = false; + + static class Handler implements HttpHandler { + int invocation = 1; + public void handle (HttpExchange t) + throws IOException + { + InputStream is = t.getRequestBody(); + Headers map = t.getRequestHeaders(); + Headers rmap = t.getResponseHeaders(); + while (is.read () != -1) ; + is.close(); + // send a 204 response with an empty chunked body + t.sendResponseHeaders (204, 0); + t.close(); + } + } +} diff --git a/test/java/lang/Double/ToString.java b/test/java/lang/Double/ToString.java new file mode 100644 index 0000000000000000000000000000000000000000..f553d4ebb6c550c1ef6354bb6f67d493c1b0b740 --- /dev/null +++ b/test/java/lang/Double/ToString.java @@ -0,0 +1,39 @@ +/* + * 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 4428022 + * @summary Tests for Double.toString + * @author Andrew Haley + */ + +public class ToString { + + public static void main(String args[]) { + if (!Double.toString(0.001).equals("0.001")) + throw new RuntimeException("Double.toString(0.001) is not \"0.001\""); + if (!Double.toString(0.002).equals("0.002")) + throw new RuntimeException("Double.toString(0.001) is not \"0.002\""); + } +} diff --git a/test/java/lang/management/RuntimeMXBean/GetSystemProperties.java b/test/java/lang/management/RuntimeMXBean/GetSystemProperties.java index 6a324bfcd5350a882d21106f95cac83459eb9882..5a655378462943edd3fbae7bdc555765d999713c 100644 --- a/test/java/lang/management/RuntimeMXBean/GetSystemProperties.java +++ b/test/java/lang/management/RuntimeMXBean/GetSystemProperties.java @@ -49,6 +49,21 @@ public class GetSystemProperties { private static final String VALUE4 = "test.property.value4"; public static void main(String[] argv) throws Exception { + // Save a copy of the original system properties + Properties props = System.getProperties(); + + try { + // replace the system Properties object for any modification + // in case jtreg caches a copy + System.setProperties(new Properties(props)); + runTest(); + } finally { + // restore original system properties + System.setProperties(props); + } + } + + private static void runTest() throws Exception { RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean(); // Print all system properties @@ -88,7 +103,10 @@ public class GetSystemProperties { Map props2 = mbean.getSystemProperties(); // expect the system properties returned should be // same as the one before adding KEY3 and KEY4 - props1.equals(props2); + if (!props1.equals(props2)) { + throw new RuntimeException("Two copies of system properties " + + "are expected to be equal"); + } System.out.println("Test passed."); } diff --git a/test/java/lang/management/RuntimeMXBean/PropertiesTest.java b/test/java/lang/management/RuntimeMXBean/PropertiesTest.java index 2900b3c3dfb3cc5584dbf75cc79861766a1e588e..047f291dfbd4168bb41c3bd93c982ca295c19d3b 100644 --- a/test/java/lang/management/RuntimeMXBean/PropertiesTest.java +++ b/test/java/lang/management/RuntimeMXBean/PropertiesTest.java @@ -40,8 +40,21 @@ import java.lang.management.RuntimeMXBean; public class PropertiesTest { private static int NUM_MYPROPS = 3; public static void main(String[] argv) throws Exception { - Properties sysProps = System.getProperties(); + // Save a copy of the original system properties + Properties props = System.getProperties(); + try { + // replace the system Properties object for any modification + // in case jtreg caches a copy + System.setProperties(new Properties(props)); + runTest(props.size()); + } finally { + // restore original system properties + System.setProperties(props); + } + } + + private static void runTest(int sysPropsCount) throws Exception { // Create a new system properties using the old one // as the defaults Properties myProps = new Properties( System.getProperties() ); @@ -65,10 +78,10 @@ public class PropertiesTest { System.out.println(i++ + ": " + key + " : " + value); } - if (props.size() != NUM_MYPROPS + sysProps.size()) { + if (props.size() != NUM_MYPROPS + sysPropsCount) { throw new RuntimeException("Test Failed: " + "Expected number of properties = " + - NUM_MYPROPS + sysProps.size() + + NUM_MYPROPS + sysPropsCount + " but found = " + props.size()); } } diff --git a/test/java/lang/reflect/DefaultAccessibility.java b/test/java/lang/reflect/DefaultAccessibility.java new file mode 100644 index 0000000000000000000000000000000000000000..0f74d044ef68594e3f9c3baeeadc38aa0ff340b4 --- /dev/null +++ b/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); + } +} diff --git a/test/java/nio/file/attribute/AclFileAttributeView/Basic.java b/test/java/nio/file/attribute/AclFileAttributeView/Basic.java index 14563202bd825727593ab9f48cfac306225227dd..3b8a8bc2f82275ff4381b6a2e590afa8f13e3e5a 100644 --- a/test/java/nio/file/attribute/AclFileAttributeView/Basic.java +++ b/test/java/nio/file/attribute/AclFileAttributeView/Basic.java @@ -22,7 +22,7 @@ */ /* @test - * @bug 4313887 6838333 + * @bug 4313887 6838333 6891404 * @summary Unit test for java.nio.file.attribute.AclFileAttribueView * @library ../.. */ diff --git a/test/java/util/Objects/BasicObjectsTest.java b/test/java/util/Objects/BasicObjectsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..be45b2c92edbc47fe784b4752f735d2d057fef35 --- /dev/null +++ b/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; + } +}