提交 4a65aa9b 编写于 作者: L lana

Merge

...@@ -571,6 +571,16 @@ $(NOT_RT_JAR_LIST): FRC ...@@ -571,6 +571,16 @@ $(NOT_RT_JAR_LIST): FRC
$(ECHO) "META-INF/services/com.sun.tools.xjc.Plugin" >> $@ $(ECHO) "META-INF/services/com.sun.tools.xjc.Plugin" >> $@
$(ECHO) "com/sun/tools/" >> $@ $(ECHO) "com/sun/tools/" >> $@
$(ECHO) "sun/jvmstat/" >> $@ $(ECHO) "sun/jvmstat/" >> $@
$(ECHO) "sun/nio/cs/ext/" >> $@
$(ECHO) "sun/awt/HKSCS.class" >> $@
$(ECHO) "sun/awt/motif/X11GB2312$Decoder.class" >> $@
$(ECHO) "sun/awt/motif/X11GB2312$Encoder.class" >> $@
$(ECHO) "sun/awt/motif/X11GB2312.class" >> $@
$(ECHO) "sun/awt/motif/X11GBK$Encoder.class" >> $@
$(ECHO) "sun/awt/motif/X11GBK.class" >> $@
$(ECHO) "sun/awt/motif/X11KSC5601$Decoder.class" >> $@
$(ECHO) "sun/awt/motif/X11KSC5601$Encoder.class" >> $@
$(ECHO) "sun/awt/motif/X11KSC5601.class" >> $@
$(ECHO) "sun/rmi/rmic/" >> $@ $(ECHO) "sun/rmi/rmic/" >> $@
$(ECHO) "sun/tools/asm/" >> $@ $(ECHO) "sun/tools/asm/" >> $@
$(ECHO) "sun/tools/java/" >> $@ $(ECHO) "sun/tools/java/" >> $@
......
...@@ -119,6 +119,7 @@ SUNWprivate_1.1 { ...@@ -119,6 +119,7 @@ SUNWprivate_1.1 {
Java_sun_nio_ch_ServerSocketChannelImpl_accept0; Java_sun_nio_ch_ServerSocketChannelImpl_accept0;
Java_sun_nio_ch_ServerSocketChannelImpl_initIDs; Java_sun_nio_ch_ServerSocketChannelImpl_initIDs;
Java_sun_nio_ch_SocketChannelImpl_checkConnect; Java_sun_nio_ch_SocketChannelImpl_checkConnect;
Java_sun_nio_ch_SocketChannelImpl_sendOutOfBandData;
Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_accept0; Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_accept0;
Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_initIDs; Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_initIDs;
Java_sun_nio_ch_UnixAsynchronousSocketChannelImpl_checkConnect; Java_sun_nio_ch_UnixAsynchronousSocketChannelImpl_checkConnect;
......
...@@ -106,6 +106,7 @@ SUNWprivate_1.1 { ...@@ -106,6 +106,7 @@ SUNWprivate_1.1 {
Java_sun_nio_ch_ServerSocketChannelImpl_accept0; Java_sun_nio_ch_ServerSocketChannelImpl_accept0;
Java_sun_nio_ch_ServerSocketChannelImpl_initIDs; Java_sun_nio_ch_ServerSocketChannelImpl_initIDs;
Java_sun_nio_ch_SocketChannelImpl_checkConnect; Java_sun_nio_ch_SocketChannelImpl_checkConnect;
Java_sun_nio_ch_SocketChannelImpl_sendOutOfBandData;
Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_accept0; Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_accept0;
Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_initIDs; Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_initIDs;
Java_sun_nio_ch_UnixAsynchronousSocketChannelImpl_checkConnect; Java_sun_nio_ch_UnixAsynchronousSocketChannelImpl_checkConnect;
......
...@@ -57,6 +57,25 @@ CHARSETS_JAR = $(LIBDIR)/charsets.jar ...@@ -57,6 +57,25 @@ CHARSETS_JAR = $(LIBDIR)/charsets.jar
# extcs # extcs
FILES_genout_extcs = $(FILES_gen_extcs:%.java=$(GENSRCDIR)/%.java) FILES_genout_extcs = $(FILES_gen_extcs:%.java=$(GENSRCDIR)/%.java)
#
# These sun.awt charsets use sun/nio/cs/ext charsets that only exist
# in JDK7 charsets.jar, which causes problem when build the symbol
# table for rt.jar in Release.gmk. They are now removed from the
# rt.jar when building jdk/jre image (in Release.gmk), so add them
# into charsets.jar here
#
ifeq ($(PLATFORM), windows)
FILES_src += \
sun/awt/HKSCS.java
else
# Solaris/Linux
FILES_src += \
sun/awt/HKSCS.java \
sun/awt/motif/X11GB2312.java \
sun/awt/motif/X11GBK.java \
sun/awt/motif/X11KSC5601.java
endif # PLATFORM
# #
# Rules # Rules
# #
......
/* /*
* Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -132,7 +132,7 @@ public class DnsContextFactory implements InitialContextFactory { ...@@ -132,7 +132,7 @@ public class DnsContextFactory implements InitialContextFactory {
throw new ConfigurationException("DNS pseudo-URL required"); throw new ConfigurationException("DNS pseudo-URL required");
} }
List servers = new ArrayList(); List<String> servers = new ArrayList<>();
for (int i = 0; i < urls.length; i++) { for (int i = 0; i < urls.length; i++) {
String server = urls[i].getHost(); String server = urls[i].getHost();
...@@ -142,7 +142,7 @@ public class DnsContextFactory implements InitialContextFactory { ...@@ -142,7 +142,7 @@ public class DnsContextFactory implements InitialContextFactory {
// No server or port given, so look to underlying platform. // No server or port given, so look to underlying platform.
// ResolverConfiguration does some limited caching, so the // ResolverConfiguration does some limited caching, so the
// following is reasonably efficient even if called rapid-fire. // following is reasonably efficient even if called rapid-fire.
List platformServers = List<String> platformServers =
ResolverConfiguration.open().nameservers(); ResolverConfiguration.open().nameservers();
if (!platformServers.isEmpty()) { if (!platformServers.isEmpty()) {
servers.addAll(platformServers); servers.addAll(platformServers);
...@@ -157,8 +157,7 @@ public class DnsContextFactory implements InitialContextFactory { ...@@ -157,8 +157,7 @@ public class DnsContextFactory implements InitialContextFactory {
? server ? server
: server + ":" + port); : server + ":" + port);
} }
return (String[]) servers.toArray( return servers.toArray(new String[servers.size()]);
new String[servers.size()]);
} }
/* /*
......
/* /*
* Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -658,6 +658,11 @@ public final class Connection implements Runnable { ...@@ -658,6 +658,11 @@ public final class Connection implements Runnable {
} }
} }
if (nparent) { if (nparent) {
LdapRequest ldr = pendingRequests;
while (ldr != null) {
ldr.notify();
ldr = ldr.next;
}
parent.processConnectionClosure(); parent.processConnectionClosure();
} }
} }
......
...@@ -803,8 +803,7 @@ final class Filter { ...@@ -803,8 +803,7 @@ final class Filter {
// //
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// private static final boolean dbg = false; private static final boolean dbg = false;
private static final boolean dbg = true;
private static int dbgIndent = 0; private static int dbgIndent = 0;
private static void dprint(String msg) { private static void dprint(String msg) {
......
...@@ -81,7 +81,7 @@ public class RegistryContext implements Context, Referenceable { ...@@ -81,7 +81,7 @@ public class RegistryContext implements Context, Referenceable {
} }
RMIClientSocketFactory socketFactory = RMIClientSocketFactory socketFactory =
(RMIClientSocketFactory) env.get(SOCKET_FACTORY); (RMIClientSocketFactory) environment.get(SOCKET_FACTORY);
registry = getRegistry(host, port, socketFactory); registry = getRegistry(host, port, socketFactory);
this.host = host; this.host = host;
this.port = port; this.port = port;
......
...@@ -41,6 +41,13 @@ public interface AutoCloseable { ...@@ -41,6 +41,13 @@ public interface AutoCloseable {
* be declared to throw more specific exceptions (or no exception * be declared to throw more specific exceptions (or no exception
* at all, if the close cannot fail). * at all, if the close cannot fail).
* *
* <p>Note that unlike the {@link java.io.Closeable#close close}
* method of {@link java.io.Closeable}, this {@code close} method
* is <em>not</em> required to be idempotent. In other words,
* calling this {@code close} method more than once may have some
* visible side effect, unlike {@code Closeable.close} which is
* required to have no effect if called more than once.
*
* @throws Exception if this resource cannot be closed * @throws Exception if this resource cannot be closed
*/ */
void close() throws Exception; void close() throws Exception;
......
...@@ -28,12 +28,12 @@ import java.io.*; ...@@ -28,12 +28,12 @@ import java.io.*;
import java.util.*; import java.util.*;
/** /**
* The <code>Throwable</code> class is the superclass of all errors and * The {@code Throwable} class is the superclass of all errors and
* exceptions in the Java language. Only objects that are instances of this * exceptions in the Java language. Only objects that are instances of this
* class (or one of its subclasses) are thrown by the Java Virtual Machine or * class (or one of its subclasses) are thrown by the Java Virtual Machine or
* can be thrown by the Java <code>throw</code> statement. Similarly, only * can be thrown by the Java {@code throw} statement. Similarly, only
* this class or one of its subclasses can be the argument type in a * this class or one of its subclasses can be the argument type in a
* <code>catch</code> clause. * {@code catch} clause.
* *
* For the purposes of compile-time checking of exceptions, {@code * For the purposes of compile-time checking of exceptions, {@code
* Throwable} and any subclass of {@code Throwable} that is not also a * Throwable} and any subclass of {@code Throwable} that is not also a
...@@ -73,11 +73,11 @@ import java.util.*; ...@@ -73,11 +73,11 @@ import java.util.*;
* permit the method to throw the cause directly. For example, suppose * permit the method to throw the cause directly. For example, suppose
* a persistent collection conforms to the {@link java.util.Collection * a persistent collection conforms to the {@link java.util.Collection
* Collection} interface, and that its persistence is implemented atop * Collection} interface, and that its persistence is implemented atop
* <tt>java.io</tt>. Suppose the internals of the <tt>add</tt> method * {@code java.io}. Suppose the internals of the {@code add} method
* can throw an {@link java.io.IOException IOException}. The implementation * can throw an {@link java.io.IOException IOException}. The implementation
* can communicate the details of the <tt>IOException</tt> to its caller * can communicate the details of the {@code IOException} to its caller
* while conforming to the <tt>Collection</tt> interface by wrapping the * while conforming to the {@code Collection} interface by wrapping the
* <tt>IOException</tt> in an appropriate unchecked exception. (The * {@code IOException} in an appropriate unchecked exception. (The
* specification for the persistent collection should indicate that it is * specification for the persistent collection should indicate that it is
* capable of throwing such exceptions.) * capable of throwing such exceptions.)
* *
...@@ -86,7 +86,7 @@ import java.util.*; ...@@ -86,7 +86,7 @@ import java.util.*;
* {@link #initCause(Throwable)} method. New throwable classes that * {@link #initCause(Throwable)} method. New throwable classes that
* wish to allow causes to be associated with them should provide constructors * wish to allow causes to be associated with them should provide constructors
* that take a cause and delegate (perhaps indirectly) to one of the * that take a cause and delegate (perhaps indirectly) to one of the
* <tt>Throwable</tt> constructors that takes a cause. For example: * {@code Throwable} constructors that takes a cause. For example:
* <pre> * <pre>
* try { * try {
* lowLevelOp(); * lowLevelOp();
...@@ -94,10 +94,10 @@ import java.util.*; ...@@ -94,10 +94,10 @@ import java.util.*;
* throw new HighLevelException(le); // Chaining-aware constructor * throw new HighLevelException(le); // Chaining-aware constructor
* } * }
* </pre> * </pre>
* Because the <tt>initCause</tt> method is public, it allows a cause to be * Because the {@code initCause} method is public, it allows a cause to be
* associated with any throwable, even a "legacy throwable" whose * associated with any throwable, even a "legacy throwable" whose
* implementation predates the addition of the exception chaining mechanism to * implementation predates the addition of the exception chaining mechanism to
* <tt>Throwable</tt>. For example: * {@code Throwable}. For example:
* <pre> * <pre>
* try { * try {
* lowLevelOp(); * lowLevelOp();
...@@ -121,28 +121,28 @@ import java.util.*; ...@@ -121,28 +121,28 @@ import java.util.*;
* use the standard exception chaining mechanism, while continuing to * use the standard exception chaining mechanism, while continuing to
* implement their "legacy" chaining mechanisms for compatibility. * implement their "legacy" chaining mechanisms for compatibility.
* *
* <p>Further, as of release 1.4, many general purpose <tt>Throwable</tt> * <p>Further, as of release 1.4, many general purpose {@code Throwable}
* classes (for example {@link Exception}, {@link RuntimeException}, * classes (for example {@link Exception}, {@link RuntimeException},
* {@link Error}) have been retrofitted with constructors that take * {@link Error}) have been retrofitted with constructors that take
* a cause. This was not strictly necessary, due to the existence of the * a cause. This was not strictly necessary, due to the existence of the
* <tt>initCause</tt> method, but it is more convenient and expressive to * {@code initCause} method, but it is more convenient and expressive to
* delegate to a constructor that takes a cause. * delegate to a constructor that takes a cause.
* *
* <p>By convention, class <code>Throwable</code> and its subclasses have two * <p>By convention, class {@code Throwable} and its subclasses have two
* constructors, one that takes no arguments and one that takes a * constructors, one that takes no arguments and one that takes a
* <code>String</code> argument that can be used to produce a detail message. * {@code String} argument that can be used to produce a detail message.
* Further, those subclasses that might likely have a cause associated with * Further, those subclasses that might likely have a cause associated with
* them should have two more constructors, one that takes a * them should have two more constructors, one that takes a
* <code>Throwable</code> (the cause), and one that takes a * {@code Throwable} (the cause), and one that takes a
* <code>String</code> (the detail message) and a <code>Throwable</code> (the * {@code String} (the detail message) and a {@code Throwable} (the
* cause). * cause).
* *
* <p>Also introduced in release 1.4 is the {@link #getStackTrace()} method, * <p>Also introduced in release 1.4 is the {@link #getStackTrace()} method,
* which allows programmatic access to the stack trace information that was * which allows programmatic access to the stack trace information that was
* previously available only in text form, via the various forms of the * previously available only in text form, via the various forms of the
* {@link #printStackTrace()} method. This information has been added to the * {@link #printStackTrace()} method. This information has been added to the
* <i>serialized representation</i> of this class so <tt>getStackTrace</tt> * <i>serialized representation</i> of this class so {@code getStackTrace}
* and <tt>printStackTrace</tt> will operate properly on a throwable that * and {@code printStackTrace} will operate properly on a throwable that
* was obtained by deserialization. * was obtained by deserialization.
* *
* @author unascribed * @author unascribed
...@@ -162,7 +162,7 @@ public class Throwable implements Serializable { ...@@ -162,7 +162,7 @@ public class Throwable implements Serializable {
/** /**
* Specific details about the Throwable. For example, for * Specific details about the Throwable. For example, for
* <tt>FileNotFoundException</tt>, this contains the name of * {@code FileNotFoundException}, this contains the name of
* the file that could not be found. * the file that could not be found.
* *
* @serial * @serial
...@@ -212,7 +212,7 @@ public class Throwable implements Serializable { ...@@ -212,7 +212,7 @@ public class Throwable implements Serializable {
private static final String SUPPRESSED_CAPTION = "Suppressed: "; private static final String SUPPRESSED_CAPTION = "Suppressed: ";
/** /**
* Constructs a new throwable with <code>null</code> as its detail message. * Constructs a new throwable with {@code null} as its detail message.
* The cause is not initialized, and may subsequently be initialized by a * The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}. * call to {@link #initCause}.
* *
...@@ -242,7 +242,7 @@ public class Throwable implements Serializable { ...@@ -242,7 +242,7 @@ public class Throwable implements Serializable {
/** /**
* Constructs a new throwable with the specified detail message and * Constructs a new throwable with the specified detail message and
* cause. <p>Note that the detail message associated with * cause. <p>Note that the detail message associated with
* <code>cause</code> is <i>not</i> automatically incorporated in * {@code cause} is <i>not</i> automatically incorporated in
* this throwable's detail message. * this throwable's detail message.
* *
* <p>The {@link #fillInStackTrace()} method is called to initialize * <p>The {@link #fillInStackTrace()} method is called to initialize
...@@ -251,7 +251,7 @@ public class Throwable implements Serializable { ...@@ -251,7 +251,7 @@ public class Throwable implements Serializable {
* @param message the detail message (which is saved for later retrieval * @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method). * by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the * @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is * {@link #getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or * permitted, and indicates that the cause is nonexistent or
* unknown.) * unknown.)
* @since 1.4 * @since 1.4
...@@ -264,8 +264,8 @@ public class Throwable implements Serializable { ...@@ -264,8 +264,8 @@ public class Throwable implements Serializable {
/** /**
* Constructs a new throwable with the specified cause and a detail * Constructs a new throwable with the specified cause and a detail
* message of <tt>(cause==null ? null : cause.toString())</tt> (which * message of {@code (cause==null ? null : cause.toString())} (which
* typically contains the class and detail message of <tt>cause</tt>). * typically contains the class and detail message of {@code cause}).
* This constructor is useful for throwables that are little more than * This constructor is useful for throwables that are little more than
* wrappers for other throwables (for example, {@link * wrappers for other throwables (for example, {@link
* java.security.PrivilegedActionException}). * java.security.PrivilegedActionException}).
...@@ -274,7 +274,7 @@ public class Throwable implements Serializable { ...@@ -274,7 +274,7 @@ public class Throwable implements Serializable {
* the stack trace data in the newly created throwable. * the stack trace data in the newly created throwable.
* *
* @param cause the cause (which is saved for later retrieval by the * @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is * {@link #getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or * permitted, and indicates that the cause is nonexistent or
* unknown.) * unknown.)
* @since 1.4 * @since 1.4
...@@ -288,8 +288,8 @@ public class Throwable implements Serializable { ...@@ -288,8 +288,8 @@ public class Throwable implements Serializable {
/** /**
* Returns the detail message string of this throwable. * Returns the detail message string of this throwable.
* *
* @return the detail message string of this <tt>Throwable</tt> instance * @return the detail message string of this {@code Throwable} instance
* (which may be <tt>null</tt>). * (which may be {@code null}).
*/ */
public String getMessage() { public String getMessage() {
return detailMessage; return detailMessage;
...@@ -300,7 +300,7 @@ public class Throwable implements Serializable { ...@@ -300,7 +300,7 @@ public class Throwable implements Serializable {
* Subclasses may override this method in order to produce a * Subclasses may override this method in order to produce a
* locale-specific message. For subclasses that do not override this * locale-specific message. For subclasses that do not override this
* method, the default implementation returns the same result as * method, the default implementation returns the same result as
* <code>getMessage()</code>. * {@code getMessage()}.
* *
* @return The localized description of this throwable. * @return The localized description of this throwable.
* @since JDK1.1 * @since JDK1.1
...@@ -310,22 +310,22 @@ public class Throwable implements Serializable { ...@@ -310,22 +310,22 @@ public class Throwable implements Serializable {
} }
/** /**
* Returns the cause of this throwable or <code>null</code> if the * Returns the cause of this throwable or {@code null} if the
* cause is nonexistent or unknown. (The cause is the throwable that * cause is nonexistent or unknown. (The cause is the throwable that
* caused this throwable to get thrown.) * caused this throwable to get thrown.)
* *
* <p>This implementation returns the cause that was supplied via one of * <p>This implementation returns the cause that was supplied via one of
* the constructors requiring a <tt>Throwable</tt>, or that was set after * the constructors requiring a {@code Throwable}, or that was set after
* creation with the {@link #initCause(Throwable)} method. While it is * creation with the {@link #initCause(Throwable)} method. While it is
* typically unnecessary to override this method, a subclass can override * typically unnecessary to override this method, a subclass can override
* it to return a cause set by some other means. This is appropriate for * it to return a cause set by some other means. This is appropriate for
* a "legacy chained throwable" that predates the addition of chained * a "legacy chained throwable" that predates the addition of chained
* exceptions to <tt>Throwable</tt>. Note that it is <i>not</i> * exceptions to {@code Throwable}. Note that it is <i>not</i>
* necessary to override any of the <tt>PrintStackTrace</tt> methods, * necessary to override any of the {@code PrintStackTrace} methods,
* all of which invoke the <tt>getCause</tt> method to determine the * all of which invoke the {@code getCause} method to determine the
* cause of a throwable. * cause of a throwable.
* *
* @return the cause of this throwable or <code>null</code> if the * @return the cause of this throwable or {@code null} if the
* cause is nonexistent or unknown. * cause is nonexistent or unknown.
* @since 1.4 * @since 1.4
*/ */
...@@ -345,11 +345,11 @@ public class Throwable implements Serializable { ...@@ -345,11 +345,11 @@ public class Throwable implements Serializable {
* even once. * even once.
* *
* @param cause the cause (which is saved for later retrieval by the * @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is * {@link #getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or * permitted, and indicates that the cause is nonexistent or
* unknown.) * unknown.)
* @return a reference to this <code>Throwable</code> instance. * @return a reference to this {@code Throwable} instance.
* @throws IllegalArgumentException if <code>cause</code> is this * @throws IllegalArgumentException if {@code cause} is this
* throwable. (A throwable cannot be its own cause.) * throwable. (A throwable cannot be its own cause.)
* @throws IllegalStateException if this throwable was * @throws IllegalStateException if this throwable was
* created with {@link #Throwable(Throwable)} or * created with {@link #Throwable(Throwable)} or
...@@ -375,7 +375,7 @@ public class Throwable implements Serializable { ...@@ -375,7 +375,7 @@ public class Throwable implements Serializable {
* <li> the result of invoking this object's {@link #getLocalizedMessage} * <li> the result of invoking this object's {@link #getLocalizedMessage}
* method * method
* </ul> * </ul>
* If <tt>getLocalizedMessage</tt> returns <tt>null</tt>, then just * If {@code getLocalizedMessage} returns {@code null}, then just
* the class name is returned. * the class name is returned.
* *
* @return a string representation of this throwable. * @return a string representation of this throwable.
...@@ -389,8 +389,8 @@ public class Throwable implements Serializable { ...@@ -389,8 +389,8 @@ public class Throwable implements Serializable {
/** /**
* Prints this throwable and its backtrace to the * Prints this throwable and its backtrace to the
* standard error stream. This method prints a stack trace for this * standard error stream. This method prints a stack trace for this
* <code>Throwable</code> object on the error output stream that is * {@code Throwable} object on the error output stream that is
* the value of the field <code>System.err</code>. The first line of * the value of the field {@code System.err}. The first line of
* output contains the result of the {@link #toString()} method for * output contains the result of the {@link #toString()} method for
* this object. Remaining lines represent data previously recorded by * this object. Remaining lines represent data previously recorded by
* the method {@link #fillInStackTrace()}. The format of this * the method {@link #fillInStackTrace()}. The format of this
...@@ -435,7 +435,7 @@ public class Throwable implements Serializable { ...@@ -435,7 +435,7 @@ public class Throwable implements Serializable {
* at Junk.c(Junk.java:21) * at Junk.c(Junk.java:21)
* ... 3 more * ... 3 more
* </pre> * </pre>
* Note the presence of lines containing the characters <tt>"..."</tt>. * Note the presence of lines containing the characters {@code "..."}.
* These lines indicate that the remainder of the stack trace for this * These lines indicate that the remainder of the stack trace for this
* exception matches the indicated number of frames from the bottom of the * exception matches the indicated number of frames from the bottom of the
* stack trace of the exception that was caused by this exception (the * stack trace of the exception that was caused by this exception (the
...@@ -542,14 +542,17 @@ public class Throwable implements Serializable { ...@@ -542,14 +542,17 @@ public class Throwable implements Serializable {
/** /**
* Prints this throwable and its backtrace to the specified print stream. * Prints this throwable and its backtrace to the specified print stream.
* *
* @param s <code>PrintStream</code> to use for output * @param s {@code PrintStream} to use for output
*/ */
public void printStackTrace(PrintStream s) { public void printStackTrace(PrintStream s) {
printStackTrace(new WrappedPrintStream(s)); printStackTrace(new WrappedPrintStream(s));
} }
private void printStackTrace(PrintStreamOrWriter s) { private void printStackTrace(PrintStreamOrWriter s) {
Set<Throwable> dejaVu = new HashSet<Throwable>(); // Guard against malicious overrides of Throwable.equals by
// using a Set with identity equality semantics.
Set<Throwable> dejaVu =
Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
dejaVu.add(this); dejaVu.add(this);
synchronized (s.lock()) { synchronized (s.lock()) {
...@@ -616,7 +619,7 @@ public class Throwable implements Serializable { ...@@ -616,7 +619,7 @@ public class Throwable implements Serializable {
* Prints this throwable and its backtrace to the specified * Prints this throwable and its backtrace to the specified
* print writer. * print writer.
* *
* @param s <code>PrintWriter</code> to use for output * @param s {@code PrintWriter} to use for output
* @since JDK1.1 * @since JDK1.1
*/ */
public void printStackTrace(PrintWriter s) { public void printStackTrace(PrintWriter s) {
...@@ -669,10 +672,10 @@ public class Throwable implements Serializable { ...@@ -669,10 +672,10 @@ public class Throwable implements Serializable {
/** /**
* Fills in the execution stack trace. This method records within this * Fills in the execution stack trace. This method records within this
* <code>Throwable</code> object information about the current state of * {@code Throwable} object information about the current state of
* the stack frames for the current thread. * the stack frames for the current thread.
* *
* @return a reference to this <code>Throwable</code> instance. * @return a reference to this {@code Throwable} instance.
* @see java.lang.Throwable#printStackTrace() * @see java.lang.Throwable#printStackTrace()
*/ */
public synchronized native Throwable fillInStackTrace(); public synchronized native Throwable fillInStackTrace();
...@@ -694,7 +697,7 @@ public class Throwable implements Serializable { ...@@ -694,7 +697,7 @@ public class Throwable implements Serializable {
* this throwable is permitted to return a zero-length array from this * this throwable is permitted to return a zero-length array from this
* method. Generally speaking, the array returned by this method will * method. Generally speaking, the array returned by this method will
* contain one element for every frame that would be printed by * contain one element for every frame that would be printed by
* <tt>printStackTrace</tt>. * {@code printStackTrace}.
* *
* @return an array of stack trace elements representing the stack trace * @return an array of stack trace elements representing the stack trace
* pertaining to this throwable. * pertaining to this throwable.
...@@ -727,14 +730,14 @@ public class Throwable implements Serializable { ...@@ -727,14 +730,14 @@ public class Throwable implements Serializable {
* read from a serialization stream. * read from a serialization stream.
* *
* @param stackTrace the stack trace elements to be associated with * @param stackTrace the stack trace elements to be associated with
* this <code>Throwable</code>. The specified array is copied by this * this {@code Throwable}. The specified array is copied by this
* call; changes in the specified array after the method invocation * call; changes in the specified array after the method invocation
* returns will have no affect on this <code>Throwable</code>'s stack * returns will have no affect on this {@code Throwable}'s stack
* trace. * trace.
* *
* @throws NullPointerException if <code>stackTrace</code> is * @throws NullPointerException if {@code stackTrace} is
* <code>null</code>, or if any of the elements of * {@code null}, or if any of the elements of
* <code>stackTrace</code> are <code>null</code> * {@code stackTrace} are {@code null}
* *
* @since 1.4 * @since 1.4
*/ */
...@@ -761,8 +764,8 @@ public class Throwable implements Serializable { ...@@ -761,8 +764,8 @@ public class Throwable implements Serializable {
* package-protection for use by SharedSecrets. * package-protection for use by SharedSecrets.
* *
* @param index index of the element to return. * @param index index of the element to return.
* @throws IndexOutOfBoundsException if <tt>index &lt; 0 || * @throws IndexOutOfBoundsException if {@code index < 0 ||
* index &gt;= getStackTraceDepth() </tt> * index >= getStackTraceDepth() }
*/ */
native StackTraceElement getStackTraceElement(int index); native StackTraceElement getStackTraceElement(int index);
...@@ -794,14 +797,27 @@ public class Throwable implements Serializable { ...@@ -794,14 +797,27 @@ public class Throwable implements Serializable {
* were suppressed, typically by the automatic resource management * were suppressed, typically by the automatic resource management
* statement, in order to deliver this exception. * statement, in order to deliver this exception.
* *
* <p>Note that when one exception {@linkplain
* #initCause(Throwable) causes} another exception, the first
* exception is usually caught and then the second exception is
* thrown in response. In contrast, when one exception suppresses
* another, two exceptions are thrown in sibling code blocks, such
* as in a {@code try} block and in its {@code finally} block, and
* control flow can only continue with one exception so the second
* is recorded as a suppressed exception of the first.
*
* @param exception the exception to be added to the list of * @param exception the exception to be added to the list of
* suppressed exceptions * suppressed exceptions
* @throws NullPointerException if {@code exception} is null * @throws NullPointerException if {@code exception} is null
* @throws IllegalArgumentException if {@code exception} is this
* throwable; a throwable cannot suppress itself.
* @since 1.7 * @since 1.7
*/ */
public synchronized void addSuppressedException(Throwable exception) { public synchronized void addSuppressedException(Throwable exception) {
if (exception == null) if (exception == null)
throw new NullPointerException(NULL_CAUSE_MESSAGE); throw new NullPointerException(NULL_CAUSE_MESSAGE);
if (exception == this)
throw new IllegalArgumentException("Self-suppression not permitted");
if (suppressedExceptions.size() == 0) if (suppressedExceptions.size() == 0)
suppressedExceptions = new ArrayList<Throwable>(); suppressedExceptions = new ArrayList<Throwable>();
......
...@@ -596,6 +596,9 @@ class Bits { // package-private ...@@ -596,6 +596,9 @@ class Bits { // package-private
return pageSize; return pageSize;
} }
static int pageCount(long size) {
return (int)(size + (long)pageSize() - 1L) / pageSize();
}
private static boolean unaligned; private static boolean unaligned;
private static boolean unalignedKnown = false; private static boolean unalignedKnown = false;
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
package java.nio; package java.nio;
import sun.misc.Unsafe;
/** /**
* A direct byte buffer whose content is a memory-mapped region of a file. * A direct byte buffer whose content is a memory-mapped region of a file.
...@@ -93,6 +95,22 @@ public abstract class MappedByteBuffer ...@@ -93,6 +95,22 @@ public abstract class MappedByteBuffer
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Returns the distance (in bytes) of the buffer from the page aligned address
// of the mapping. Computed each time to avoid storing in every direct buffer.
private long mappingOffset() {
int ps = Bits.pageSize();
long offset = address % ps;
return (offset >= 0) ? offset : (ps + offset);
}
private long mappingAddress(long mappingOffset) {
return address - mappingOffset;
}
private long mappingLength(long mappingOffset) {
return (long)capacity() + mappingOffset;
}
/** /**
* Tells whether or not this buffer's content is resident in physical * Tells whether or not this buffer's content is resident in physical
* memory. * memory.
...@@ -115,7 +133,9 @@ public abstract class MappedByteBuffer ...@@ -115,7 +133,9 @@ public abstract class MappedByteBuffer
checkMapped(); checkMapped();
if ((address == 0) || (capacity() == 0)) if ((address == 0) || (capacity() == 0))
return true; return true;
return isLoaded0(((DirectByteBuffer)this).address(), capacity()); long offset = mappingOffset();
long length = mappingLength(offset);
return isLoaded0(mappingAddress(offset), length, Bits.pageCount(length));
} }
/** /**
...@@ -132,7 +152,20 @@ public abstract class MappedByteBuffer ...@@ -132,7 +152,20 @@ public abstract class MappedByteBuffer
checkMapped(); checkMapped();
if ((address == 0) || (capacity() == 0)) if ((address == 0) || (capacity() == 0))
return this; return this;
load0(((DirectByteBuffer)this).address(), capacity(), Bits.pageSize()); long offset = mappingOffset();
long length = mappingLength(offset);
load0(mappingAddress(offset), length);
// touch each page
Unsafe unsafe = Unsafe.getUnsafe();
int ps = Bits.pageSize();
int count = Bits.pageCount(length);
long a = mappingAddress(offset);
for (int i=0; i<count; i++) {
unsafe.getByte(a);
a += ps;
}
return this; return this;
} }
...@@ -156,14 +189,15 @@ public abstract class MappedByteBuffer ...@@ -156,14 +189,15 @@ public abstract class MappedByteBuffer
*/ */
public final MappedByteBuffer force() { public final MappedByteBuffer force() {
checkMapped(); checkMapped();
if ((address == 0) || (capacity() == 0)) if ((address != 0) && (capacity() != 0)) {
return this; long offset = mappingOffset();
force0(((DirectByteBuffer)this).address(), capacity()); force0(mappingAddress(offset), mappingLength(offset));
}
return this; return this;
} }
private native boolean isLoaded0(long address, long length); private native boolean isLoaded0(long address, long length, int pageCount);
private native int load0(long address, long length, int pageSize); private native void load0(long address, long length);
private native void force0(long address, long length); private native void force0(long address, long length);
} }
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -387,7 +387,7 @@ public abstract class X509CRL extends CRL implements X509Extension { ...@@ -387,7 +387,7 @@ public abstract class X509CRL extends CRL implements X509Extension {
/** /**
* Gets the signature algorithm name for the CRL * Gets the signature algorithm name for the CRL
* signature algorithm. An example is the string "SHA-1/DSA". * signature algorithm. An example is the string "SHA256withRSA".
* The ASN.1 definition for this is: * The ASN.1 definition for this is:
* <pre> * <pre>
* signatureAlgorithm AlgorithmIdentifier<p> * signatureAlgorithm AlgorithmIdentifier<p>
......
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -352,7 +352,7 @@ implements X509Extension { ...@@ -352,7 +352,7 @@ implements X509Extension {
/** /**
* Gets the signature algorithm name for the certificate * Gets the signature algorithm name for the certificate
* signature algorithm. An example is the string "SHA-1/DSA". * signature algorithm. An example is the string "SHA256withRSA".
* The ASN.1 definition for this is: * The ASN.1 definition for this is:
* <pre> * <pre>
* signatureAlgorithm AlgorithmIdentifier<p> * signatureAlgorithm AlgorithmIdentifier<p>
......
...@@ -26,18 +26,9 @@ ...@@ -26,18 +26,9 @@
package java.util; package java.util;
/** /**
* Linked list implementation of the {@code List} interface. Implements all * Linked list implementation of the {@link List} and {@link Deque} interfaces.
* optional list operations, and permits all elements (including * Implements all optional operations, and permits all elements (including
* {@code null}). In addition to implementing the {@code List} interface, * {@code null}).
* the {@code LinkedList} class provides uniformly named methods to
* {@code get}, {@code remove} and {@code insert} an element at the
* beginning and end of the list. These operations allow linked lists to be
* used as a stack, {@linkplain Queue queue}, or {@linkplain Deque
* double-ended queue}.
*
* <p>The class implements the {@code Deque} interface, providing
* first-in-first-out queue operations for {@code add},
* {@code poll}, along with other stack and deque operations.
* *
* <p>All of the operations perform as could be expected for a doubly-linked * <p>All of the operations perform as could be expected for a doubly-linked
* list. Operations that index into the list will traverse the list from * list. Operations that index into the list will traverse the list from
......
/* /*
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -113,7 +113,6 @@ public class BasicColorChooserUI extends ColorChooserUI ...@@ -113,7 +113,6 @@ public class BasicColorChooserUI extends ColorChooserUI
previewPanelHolder.setBorder(new TitledBorder(previewString)); previewPanelHolder.setBorder(new TitledBorder(previewString));
} }
previewPanelHolder.setInheritsPopupMenu(true); previewPanelHolder.setInheritsPopupMenu(true);
chooser.add(previewPanelHolder, BorderLayout.SOUTH);
installPreviewPanel(); installPreviewPanel();
chooser.applyComponentOrientation(c.getComponentOrientation()); chooser.applyComponentOrientation(c.getComponentOrientation());
...@@ -126,13 +125,9 @@ public class BasicColorChooserUI extends ColorChooserUI ...@@ -126,13 +125,9 @@ public class BasicColorChooserUI extends ColorChooserUI
uninstallDefaultChoosers(); uninstallDefaultChoosers();
uninstallListeners(); uninstallListeners();
uninstallPreviewPanel();
uninstallDefaults(); uninstallDefaults();
previewPanelHolder.remove(previewPanel);
if (previewPanel instanceof UIResource) {
chooser.setPreviewPanel(null);
}
previewPanelHolder = null; previewPanelHolder = null;
previewPanel = null; previewPanel = null;
defaultChoosers = null; defaultChoosers = null;
...@@ -143,29 +138,37 @@ public class BasicColorChooserUI extends ColorChooserUI ...@@ -143,29 +138,37 @@ public class BasicColorChooserUI extends ColorChooserUI
} }
protected void installPreviewPanel() { protected void installPreviewPanel() {
if (previewPanel != null) { JComponent previewPanel = this.chooser.getPreviewPanel();
previewPanelHolder.remove(previewPanel); if (previewPanel == null) {
previewPanel.removeMouseListener(getHandler()); previewPanel = ColorChooserComponentFactory.getPreviewPanel();
} }
else {
previewPanel = chooser.getPreviewPanel(); Dimension size = new BorderLayout().minimumLayoutSize(previewPanel);
Dimension layoutSize = new Dimension(); // fix for bug 4759306 if ((size.width == 0) && (size.height == 0)) {
if (previewPanel != null) { previewPanel = null;
layoutSize = new BorderLayout().minimumLayoutSize(previewPanel);
if ((previewPanelHolder != null) && (chooser != null) &&
(layoutSize.getWidth() + layoutSize.getHeight() == 0)) {
chooser.remove(previewPanelHolder);
return;
} }
} }
if (previewPanel == null || previewPanel instanceof UIResource) { this.previewPanel = previewPanel;
previewPanel = ColorChooserComponentFactory.getPreviewPanel(); // get from table? if (previewPanel != null) {
chooser.setPreviewPanel(previewPanel); chooser.add(previewPanelHolder, BorderLayout.SOUTH);
previewPanel.setForeground(chooser.getColor());
previewPanelHolder.add(previewPanel);
previewPanel.addMouseListener(getHandler());
previewPanel.setInheritsPopupMenu(true);
} }
previewPanel.setForeground(chooser.getColor()); }
previewPanelHolder.add(previewPanel);
previewPanel.addMouseListener(getHandler()); /**
previewPanel.setInheritsPopupMenu(true); * Removes installed preview panel from the UI delegate.
*
* @since 1.7
*/
protected void uninstallPreviewPanel() {
if (this.previewPanel != null) {
this.previewPanel.removeMouseListener(getHandler());
this.previewPanelHolder.remove(this.previewPanel);
}
this.chooser.remove(this.previewPanelHolder);
} }
protected void installDefaults() { protected void installDefaults() {
...@@ -209,7 +212,6 @@ public class BasicColorChooserUI extends ColorChooserUI ...@@ -209,7 +212,6 @@ public class BasicColorChooserUI extends ColorChooserUI
chooser.removePropertyChangeListener( propertyChangeListener ); chooser.removePropertyChangeListener( propertyChangeListener );
chooser.getSelectionModel().removeChangeListener(previewListener); chooser.getSelectionModel().removeChangeListener(previewListener);
previewListener = null; previewListener = null;
previewPanel.removeMouseListener(getHandler());
} }
private void selectionChanged(ColorSelectionModel model) { private void selectionChanged(ColorSelectionModel model) {
...@@ -312,9 +314,8 @@ public class BasicColorChooserUI extends ColorChooserUI ...@@ -312,9 +314,8 @@ public class BasicColorChooserUI extends ColorChooserUI
} }
} }
else if (prop == JColorChooser.PREVIEW_PANEL_PROPERTY) { else if (prop == JColorChooser.PREVIEW_PANEL_PROPERTY) {
if (evt.getNewValue() != previewPanel) { uninstallPreviewPanel();
installPreviewPanel(); installPreviewPanel();
}
} }
else if (prop == JColorChooser.SELECTION_MODEL_PROPERTY) { else if (prop == JColorChooser.SELECTION_MODEL_PROPERTY) {
ColorSelectionModel oldModel = (ColorSelectionModel) evt.getOldValue(); ColorSelectionModel oldModel = (ColorSelectionModel) evt.getOldValue();
...@@ -352,5 +353,4 @@ public class BasicColorChooserUI extends ColorChooserUI ...@@ -352,5 +353,4 @@ public class BasicColorChooserUI extends ColorChooserUI
super("color"); super("color");
} }
} }
} }
...@@ -202,8 +202,8 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup { ...@@ -202,8 +202,8 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
* Implementation of ComboPopup.show(). * Implementation of ComboPopup.show().
*/ */
public void show() { public void show() {
comboBox.firePopupMenuWillBecomeVisible();
setListSelection(comboBox.getSelectedIndex()); setListSelection(comboBox.getSelectedIndex());
Point location = getPopupLocation(); Point location = getPopupLocation();
show( comboBox, location.x, location.y ); show( comboBox, location.x, location.y );
} }
...@@ -344,7 +344,8 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup { ...@@ -344,7 +344,8 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
protected void firePopupMenuWillBecomeVisible() { protected void firePopupMenuWillBecomeVisible() {
super.firePopupMenuWillBecomeVisible(); super.firePopupMenuWillBecomeVisible();
comboBox.firePopupMenuWillBecomeVisible(); // comboBox.firePopupMenuWillBecomeVisible() is called from BasicComboPopup.show() method
// to let the user change the popup menu from the PopupMenuListener.popupMenuWillBecomeVisible()
} }
protected void firePopupMenuWillBecomeInvisible() { protected void firePopupMenuWillBecomeInvisible() {
......
...@@ -570,7 +570,9 @@ public class DefaultFormatter extends JFormattedTextField.AbstractFormatter ...@@ -570,7 +570,9 @@ public class DefaultFormatter extends JFormattedTextField.AbstractFormatter
direction = -1; direction = -1;
} }
if (getOverwriteMode() && rh.text != null) { if (getOverwriteMode() && rh.text != null &&
getFormattedTextField().getSelectedText() == null)
{
rh.length = Math.min(Math.max(rh.length, rh.text.length()), rh.length = Math.min(Math.max(rh.length, rh.text.length()),
rh.fb.getDocument().getLength() - rh.offset); rh.fb.getDocument().getLength() - rh.offset);
} }
......
...@@ -622,18 +622,8 @@ public class InternationalFormatter extends DefaultFormatter { ...@@ -622,18 +622,8 @@ public class InternationalFormatter extends DefaultFormatter {
/** /**
* Overriden in an attempt to honor the literals. * Overriden in an attempt to honor the literals.
* <p> * <p>If we do not allow invalid values and are in overwrite mode, this
* If we do * {@code rh.length} is corrected as to preserve trailing literals.
* not allow invalid values and are in overwrite mode, this does the
* following for each character in the replacement range:
* <ol>
* <li>If the character is a literal, add it to the string to replace
* with. If there is text to insert and it doesn't match the
* literal, then insert the literal in the the middle of the insert
* text. This allows you to either paste in literals or not and
* get the same behavior.
* <li>If there is no text to insert, replace it with ' '.
* </ol>
* If not in overwrite mode, and there is text to insert it is * If not in overwrite mode, and there is text to insert it is
* inserted at the next non literal index going forward. If there * inserted at the next non literal index going forward. If there
* is only text to remove, it is removed from the next non literal * is only text to remove, it is removed from the next non literal
...@@ -643,61 +633,27 @@ public class InternationalFormatter extends DefaultFormatter { ...@@ -643,61 +633,27 @@ public class InternationalFormatter extends DefaultFormatter {
if (!getAllowsInvalid()) { if (!getAllowsInvalid()) {
String text = rh.text; String text = rh.text;
int tl = (text != null) ? text.length() : 0; int tl = (text != null) ? text.length() : 0;
JTextComponent c = getFormattedTextField();
if (tl == 0 && rh.length == 1 && getFormattedTextField(). if (tl == 0 && rh.length == 1 && c.getSelectionStart() != rh.offset) {
getSelectionStart() != rh.offset) {
// Backspace, adjust to actually delete next non-literal. // Backspace, adjust to actually delete next non-literal.
rh.offset = getNextNonliteralIndex(rh.offset, -1); rh.offset = getNextNonliteralIndex(rh.offset, -1);
} } else if (getOverwriteMode()) {
if (getOverwriteMode()) { int pos = rh.offset;
StringBuffer replace = null; int textPos = pos;
boolean overflown = false;
for (int counter = 0, textIndex = 0,
max = Math.max(tl, rh.length); counter < max; for (int i = 0; i < rh.length; i++) {
counter++) { while (isLiteral(pos)) pos++;
if (isLiteral(rh.offset + counter)) { if (pos >= string.length()) {
if (replace != null) { pos = textPos;
replace.append(getLiteral(rh.offset + overflown = true;
counter)); break;
}
if (textIndex < tl && text.charAt(textIndex) ==
getLiteral(rh.offset + counter)) {
textIndex++;
}
else if (textIndex == 0) {
rh.offset++;
rh.length--;
counter--;
max--;
}
else if (replace == null) {
replace = new StringBuffer(max);
replace.append(text.substring(0, textIndex));
replace.append(getLiteral(rh.offset +
counter));
}
}
else if (textIndex < tl) {
if (replace != null) {
replace.append(text.charAt(textIndex));
}
textIndex++;
}
else {
// Nothing to replace it with, assume ' '
if (replace == null) {
replace = new StringBuffer(max);
if (textIndex > 0) {
replace.append(text.substring(0, textIndex));
}
}
if (replace != null) {
replace.append(' ');
}
} }
textPos = ++pos;
} }
if (replace != null) { if (overflown || c.getSelectedText() == null) {
rh.text = replace.toString(); rh.length = pos - rh.offset;
} }
} }
else if (tl > 0) { else if (tl > 0) {
......
/* /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
package sun.net.dns; package sun.net.dns;
import java.util.List; import java.util.List;
import java.io.IOException;
/** /**
* The configuration of the client resolver. * The configuration of the client resolver.
...@@ -68,7 +67,7 @@ public abstract class ResolverConfiguration { ...@@ -68,7 +67,7 @@ public abstract class ResolverConfiguration {
* *
* @return list of domain names * @return list of domain names
*/ */
public abstract List searchlist(); public abstract List<String> searchlist();
/** /**
* Returns a list of name servers used for host name lookup. * Returns a list of name servers used for host name lookup.
...@@ -78,7 +77,7 @@ public abstract class ResolverConfiguration { ...@@ -78,7 +77,7 @@ public abstract class ResolverConfiguration {
* *
* @return list of the name servers * @return list of the name servers
*/ */
public abstract List nameservers(); public abstract List<String> nameservers();
/** /**
......
/* /*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -45,20 +45,21 @@ import sun.security.action.*; ...@@ -45,20 +45,21 @@ import sun.security.action.*;
public final class DNSNameService implements NameService { public final class DNSNameService implements NameService {
// List of domains specified by property // List of domains specified by property
private LinkedList domainList = null; private LinkedList<String> domainList = null;
// JNDI-DNS URL for name servers specified via property // JNDI-DNS URL for name servers specified via property
private String nameProviderUrl = null; private String nameProviderUrl = null;
// Per-thread soft cache of the last temporary context // Per-thread soft cache of the last temporary context
private static ThreadLocal contextRef = new ThreadLocal(); private static ThreadLocal<SoftReference<ThreadContext>> contextRef =
new ThreadLocal<>();
// Simple class to encapsulate the temporary context // Simple class to encapsulate the temporary context
private static class ThreadContext { private static class ThreadContext {
private DirContext dirCtxt; private DirContext dirCtxt;
private List nsList; private List<String> nsList;
public ThreadContext(DirContext dirCtxt, List nsList) { public ThreadContext(DirContext dirCtxt, List<String> nsList) {
this.dirCtxt = dirCtxt; this.dirCtxt = dirCtxt;
this.nsList = nsList; this.nsList = nsList;
} }
...@@ -67,16 +68,16 @@ public final class DNSNameService implements NameService { ...@@ -67,16 +68,16 @@ public final class DNSNameService implements NameService {
return dirCtxt; return dirCtxt;
} }
public List nameservers() { public List<String> nameservers() {
return nsList; return nsList;
} }
} }
// Returns a per-thread DirContext // Returns a per-thread DirContext
private DirContext getTemporaryContext() throws NamingException { private DirContext getTemporaryContext() throws NamingException {
SoftReference ref = (SoftReference)contextRef.get(); SoftReference<ThreadContext> ref = contextRef.get();
ThreadContext thrCtxt = null; ThreadContext thrCtxt = null;
List nsList = null; List<String> nsList = null;
// if no property specified we need to obtain the list of servers // if no property specified we need to obtain the list of servers
// //
...@@ -87,7 +88,7 @@ public final class DNSNameService implements NameService { ...@@ -87,7 +88,7 @@ public final class DNSNameService implements NameService {
// specified then we need to check if the DNS configuration // specified then we need to check if the DNS configuration
// has changed. // has changed.
// //
if ((ref != null) && ((thrCtxt = (ThreadContext)ref.get()) != null)) { if ((ref != null) && ((thrCtxt = ref.get()) != null)) {
if (nameProviderUrl == null) { if (nameProviderUrl == null) {
if (!thrCtxt.nameservers().equals(nsList)) { if (!thrCtxt.nameservers().equals(nsList)) {
// DNS configuration has changed // DNS configuration has changed
...@@ -98,7 +99,7 @@ public final class DNSNameService implements NameService { ...@@ -98,7 +99,7 @@ public final class DNSNameService implements NameService {
// new thread context needs to be created // new thread context needs to be created
if (thrCtxt == null) { if (thrCtxt == null) {
final Hashtable<String,Object> env = new Hashtable<String,Object>(); final Hashtable<String,Object> env = new Hashtable<>();
env.put("java.naming.factory.initial", env.put("java.naming.factory.initial",
"com.sun.jndi.dns.DnsContextFactory"); "com.sun.jndi.dns.DnsContextFactory");
...@@ -119,10 +120,9 @@ public final class DNSNameService implements NameService { ...@@ -119,10 +120,9 @@ public final class DNSNameService implements NameService {
// //
DirContext dirCtxt; DirContext dirCtxt;
try { try {
dirCtxt = (DirContext) dirCtxt = java.security.AccessController.doPrivileged(
java.security.AccessController.doPrivileged( new java.security.PrivilegedExceptionAction<DirContext>() {
new java.security.PrivilegedExceptionAction() { public DirContext run() throws NamingException {
public Object run() throws NamingException {
// Create the DNS context using NamingManager rather than using // Create the DNS context using NamingManager rather than using
// the initial context constructor. This avoids having the initial // the initial context constructor. This avoids having the initial
// context constructor call itself. // context constructor call itself.
...@@ -130,7 +130,7 @@ public final class DNSNameService implements NameService { ...@@ -130,7 +130,7 @@ public final class DNSNameService implements NameService {
if (!(ctx instanceof DirContext)) { if (!(ctx instanceof DirContext)) {
return null; // cannot create a DNS context return null; // cannot create a DNS context
} }
return ctx; return (DirContext)ctx;
} }
}); });
} catch (java.security.PrivilegedActionException pae) { } catch (java.security.PrivilegedActionException pae) {
...@@ -161,18 +161,18 @@ public final class DNSNameService implements NameService { ...@@ -161,18 +161,18 @@ public final class DNSNameService implements NameService {
* *
* @throws UnknownHostException if lookup fails or other error. * @throws UnknownHostException if lookup fails or other error.
*/ */
private ArrayList resolve(final DirContext ctx, final String name, final String[] ids, private ArrayList<String> resolve(final DirContext ctx, final String name,
int depth) throws UnknownHostException final String[] ids, int depth)
throws UnknownHostException
{ {
ArrayList results = new ArrayList(); ArrayList<String> results = new ArrayList<>();
Attributes attrs; Attributes attrs;
// do the query // do the query
try { try {
attrs = (Attributes) attrs = java.security.AccessController.doPrivileged(
java.security.AccessController.doPrivileged( new java.security.PrivilegedExceptionAction<Attributes>() {
new java.security.PrivilegedExceptionAction() { public Attributes run() throws NamingException {
public Object run() throws NamingException {
return ctx.getAttributes(name, ids); return ctx.getAttributes(name, ids);
} }
}); });
...@@ -181,7 +181,7 @@ public final class DNSNameService implements NameService { ...@@ -181,7 +181,7 @@ public final class DNSNameService implements NameService {
} }
// non-requested type returned so enumeration is empty // non-requested type returned so enumeration is empty
NamingEnumeration ne = attrs.getAll(); NamingEnumeration<? extends Attribute> ne = attrs.getAll();
if (!ne.hasMoreElements()) { if (!ne.hasMoreElements()) {
throw new UnknownHostException("DNS record not found"); throw new UnknownHostException("DNS record not found");
} }
...@@ -190,7 +190,7 @@ public final class DNSNameService implements NameService { ...@@ -190,7 +190,7 @@ public final class DNSNameService implements NameService {
UnknownHostException uhe = null; UnknownHostException uhe = null;
try { try {
while (ne.hasMoreElements()) { while (ne.hasMoreElements()) {
Attribute attr = (Attribute)ne.next(); Attribute attr = ne.next();
String attrID = attr.getID(); String attrID = attr.getID();
for (NamingEnumeration e = attr.getAll(); e.hasMoreElements();) { for (NamingEnumeration e = attr.getAll(); e.hasMoreElements();) {
...@@ -251,13 +251,12 @@ public final class DNSNameService implements NameService { ...@@ -251,13 +251,12 @@ public final class DNSNameService implements NameService {
// no property specified so check host DNS resolver configured // no property specified so check host DNS resolver configured
// with at least one nameserver in dotted notation. // with at least one nameserver in dotted notation.
// //
List nsList = ResolverConfiguration.open().nameservers(); List<String> nsList = ResolverConfiguration.open().nameservers();
if (nsList.size() == 0) if (nsList.isEmpty()) {
throw new RuntimeException("no nameservers provided"); throw new RuntimeException("no nameservers provided");
}
boolean found = false; boolean found = false;
Iterator i = nsList.iterator(); for (String addr: nsList) {
while (i.hasNext()) {
String addr = (String)i.next();
if (IPAddressUtil.isIPv4LiteralAddress(addr) || if (IPAddressUtil.isIPv4LiteralAddress(addr) ||
IPAddressUtil.isIPv6LiteralAddress(addr)) { IPAddressUtil.isIPv6LiteralAddress(addr)) {
found = true; found = true;
...@@ -308,8 +307,8 @@ public final class DNSNameService implements NameService { ...@@ -308,8 +307,8 @@ public final class DNSNameService implements NameService {
// suffix if the list has one entry. // suffix if the list has one entry.
if (results == null) { if (results == null) {
List searchList = null; List<String> searchList = null;
Iterator i; Iterator<String> i;
boolean usingSearchList = false; boolean usingSearchList = false;
if (domainList != null) { if (domainList != null) {
...@@ -324,7 +323,7 @@ public final class DNSNameService implements NameService { ...@@ -324,7 +323,7 @@ public final class DNSNameService implements NameService {
// iterator through each domain suffix // iterator through each domain suffix
while (i.hasNext()) { while (i.hasNext()) {
String parentDomain = (String)i.next(); String parentDomain = i.next();
int start = 0; int start = 0;
while ((start = parentDomain.indexOf(".")) != -1 while ((start = parentDomain.indexOf(".")) != -1
&& start < parentDomain.length() -1) { && start < parentDomain.length() -1) {
...@@ -407,7 +406,7 @@ public final class DNSNameService implements NameService { ...@@ -407,7 +406,7 @@ public final class DNSNameService implements NameService {
String literalip = ""; String literalip = "";
String[] ids = { "PTR" }; String[] ids = { "PTR" };
DirContext ctx; DirContext ctx;
ArrayList results = null; ArrayList<String> results = null;
try { try {
ctx = getTemporaryContext(); ctx = getTemporaryContext();
} catch (NamingException nx) { } catch (NamingException nx) {
...@@ -420,7 +419,7 @@ public final class DNSNameService implements NameService { ...@@ -420,7 +419,7 @@ public final class DNSNameService implements NameService {
literalip += "IN-ADDR.ARPA."; literalip += "IN-ADDR.ARPA.";
results = resolve(ctx, literalip, ids, 0); results = resolve(ctx, literalip, ids, 0);
host = (String)results.get(0); host = results.get(0);
} else if (addr.length == 16) { // IPv6 Address } else if (addr.length == 16) { // IPv6 Address
/** /**
* Because RFC 3152 changed the root domain name for reverse * Because RFC 3152 changed the root domain name for reverse
...@@ -437,7 +436,7 @@ public final class DNSNameService implements NameService { ...@@ -437,7 +436,7 @@ public final class DNSNameService implements NameService {
try { try {
results = resolve(ctx, ip6lit, ids, 0); results = resolve(ctx, ip6lit, ids, 0);
host = (String)results.get(0); host = results.get(0);
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
host = null; host = null;
} }
...@@ -445,7 +444,7 @@ public final class DNSNameService implements NameService { ...@@ -445,7 +444,7 @@ public final class DNSNameService implements NameService {
// IP6.ARPA lookup failed, let's try the older IP6.INT // IP6.ARPA lookup failed, let's try the older IP6.INT
ip6lit = literalip + "IP6.INT."; ip6lit = literalip + "IP6.INT.";
results = resolve(ctx, ip6lit, ids, 0); results = resolve(ctx, ip6lit, ids, 0);
host = (String)results.get(0); host = results.get(0);
} }
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -478,11 +477,10 @@ public final class DNSNameService implements NameService { ...@@ -478,11 +477,10 @@ public final class DNSNameService implements NameService {
* @return String containing the JNDI-DNS provider URL * @return String containing the JNDI-DNS provider URL
* corresponding to the supplied List of nameservers. * corresponding to the supplied List of nameservers.
*/ */
private static String createProviderURL(List nsList) { private static String createProviderURL(List<String> nsList) {
Iterator i = nsList.iterator();
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
while (i.hasNext()) { for (String s: nsList) {
appendIfLiteralAddress((String)i.next(), sb); appendIfLiteralAddress(s, sb);
} }
return sb.toString(); return sb.toString();
} }
......
...@@ -336,7 +336,12 @@ public class SocketAdaptor ...@@ -336,7 +336,12 @@ public class SocketAdaptor
} }
public void sendUrgentData(int data) throws IOException { public void sendUrgentData(int data) throws IOException {
throw new SocketException("Urgent data not supported"); synchronized (sc.blockingLock()) {
if (!sc.isBlocking())
throw new IllegalBlockingModeException();
int n = sc.sendOutOfBandData((byte)data);
assert n == 1;
}
} }
public void setOOBInline(boolean on) throws SocketException { public void setOOBInline(boolean on) throws SocketException {
......
...@@ -498,6 +498,36 @@ class SocketChannelImpl ...@@ -498,6 +498,36 @@ class SocketChannelImpl
return write0(Util.subsequence(srcs, offset, length)); return write0(Util.subsequence(srcs, offset, length));
} }
// package-private
int sendOutOfBandData(byte b) throws IOException {
synchronized (writeLock) {
ensureWriteOpen();
int n = 0;
try {
begin();
synchronized (stateLock) {
if (!isOpen())
return 0;
writerThread = NativeThread.current();
}
for (;;) {
n = sendOutOfBandData(fd, b);
if ((n == IOStatus.INTERRUPTED) && isOpen())
continue;
return IOStatus.normalize(n);
}
} finally {
writerCleanup();
end((n > 0) || (n == IOStatus.UNAVAILABLE));
synchronized (stateLock) {
if ((n <= 0) && (!isOutputOpen))
throw new AsynchronousCloseException();
}
assert IOStatus.check(n);
}
}
}
protected void implConfigureBlocking(boolean block) throws IOException { protected void implConfigureBlocking(boolean block) throws IOException {
IOUtil.configureBlocking(fd, block); IOUtil.configureBlocking(fd, block);
} }
...@@ -957,6 +987,9 @@ class SocketChannelImpl ...@@ -957,6 +987,9 @@ class SocketChannelImpl
boolean block, boolean ready) boolean block, boolean ready)
throws IOException; throws IOException;
private static native int sendOutOfBandData(FileDescriptor fd, byte data)
throws IOException;
static { static {
Util.load(); Util.load();
nd = new SocketDispatcher(); nd = new SocketDispatcher();
......
...@@ -42,6 +42,8 @@ import java.util.Enumeration; ...@@ -42,6 +42,8 @@ import java.util.Enumeration;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.List;
import sun.net.dns.ResolverConfiguration;
import sun.security.krb5.internal.crypto.EType; import sun.security.krb5.internal.crypto.EType;
import sun.security.krb5.internal.ktab.*; import sun.security.krb5.internal.ktab.*;
import sun.security.krb5.internal.Krb5; import sun.security.krb5.internal.Krb5;
...@@ -1180,6 +1182,33 @@ public class Config { ...@@ -1180,6 +1182,33 @@ public class Config {
} }
// get the domain realm mapping from the configuration // get the domain realm mapping from the configuration
String mapRealm = PrincipalName.mapHostToRealm(hostName); String mapRealm = PrincipalName.mapHostToRealm(hostName);
if (mapRealm == null) {
// No match. Try search and/or domain in /etc/resolv.conf
List<String> srchlist = ResolverConfiguration.open().searchlist();
for (String domain: srchlist) {
realm = checkRealm(domain);
if (realm != null) {
break;
}
}
} else {
realm = checkRealm(mapRealm);
}
if (realm == null) {
throw new KrbException(Krb5.KRB_ERR_GENERIC,
"Unable to locate Kerberos realm");
}
return realm;
}
/**
* Check if the provided realm is the correct realm
* @return the realm if correct, or null otherwise
*/
private static String checkRealm(String mapRealm) {
if (DEBUG) {
System.out.println("getRealmFromDNS: trying " + mapRealm);
}
String[] records = null; String[] records = null;
String newRealm = mapRealm; String newRealm = mapRealm;
while ((records == null) && (newRealm != null)) { while ((records == null) && (newRealm != null)) {
...@@ -1188,23 +1217,14 @@ public class Config { ...@@ -1188,23 +1217,14 @@ public class Config {
newRealm = Realm.parseRealmComponent(newRealm); newRealm = Realm.parseRealmComponent(newRealm);
// if no DNS TXT records found, try again using sub-realm // if no DNS TXT records found, try again using sub-realm
} }
if (records == null) { if (records != null) {
// no DNS TXT records for (int i = 0; i < records.length; i++) {
throw new KrbException(Krb5.KRB_ERR_GENERIC, if (records[i].equalsIgnoreCase(mapRealm)) {
"Unable to locate Kerberos realm"); return records[i];
} }
boolean found = false;
for (int i = 0; i < records.length; i++) {
if (records[i].equals(mapRealm)) {
found = true;
realm = records[i];
} }
} }
if (found == false) { return null;
throw new KrbException(Krb5.KRB_ERR_GENERIC,
"Unable to locate Kerberos realm");
}
return realm;
} }
/** /**
...@@ -1218,10 +1238,16 @@ public class Config { ...@@ -1218,10 +1238,16 @@ public class Config {
String kdcs = null; String kdcs = null;
String[] srvs = null; String[] srvs = null;
// locate DNS SRV record using UDP // locate DNS SRV record using UDP
srvs = KrbServiceLocator.getKerberosService(realm, "_udp."); if (DEBUG) {
System.out.println("getKDCFromDNS using UDP");
}
srvs = KrbServiceLocator.getKerberosService(realm, "_udp");
if (srvs == null) { if (srvs == null) {
// locate DNS SRV record using TCP // locate DNS SRV record using TCP
srvs = KrbServiceLocator.getKerberosService(realm, "_tcp."); if (DEBUG) {
System.out.println("getKDCFromDNS using UDP");
}
srvs = KrbServiceLocator.getKerberosService(realm, "_tcp");
} }
if (srvs == null) { if (srvs == null) {
// no DNS SRV records // no DNS SRV records
......
...@@ -36,6 +36,7 @@ import sun.security.krb5.internal.ccache.CredentialsCache; ...@@ -36,6 +36,7 @@ import sun.security.krb5.internal.ccache.CredentialsCache;
import sun.security.krb5.internal.crypto.EType; import sun.security.krb5.internal.crypto.EType;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.Locale;
import java.net.InetAddress; import java.net.InetAddress;
/** /**
...@@ -287,7 +288,7 @@ public class Credentials { ...@@ -287,7 +288,7 @@ public class Credentials {
// The default ticket cache on Windows is not a file. // The default ticket cache on Windows is not a file.
String os = java.security.AccessController.doPrivileged( String os = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("os.name")); new sun.security.action.GetPropertyAction("os.name"));
if (os.toUpperCase().startsWith("WINDOWS")) { if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS")) {
Credentials creds = acquireDefaultCreds(); Credentials creds = acquireDefaultCreds();
if (creds == null) { if (creds == null) {
if (DEBUG) { if (DEBUG) {
......
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,6 +28,7 @@ package sun.security.pkcs; ...@@ -28,6 +28,7 @@ package sun.security.pkcs;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.util.Locale;
import java.util.Date; import java.util.Date;
import java.util.Hashtable; import java.util.Hashtable;
import sun.security.x509.CertificateExtensions; import sun.security.x509.CertificateExtensions;
...@@ -742,7 +743,7 @@ public class PKCS9Attribute implements DerEncoder { ...@@ -742,7 +743,7 @@ public class PKCS9Attribute implements DerEncoder {
* the name. * the name.
*/ */
public static ObjectIdentifier getOID(String name) { public static ObjectIdentifier getOID(String name) {
return NAME_OID_TABLE.get(name.toLowerCase()); return NAME_OID_TABLE.get(name.toLowerCase(Locale.ENGLISH));
} }
/** /**
......
...@@ -26,6 +26,7 @@ package sun.security.pkcs11; ...@@ -26,6 +26,7 @@ package sun.security.pkcs11;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale;
import java.security.*; import java.security.*;
import java.security.spec.*; import java.security.spec.*;
...@@ -201,7 +202,7 @@ final class P11Cipher extends CipherSpi { ...@@ -201,7 +202,7 @@ final class P11Cipher extends CipherSpi {
} }
private int parseMode(String mode) throws NoSuchAlgorithmException { private int parseMode(String mode) throws NoSuchAlgorithmException {
mode = mode.toUpperCase(); mode = mode.toUpperCase(Locale.ENGLISH);
int result; int result;
if (mode.equals("ECB")) { if (mode.equals("ECB")) {
result = MODE_ECB; result = MODE_ECB;
...@@ -222,7 +223,7 @@ final class P11Cipher extends CipherSpi { ...@@ -222,7 +223,7 @@ final class P11Cipher extends CipherSpi {
throws NoSuchPaddingException { throws NoSuchPaddingException {
paddingObj = null; paddingObj = null;
padBuffer = null; padBuffer = null;
padding = padding.toUpperCase(); padding = padding.toUpperCase(Locale.ENGLISH);
if (padding.equals("NOPADDING")) { if (padding.equals("NOPADDING")) {
paddingType = PAD_NONE; paddingType = PAD_NONE;
} else if (padding.equals("PKCS5PADDING")) { } else if (padding.equals("PKCS5PADDING")) {
......
...@@ -29,6 +29,8 @@ import java.security.*; ...@@ -29,6 +29,8 @@ import java.security.*;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.*; import java.security.spec.*;
import java.util.Locale;
import javax.crypto.*; import javax.crypto.*;
import javax.crypto.spec.*; import javax.crypto.spec.*;
...@@ -110,7 +112,7 @@ final class P11RSACipher extends CipherSpi { ...@@ -110,7 +112,7 @@ final class P11RSACipher extends CipherSpi {
protected void engineSetPadding(String padding) protected void engineSetPadding(String padding)
throws NoSuchPaddingException { throws NoSuchPaddingException {
String lowerPadding = padding.toLowerCase(); String lowerPadding = padding.toLowerCase(Locale.ENGLISH);
if (lowerPadding.equals("pkcs1Padding")) { if (lowerPadding.equals("pkcs1Padding")) {
// empty // empty
} else { } else {
......
/* /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2010 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -52,6 +52,7 @@ import java.util.ArrayList; ...@@ -52,6 +52,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale;
import sun.security.x509.AccessDescription; import sun.security.x509.AccessDescription;
import sun.security.x509.GeneralNameInterface; import sun.security.x509.GeneralNameInterface;
import sun.security.x509.URIName; import sun.security.x509.URIName;
...@@ -162,7 +163,7 @@ class URICertStore extends CertStoreSpi { ...@@ -162,7 +163,7 @@ class URICertStore extends CertStoreSpi {
} }
this.uri = ((URICertStoreParameters) params).uri; this.uri = ((URICertStoreParameters) params).uri;
// if ldap URI, use an LDAPCertStore to fetch certs and CRLs // if ldap URI, use an LDAPCertStore to fetch certs and CRLs
if (uri.getScheme().toLowerCase().equals("ldap")) { if (uri.getScheme().toLowerCase(Locale.ENGLISH).equals("ldap")) {
if (LDAP.helper() == null) if (LDAP.helper() == null)
throw new NoSuchAlgorithmException("LDAP not present"); throw new NoSuchAlgorithmException("LDAP not present");
ldap = true; ldap = true;
......
/* /*
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,6 +28,7 @@ package sun.security.util; ...@@ -28,6 +28,7 @@ package sun.security.util;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.Locale;
/** /**
* A utility class for debuging. * A utility class for debuging.
...@@ -262,7 +263,7 @@ public class Debug { ...@@ -262,7 +263,7 @@ public class Debug {
source = left; source = left;
// convert the rest to lower-case characters // convert the rest to lower-case characters
target.append(source.toString().toLowerCase()); target.append(source.toString().toLowerCase(Locale.ENGLISH));
return target.toString(); return target.toString();
} }
......
/* /*
* Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,17 +25,16 @@ ...@@ -25,17 +25,16 @@
package sun.security.util; package sun.security.util;
import java.io.FilterOutputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.Vector;
import java.util.Comparator; import java.util.Comparator;
import java.util.Arrays; import java.util.Arrays;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Locale;
/** /**
...@@ -501,7 +500,7 @@ extends ByteArrayOutputStream implements DerEncoder { ...@@ -501,7 +500,7 @@ extends ByteArrayOutputStream implements DerEncoder {
pattern = "yyyyMMddHHmmss'Z'"; pattern = "yyyyMMddHHmmss'Z'";
} }
SimpleDateFormat sdf = new SimpleDateFormat(pattern); SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US);
sdf.setTimeZone(tz); sdf.setTimeZone(tz);
byte[] time = (sdf.format(d)).getBytes("ISO-8859-1"); byte[] time = (sdf.format(d)).getBytes("ISO-8859-1");
......
/* /*
* Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1227,7 +1227,7 @@ class AVAKeyword { ...@@ -1227,7 +1227,7 @@ class AVAKeyword {
(String keyword, int standard, Map<String, String> extraKeywordMap) (String keyword, int standard, Map<String, String> extraKeywordMap)
throws IOException { throws IOException {
keyword = keyword.toUpperCase(); keyword = keyword.toUpperCase(Locale.ENGLISH);
if (standard == AVA.RFC2253) { if (standard == AVA.RFC2253) {
if (keyword.startsWith(" ") || keyword.endsWith(" ")) { if (keyword.startsWith(" ") || keyword.endsWith(" ")) {
throw new IOException("Invalid leading or trailing space " + throw new IOException("Invalid leading or trailing space " +
......
/* /*
* Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -553,9 +553,10 @@ public class AlgorithmId implements Serializable, DerEncoder { ...@@ -553,9 +553,10 @@ public class AlgorithmId implements Serializable, DerEncoder {
for (Enumeration<Object> enum_ = provs[i].keys(); for (Enumeration<Object> enum_ = provs[i].keys();
enum_.hasMoreElements(); ) { enum_.hasMoreElements(); ) {
String alias = (String)enum_.nextElement(); String alias = (String)enum_.nextElement();
String upperCaseAlias = alias.toUpperCase(Locale.ENGLISH);
int index; int index;
if (alias.toUpperCase().startsWith("ALG.ALIAS") && if (upperCaseAlias.startsWith("ALG.ALIAS") &&
(index=alias.toUpperCase().indexOf("OID.", 0)) != -1) { (index=upperCaseAlias.indexOf("OID.", 0)) != -1) {
index += "OID.".length(); index += "OID.".length();
if (index == alias.length()) { if (index == alias.length()) {
// invalid alias entry // invalid alias entry
...@@ -565,19 +566,26 @@ public class AlgorithmId implements Serializable, DerEncoder { ...@@ -565,19 +566,26 @@ public class AlgorithmId implements Serializable, DerEncoder {
oidTable = new HashMap<String,ObjectIdentifier>(); oidTable = new HashMap<String,ObjectIdentifier>();
} }
oidString = alias.substring(index); oidString = alias.substring(index);
String stdAlgName String stdAlgName = provs[i].getProperty(alias);
= provs[i].getProperty(alias).toUpperCase(); if (stdAlgName != null) {
if (oidTable.get(stdAlgName) == null) { stdAlgName = stdAlgName.toUpperCase(Locale.ENGLISH);
}
if (stdAlgName != null &&
oidTable.get(stdAlgName) == null) {
oidTable.put(stdAlgName, oidTable.put(stdAlgName,
new ObjectIdentifier(oidString)); new ObjectIdentifier(oidString));
} }
} }
} }
} }
if (oidTable == null) {
oidTable = new HashMap<String,ObjectIdentifier>(1);
}
initOidTable = true; initOidTable = true;
} }
return oidTable.get(name.toUpperCase()); return oidTable.get(name.toUpperCase(Locale.ENGLISH));
} }
private static ObjectIdentifier oid(int ... values) { private static ObjectIdentifier oid(int ... values) {
......
/* /*
* Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package sun.security.x509; package sun.security.x509;
import java.io.IOException; import java.io.IOException;
import java.util.Locale;
import sun.security.util.*; import sun.security.util.*;
...@@ -198,8 +199,9 @@ public class DNSName implements GeneralNameInterface { ...@@ -198,8 +199,9 @@ public class DNSName implements GeneralNameInterface {
else if (inputName.getType() != NAME_DNS) else if (inputName.getType() != NAME_DNS)
constraintType = NAME_DIFF_TYPE; constraintType = NAME_DIFF_TYPE;
else { else {
String inName = (((DNSName)inputName).getName()).toLowerCase(); String inName =
String thisName = name.toLowerCase(); (((DNSName)inputName).getName()).toLowerCase(Locale.ENGLISH);
String thisName = name.toLowerCase(Locale.ENGLISH);
if (inName.equals(thisName)) if (inName.equals(thisName))
constraintType = NAME_MATCH; constraintType = NAME_MATCH;
else if (thisName.endsWith(inName)) { else if (thisName.endsWith(inName)) {
......
/* /*
* Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package sun.security.x509; package sun.security.x509;
import java.io.IOException; import java.io.IOException;
import java.util.Locale;
import sun.security.util.*; import sun.security.util.*;
...@@ -187,8 +188,9 @@ public class RFC822Name implements GeneralNameInterface ...@@ -187,8 +188,9 @@ public class RFC822Name implements GeneralNameInterface
constraintType = NAME_DIFF_TYPE; constraintType = NAME_DIFF_TYPE;
} else { } else {
//RFC2459 specifies that case is not significant in RFC822Names //RFC2459 specifies that case is not significant in RFC822Names
String inName = (((RFC822Name)inputName).getName()).toLowerCase(); String inName =
String thisName = name.toLowerCase(); (((RFC822Name)inputName).getName()).toLowerCase(Locale.ENGLISH);
String thisName = name.toLowerCase(Locale.ENGLISH);
if (inName.equals(thisName)) { if (inName.equals(thisName)) {
constraintType = NAME_MATCH; constraintType = NAME_MATCH;
} else if (thisName.endsWith(inName)) { } else if (thisName.endsWith(inName)) {
......
/* /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -56,8 +56,11 @@ public class ResolverConfigurationImpl ...@@ -56,8 +56,11 @@ public class ResolverConfigurationImpl
// Parse /etc/resolv.conf to get the values for a particular // Parse /etc/resolv.conf to get the values for a particular
// keyword. // keyword.
// //
private LinkedList resolvconf(String keyword, int maxperkeyword, int maxkeywords) { private LinkedList<String> resolvconf(String keyword,
LinkedList ll = new LinkedList(); int maxperkeyword,
int maxkeywords)
{
LinkedList<String> ll = new LinkedList<>();
try { try {
BufferedReader in = BufferedReader in =
...@@ -99,8 +102,8 @@ public class ResolverConfigurationImpl ...@@ -99,8 +102,8 @@ public class ResolverConfigurationImpl
return ll; return ll;
} }
private LinkedList searchlist; private LinkedList<String> searchlist;
private LinkedList nameservers; private LinkedList<String> nameservers;
// Load DNS configuration from OS // Load DNS configuration from OS
...@@ -118,9 +121,9 @@ public class ResolverConfigurationImpl ...@@ -118,9 +121,9 @@ public class ResolverConfigurationImpl
// get the name servers from /etc/resolv.conf // get the name servers from /etc/resolv.conf
nameservers = nameservers =
(LinkedList)java.security.AccessController.doPrivileged( java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() { new java.security.PrivilegedAction<LinkedList<String>>() {
public Object run() { public LinkedList<String> run() {
// typically MAXNS is 3 but we've picked 5 here // typically MAXNS is 3 but we've picked 5 here
// to allow for additional servers if required. // to allow for additional servers if required.
return resolvconf("nameserver", 1, 5); return resolvconf("nameserver", 1, 5);
...@@ -137,15 +140,15 @@ public class ResolverConfigurationImpl ...@@ -137,15 +140,15 @@ public class ResolverConfigurationImpl
// obtain search list or local domain // obtain search list or local domain
private LinkedList getSearchList() { private LinkedList<String> getSearchList() {
LinkedList sl; LinkedList<String> sl;
// first try the search keyword in /etc/resolv.conf // first try the search keyword in /etc/resolv.conf
sl = (LinkedList)java.security.AccessController.doPrivileged( sl = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() { new java.security.PrivilegedAction<LinkedList<String>>() {
public Object run() { public LinkedList<String> run() {
LinkedList ll; LinkedList ll;
// first try search keyword (max 6 domains) // first try search keyword (max 6 domains)
...@@ -177,10 +180,10 @@ public class ResolverConfigurationImpl ...@@ -177,10 +180,10 @@ public class ResolverConfigurationImpl
// try domain keyword in /etc/resolv.conf // try domain keyword in /etc/resolv.conf
sl = (LinkedList)java.security.AccessController.doPrivileged( sl = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() { new java.security.PrivilegedAction<LinkedList<String>>() {
public Object run() { public LinkedList<String> run() {
LinkedList ll; LinkedList<String> ll;
ll = resolvconf("domain", 1, 1); ll = resolvconf("domain", 1, 1);
if (ll.size() > 0) { if (ll.size() > 0) {
...@@ -197,7 +200,7 @@ public class ResolverConfigurationImpl ...@@ -197,7 +200,7 @@ public class ResolverConfigurationImpl
// no local domain so try fallback (RPC) domain or // no local domain so try fallback (RPC) domain or
// hostname // hostname
sl = new LinkedList(); sl = new LinkedList<>();
String domain = fallbackDomain0(); String domain = fallbackDomain0();
if (domain != null && domain.length() > 0) { if (domain != null && domain.length() > 0) {
sl.add(domain); sl.add(domain);
...@@ -213,7 +216,7 @@ public class ResolverConfigurationImpl ...@@ -213,7 +216,7 @@ public class ResolverConfigurationImpl
opts = new OptionsImpl(); opts = new OptionsImpl();
} }
public List searchlist() { public List<String> searchlist() {
synchronized (lock) { synchronized (lock) {
loadConfig(); loadConfig();
...@@ -222,7 +225,7 @@ public class ResolverConfigurationImpl ...@@ -222,7 +225,7 @@ public class ResolverConfigurationImpl
} }
} }
public List nameservers() { public List<String> nameservers() {
synchronized (lock) { synchronized (lock) {
loadConfig(); loadConfig();
......
...@@ -131,7 +131,7 @@ static struct sockaddr *getBroadcast(JNIEnv *env, int sock, const char *name, s ...@@ -131,7 +131,7 @@ static struct sockaddr *getBroadcast(JNIEnv *env, int sock, const char *name, s
static short getSubnet(JNIEnv *env, int sock, const char *ifname); static short getSubnet(JNIEnv *env, int sock, const char *ifname);
static int getIndex(int sock, const char *ifname); static int getIndex(int sock, const char *ifname);
static int getFlags(JNIEnv *env, int sock, const char *ifname); static int getFlags(int sock, const char *ifname);
static int getMacAddress(JNIEnv *env, int sock, const char* ifname, const struct in_addr* addr, unsigned char *buf); static int getMacAddress(JNIEnv *env, int sock, const char* ifname, const struct in_addr* addr, unsigned char *buf);
static int getMTU(JNIEnv *env, int sock, const char *ifname); static int getMTU(JNIEnv *env, int sock, const char *ifname);
...@@ -550,7 +550,7 @@ static int getFlags0(JNIEnv *env, jstring name) { ...@@ -550,7 +550,7 @@ static int getFlags0(JNIEnv *env, jstring name) {
name_utf = (*env)->GetStringUTFChars(env, name, &isCopy); name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
ret = getFlags(env, sock, name_utf); ret = getFlags(sock, name_utf);
close(sock); close(sock);
(*env)->ReleaseStringUTFChars(env, name, name_utf); (*env)->ReleaseStringUTFChars(env, name, name_utf);
...@@ -753,19 +753,27 @@ static netif *enumInterfaces(JNIEnv *env) { ...@@ -753,19 +753,27 @@ static netif *enumInterfaces(JNIEnv *env) {
* If IPv6 is available then enumerate IPv6 addresses. * If IPv6 is available then enumerate IPv6 addresses.
*/ */
#ifdef AF_INET6 #ifdef AF_INET6
sock = openSocket(env, AF_INET6);
if (sock < 0 && (*env)->ExceptionOccurred(env)) {
freeif(ifs);
return NULL;
}
ifs = enumIPv6Interfaces(env, sock, ifs); /* User can disable ipv6 expicitly by -Djava.net.preferIPv4Stack=true,
close(sock); * so we have to call ipv6_available()
*/
if (ipv6_available()) {
if ((*env)->ExceptionOccurred(env)) { sock = openSocket(env, AF_INET6);
freeif(ifs); if (sock < 0 && (*env)->ExceptionOccurred(env)) {
return NULL; freeif(ifs);
} return NULL;
}
ifs = enumIPv6Interfaces(env, sock, ifs);
close(sock);
if ((*env)->ExceptionOccurred(env)) {
freeif(ifs);
return NULL;
}
}
#endif #endif
return ifs; return ifs;
...@@ -877,7 +885,7 @@ netif *addif(JNIEnv *env, int sock, const char * if_name, netif *ifs, struct soc ...@@ -877,7 +885,7 @@ netif *addif(JNIEnv *env, int sock, const char * if_name, netif *ifs, struct soc
* the 'parent' interface with the new records. * the 'parent' interface with the new records.
*/ */
*name_colonP = 0; *name_colonP = 0;
if (getFlags(env,sock,name) < 0) { if (getFlags(sock, name) < 0) {
// failed to access parent interface do not create parent. // failed to access parent interface do not create parent.
// We are a virtual interface with no parent. // We are a virtual interface with no parent.
isVirtual = 1; isVirtual = 1;
...@@ -1249,7 +1257,7 @@ static int getMTU(JNIEnv *env, int sock, const char *ifname) { ...@@ -1249,7 +1257,7 @@ static int getMTU(JNIEnv *env, int sock, const char *ifname) {
return if2.ifr_mtu; return if2.ifr_mtu;
} }
static int getFlags(JNIEnv *env, int sock, const char *ifname) { static int getFlags(int sock, const char *ifname) {
struct ifreq if2; struct ifreq if2;
int ret = -1; int ret = -1;
...@@ -1625,13 +1633,12 @@ static int getMTU(JNIEnv *env, int sock, const char *ifname) { ...@@ -1625,13 +1633,12 @@ static int getMTU(JNIEnv *env, int sock, const char *ifname) {
} }
static int getFlags(JNIEnv *env, int sock, const char *ifname) { static int getFlags(int sock, const char *ifname) {
struct lifreq lifr; struct lifreq lifr;
memset((caddr_t)&lifr, 0, sizeof(lifr)); memset((caddr_t)&lifr, 0, sizeof(lifr));
strcpy((caddr_t)&(lifr.lifr_name), ifname); strcpy((caddr_t)&(lifr.lifr_name), ifname);
if (ioctl(sock, SIOCGLIFFLAGS, (char *)&lifr) < 0) { if (ioctl(sock, SIOCGLIFFLAGS, (char *)&lifr) < 0) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGLIFFLAGS failed");
return -1; return -1;
} }
......
...@@ -32,14 +32,11 @@ ...@@ -32,14 +32,11 @@
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj, Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj, jlong address,
jlong address, jlong len) jlong len, jint numPages)
{ {
jboolean loaded = JNI_TRUE; jboolean loaded = JNI_TRUE;
jint pageSize = sysconf(_SC_PAGESIZE);
jint numPages = (len + pageSize - 1) / pageSize;
int result = 0; int result = 0;
int i = 0; int i = 0;
void *a = (void *) jlong_to_ptr(address); void *a = (void *) jlong_to_ptr(address);
...@@ -55,9 +52,9 @@ Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj, ...@@ -55,9 +52,9 @@ Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj,
} }
result = mincore(a, (size_t)len, vec); result = mincore(a, (size_t)len, vec);
if (result != 0) { if (result == -1) {
free(vec);
JNU_ThrowIOExceptionWithLastError(env, "mincore failed"); JNU_ThrowIOExceptionWithLastError(env, "mincore failed");
free(vec);
return JNI_FALSE; return JNI_FALSE;
} }
...@@ -72,23 +69,15 @@ Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj, ...@@ -72,23 +69,15 @@ Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj,
} }
JNIEXPORT jint JNICALL JNIEXPORT void JNICALL
Java_java_nio_MappedByteBuffer_load0(JNIEnv *env, jobject obj, jlong address, Java_java_nio_MappedByteBuffer_load0(JNIEnv *env, jobject obj, jlong address,
jlong len, jint pageSize) jlong len)
{ {
int pageIncrement = pageSize / sizeof(int); char *a = (char *)jlong_to_ptr(address);
int numPages = (len + pageSize - 1) / pageSize; int result = madvise((caddr_t)a, (size_t)len, MADV_WILLNEED);
int *ptr = (int *)jlong_to_ptr(address); if (result == -1) {
int i = 0; JNU_ThrowIOExceptionWithLastError(env, "madvise failed");
int j = 0;
int result = madvise((caddr_t)ptr, len, MADV_WILLNEED);
/* touch every page */
for (i=0; i<numPages; i++) {
j += *((volatile int *)ptr);
ptr += pageIncrement;
} }
return j;
} }
...@@ -96,13 +85,9 @@ JNIEXPORT void JNICALL ...@@ -96,13 +85,9 @@ JNIEXPORT void JNICALL
Java_java_nio_MappedByteBuffer_force0(JNIEnv *env, jobject obj, jlong address, Java_java_nio_MappedByteBuffer_force0(JNIEnv *env, jobject obj, jlong address,
jlong len) jlong len)
{ {
jlong pageSize = sysconf(_SC_PAGESIZE); void* a = (void *)jlong_to_ptr(address);
unsigned long lAddress = address; int result = msync(a, (size_t)len, MS_SYNC);
if (result == -1) {
jlong offset = lAddress % pageSize;
void *a = (void *) jlong_to_ptr(lAddress - offset);
int result = msync(a, (size_t)(len + offset), MS_SYNC);
if (result != 0) {
JNU_ThrowIOExceptionWithLastError(env, "msync failed"); JNU_ThrowIOExceptionWithLastError(env, "msync failed");
} }
} }
...@@ -84,3 +84,11 @@ Java_sun_nio_ch_SocketChannelImpl_checkConnect(JNIEnv *env, jobject this, ...@@ -84,3 +84,11 @@ Java_sun_nio_ch_SocketChannelImpl_checkConnect(JNIEnv *env, jobject this,
} }
return 0; return 0;
} }
JNIEXPORT jint JNICALL
Java_sun_nio_ch_SocketChannelImpl_sendOutOfBandData(JNIEnv* env, jclass this,
jobject fdo, jbyte b)
{
int n = send(fdval(env, fdo), (const void*)&b, 1, MSG_OOB);
return convertReturnVal(env, n, JNI_FALSE);
}
/* /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,7 +28,6 @@ package sun.net.dns; ...@@ -28,7 +28,6 @@ package sun.net.dns;
import java.util.List; import java.util.List;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.io.IOException;
/* /*
* An implementation of sun.net.ResolverConfiguration for Windows. * An implementation of sun.net.ResolverConfiguration for Windows.
...@@ -63,8 +62,8 @@ public class ResolverConfigurationImpl ...@@ -63,8 +62,8 @@ public class ResolverConfigurationImpl
// Parse string that consists of token delimited by space or commas // Parse string that consists of token delimited by space or commas
// and return LinkedHashMap // and return LinkedHashMap
private LinkedList stringToList(String str) { private LinkedList<String> stringToList(String str) {
LinkedList ll = new LinkedList(); LinkedList<String> ll = new LinkedList<>();
// comma and space are valid delimites // comma and space are valid delimites
StringTokenizer st = new StringTokenizer(str, ", "); StringTokenizer st = new StringTokenizer(str, ", ");
...@@ -112,7 +111,7 @@ public class ResolverConfigurationImpl ...@@ -112,7 +111,7 @@ public class ResolverConfigurationImpl
opts = new OptionsImpl(); opts = new OptionsImpl();
} }
public List searchlist() { public List<String> searchlist() {
synchronized (lock) { synchronized (lock) {
loadConfig(); loadConfig();
...@@ -121,7 +120,7 @@ public class ResolverConfigurationImpl ...@@ -121,7 +120,7 @@ public class ResolverConfigurationImpl
} }
} }
public List nameservers() { public List<String> nameservers() {
synchronized (lock) { synchronized (lock) {
loadConfig(); loadConfig();
......
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
#include <stdlib.h> #include <stdlib.h>
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj, Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj, jlong address,
jlong address, jlong len) jlong len, jint numPages)
{ {
jboolean loaded = JNI_FALSE; jboolean loaded = JNI_FALSE;
/* Information not available? /* Information not available?
...@@ -43,22 +43,11 @@ Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj, ...@@ -43,22 +43,11 @@ Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj,
return loaded; return loaded;
} }
JNIEXPORT jint JNICALL JNIEXPORT void JNICALL
Java_java_nio_MappedByteBuffer_load0(JNIEnv *env, jobject obj, jlong address, Java_java_nio_MappedByteBuffer_load0(JNIEnv *env, jobject obj, jlong address,
jlong len, jint pageSize) jlong len)
{ {
int *ptr = (int *) jlong_to_ptr(address); // no madvise available
int pageIncrement = pageSize / sizeof(int);
jlong numPages = (len + pageSize - 1) / pageSize;
int i = 0;
int j = 0;
/* touch every page */
for (i=0; i<numPages; i++) {
j += *((volatile int *)ptr);
ptr += pageIncrement;
}
return j;
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
......
...@@ -139,3 +139,16 @@ Java_sun_nio_ch_SocketChannelImpl_checkConnect(JNIEnv *env, jobject this, ...@@ -139,3 +139,16 @@ Java_sun_nio_ch_SocketChannelImpl_checkConnect(JNIEnv *env, jobject this,
return 0; return 0;
} }
JNIEXPORT jint JNICALL
Java_sun_nio_ch_SocketChannelImpl_sendOutOfBandData(JNIEnv* env, jclass this,
jobject fdo, jbyte b)
{
int n = send(fdval(env, fdo), (const char*)&b, 1, MSG_OOB);
if (n == SOCKET_ERROR) {
handleSocketError(env, WSAGetLastError());
return IOS_THROWN;
} else {
return n;
}
}
...@@ -310,24 +310,32 @@ typedef JLocalRef<jclass> JLClass; ...@@ -310,24 +310,32 @@ typedef JLocalRef<jclass> JLClass;
* Class to encapsulate the extraction of the java string contents * Class to encapsulate the extraction of the java string contents
* into a buffer and the cleanup of the buffer * into a buffer and the cleanup of the buffer
*/ */
class JavaStringBuffer class JavaStringBuffer
{ {
protected: protected:
LPWSTR m_pStr; LPWSTR m_pStr;
jsize m_dwSize; jsize m_dwSize;
LPWSTR getNonEmptyString() {
return (NULL==m_pStr)
? L""
: m_pStr;
}
public: public:
JavaStringBuffer(jsize cbTCharCount) { JavaStringBuffer(jsize cbTCharCount) {
m_dwSize = cbTCharCount; m_dwSize = cbTCharCount;
m_pStr = (LPWSTR)safe_Malloc( (m_dwSize+1)*sizeof(WCHAR) ); m_pStr = (0 == m_dwSize)
? NULL
: (LPWSTR)safe_Malloc( (m_dwSize+1)*sizeof(WCHAR) );
} }
JavaStringBuffer(JNIEnv *env, jstring text) { JavaStringBuffer(JNIEnv *env, jstring text) {
if (NULL == text) { m_dwSize = (NULL == text)
m_pStr = L""; ? 0
m_dwSize = 0; : env->GetStringLength(text);
if (0 == m_dwSize) {
m_pStr = NULL;
} else { } else {
m_dwSize = env->GetStringLength(text);
m_pStr = (LPWSTR)safe_Malloc( (m_dwSize+1)*sizeof(WCHAR) ); m_pStr = (LPWSTR)safe_Malloc( (m_dwSize+1)*sizeof(WCHAR) );
env->GetStringRegion(text, 0, m_dwSize, reinterpret_cast<jchar *>(m_pStr)); env->GetStringRegion(text, 0, m_dwSize, reinterpret_cast<jchar *>(m_pStr));
m_pStr[m_dwSize] = 0; m_pStr[m_dwSize] = 0;
...@@ -341,12 +349,16 @@ public: ...@@ -341,12 +349,16 @@ public:
void Resize(jsize cbTCharCount) { void Resize(jsize cbTCharCount) {
m_dwSize = cbTCharCount; m_dwSize = cbTCharCount;
//It is ok to have non-null terminated string here.
//The function is used only for space reservation in staff buffer for
//followed data copying process. And that is the reason why we ignore
//the special case m_dwSize==0 here.
m_pStr = (LPWSTR)safe_Realloc(m_pStr, (m_dwSize+1)*sizeof(WCHAR) ); m_pStr = (LPWSTR)safe_Realloc(m_pStr, (m_dwSize+1)*sizeof(WCHAR) );
} }
//we are in UNICODE now, so LPWSTR:=:LPTSTR //we are in UNICODE now, so LPWSTR:=:LPTSTR
operator LPWSTR() { return m_pStr; } operator LPWSTR() { return getNonEmptyString(); }
operator LPARAM() { return (LPARAM)m_pStr; } operator LPARAM() { return (LPARAM)getNonEmptyString(); }
void *GetData() { return (void *)m_pStr; } void *GetData() { return (void *)getNonEmptyString(); }
jsize GetSize() { return m_dwSize; } jsize GetSize() { return m_dwSize; }
}; };
......
...@@ -366,139 +366,6 @@ javax/print/attribute/MediaMappingsTest.java generic-all ...@@ -366,139 +366,6 @@ javax/print/attribute/MediaMappingsTest.java generic-all
# jdk_net # jdk_net
# Suspect many of these tests auffer from using fixed ports, no concrete
# evidence.
# Times out on Windows X64
sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java generic-all
# Dies on Solaris 10 sparc and sparcv9, Linux -ea -esa with
# Interrupted or IO exception, maybe writing to non-unique named file?
com/sun/net/httpserver/bugs/B6373555.java generic-all
# Fails on OpenSolaris, times out
java/net/MulticastSocket/SetOutgoingIf.java generic-all
# Timed out on Solaris 10 X86.
com/sun/net/httpserver/Test3.java generic-all
# Exception in test on windows
com/sun/net/httpserver/bugs/B6373555.java windows-all
# One of these pollutes the samevm on Linux, too many open files, kills jtreg
com/sun/net/httpserver/bugs/B6339483.java generic-all
com/sun/net/httpserver/bugs/B6341616.java generic-all
# Suspects in cascading samevm problem, solaris 11 i586 (needs othervm?)
# Suspect use of setHttps*()?
com/sun/net/httpserver/SelCacheTest.java generic-all
com/sun/net/httpserver/Test1.java generic-all
com/sun/net/httpserver/Test12.java generic-all
com/sun/net/httpserver/Test13.java generic-all
com/sun/net/httpserver/Test6a.java generic-all
com/sun/net/httpserver/Test7a.java generic-all
com/sun/net/httpserver/Test8a.java generic-all
com/sun/net/httpserver/Test9.java generic-all
com/sun/net/httpserver/Test9a.java generic-all
# 10,000 connections, fails on Linux and makes tests&jtreg fail with samevm
com/sun/net/httpserver/bugs/B6361557.java generic-all
# Address already in use with samevm? Always? Solaris sparc, probably ports
java/net/Authenticator/B4933582.sh generic-all
java/net/DatagramSocket/SendSize.java generic-all
# Solaris 11: exception wrong address???
java/net/Inet6Address/B6558853.java generic-all
# Not closing stream on file i6a1, windows samevm problem
java/net/Inet6Address/serialize/Serialize.java generic-all
# Linux x64 fails "network unreachable"?
java/net/ipv6tests/TcpTest.java generic-all
# Linux i586, fails with unexpected output
java/net/MulticastSocket/NoLoopbackPackets.java linux-i586
# Address already in use
java/net/DatagramSocket/DatagramTimeout.java generic-all
# Fails on windows, takes too long and fails
# Solaris 10 sparcv9, samevm, java.lang.Exception: Takes too long. Dead lock
java/net/Socket/DeadlockTest.java generic-all
# Linux i586 address already in use or connection error, samevm issues
java/net/Socket/AccurateTimeout.java generic-all
java/net/Socket/asyncClose/BrokenPipe.java generic-all
java/net/Socket/CloseAvailable.java generic-all
# Linux X64 address already in use, samevm issues
java/net/Socket/LingerTest.java generic-all
java/net/Socket/LinkLocal.java generic-all
java/net/Socket/NullHost.java generic-all
java/net/Socket/ProxyCons.java generic-all
java/net/Socket/ReadTimeout.java generic-all
# Linux X64 address already in use, samevm issues
java/net/Socket/SetReceiveBufferSize.java generic-all
# Linux i586 address already in use or connection error, samevm issues
java/net/Socket/setReuseAddress/Basic.java generic-all
java/net/Socket/setReuseAddress/Restart.java generic-all
# Linux X64 address already in use, samevm issues
java/net/Socket/SetSoLinger.java generic-all
# Address already in use, windows samevm
java/net/Socket/Timeout.java generic-all
# Linux X64 address already in use, samevm issues
java/net/Socket/ShutdownBoth.java generic-all
java/net/Socket/SoTimeout.java generic-all
java/net/Socket/TestClose.java generic-all
java/net/Socket/UrgentDataTest.java generic-all
java/net/SocketInputStream/SocketClosedException.java generic-all
java/net/SocketInputStream/SocketTimeout.java generic-all
# Linux i586, address already in use or timeout, samevm issues
java/net/URLConnection/DisconnectAfterEOF.java generic-all
java/net/URLConnection/HandleContentTypeWithAttrs.java generic-all
java/net/URLConnection/Responses.java generic-all
java/net/URLConnection/TimeoutTest.java generic-all
java/net/URLConnection/ZeroContentLength.java generic-all
# Solaris 11 i586 fails with samevm, not sure why
java/net/ResponseCache/B6181108.java generic-all
java/net/ResponseCache/ResponseCacheTest.java generic-all
java/net/URL/GetContent.java generic-all
java/net/URLConnection/HttpContinueStackOverflow.java generic-all
java/net/URLConnection/Redirect307Test.java generic-all
java/net/URLConnection/RedirectLimit.java generic-all
java/net/URLConnection/ResendPostBody.java generic-all
java/net/URL/OpenStream.java generic-all
java/net/URLClassLoader/ClassLoad.java generic-all
java/net/URLConnection/SetIfModifiedSince.java generic-all
java/net/URLConnection/URLConnectionHeaders.java generic-all
# Linux i586 Connection refused or address already in use, samevm issues
sun/net/ftp/B6427768.java generic-all
sun/net/ftp/FtpGetContent.java generic-all
sun/net/ftp/FtpURL.java generic-all
# Failed on solaris 10 i586, Exception: should have gotten HttpRetryException?
sun/net/www/http/ChunkedOutputStream/Test.java generic-all
# Trouble cleaning up threads in samevm mode on solaris 11 i586
sun/net/www/http/HttpClient/ProxyTest.java generic-all
sun/net/www/http/ChunkedInputStream/ChunkedEncodingTest.java generic-all
sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java generic-all
sun/net/www/http/HttpClient/B6726695.java generic-all
sun/net/www/http/HttpClient/MultiThreadTest.java generic-all
sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java generic-all
# Connection refused, windows samevm
sun/net/www/protocol/http/DigestTest.java generic-all
############################################################################ ############################################################################
# jdk_io # jdk_io
......
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -141,7 +141,10 @@ topPid=$$ ...@@ -141,7 +141,10 @@ topPid=$$
cleanup() cleanup()
{ {
if [ -r "$failFile" ] ; then if [ -r "$failFile" ] ; then
cat $failFile >& 2 ls -l "$failFile" >&2
echo "<cleanup:_begin_failFile_contents>" >&2
cat "$failFile" >&2
echo "<cleanup:_end_failFile_contents>" >&2
fi fi
# Kill all processes that have our special # Kill all processes that have our special
...@@ -337,6 +340,10 @@ EOF ...@@ -337,6 +340,10 @@ EOF
failFile=$tmpFileDir/testFailed failFile=$tmpFileDir/testFailed
debuggeepidFile=$tmpFileDir/debuggeepid debuggeepidFile=$tmpFileDir/debuggeepid
rm -f $failFile $debuggeepidFile rm -f $failFile $debuggeepidFile
if [ -f "$failFile" ]; then
echo "ERROR: unable to delete existing failFile:" >&2
ls -l "$failFile" >&2
fi
if [ -z "$pkg" ] ; then if [ -z "$pkg" ] ; then
pkgSlash= pkgSlash=
...@@ -524,6 +531,10 @@ cmd() ...@@ -524,6 +531,10 @@ cmd()
# See 6562090. Maybe there is a way that the exit # See 6562090. Maybe there is a way that the exit
# can cause jdb to not get the quit. # can cause jdb to not get the quit.
sleep 5 sleep 5
# The exit code value here doesn't matter since this function
# is called as part of a pipeline and it is not the last command
# in the pipeline.
exit 1 exit 1
fi fi
...@@ -938,6 +949,10 @@ waitForFinish() ...@@ -938,6 +949,10 @@ waitForFinish()
done done
if [ -r "$failFile" ] ; then if [ -r "$failFile" ] ; then
ls -l "$failFile" >&2
echo "<waitForFinish:_begin_failFile_contents>" >&2
cat "$failFile" >&2
echo "<waitForFinish:_end_failFile_contents>" >&2
exit 1 exit 1
fi fi
} }
...@@ -946,33 +961,45 @@ waitForFinish() ...@@ -946,33 +961,45 @@ waitForFinish()
# $3 is the number of lines to search (from the end) # $3 is the number of lines to search (from the end)
grepForString() grepForString()
{ {
# See bug 6220903. Sometimes the jdb '> ' prompt chars
# get inserted into the string we are searching for
# so ignore those chars.
if [ -z "$3" ] ; then if [ -z "$3" ] ; then
theCmd=cat theCmd=cat
else else
theCmd="tail -$3" theCmd="tail -$3"
fi fi
case "$2" in case "$2" in
*\>*) *\>*)
# Target string contains a > so we better # Target string contains a '>' so we better not ignore it
# not ignore it
$theCmd $1 | $grep -s "$2" > $devnull 2>&1 $theCmd $1 | $grep -s "$2" > $devnull 2>&1
return $? stat="$?"
;; ;;
*)
# Target string does not contain a '>'.
# NOTE: if $1 does not end with a new line, piping it to sed
# doesn't include the chars on the last line. Detect this
# case, and add a new line.
theFile="$1"
if [ `tail -1 "$theFile" | wc -l | sed -e 's@ @@g'` = 0 ] ; then
# The target file doesn't end with a new line so we have
# add one to a copy of the target file so the sed command
# below can filter that last line.
cp "$theFile" "$theFile.tmp"
theFile="$theFile.tmp"
echo >> "$theFile"
fi
# See bug 6220903. Sometimes the jdb prompt chars ('> ') can
# get interleaved in the target file which can keep us from
# matching the target string.
$theCmd "$theFile" | sed -e 's@> @@g' -e 's@>@@g' \
| $grep -s "$2" > $devnull 2>&1
stat=$?
if [ "$theFile" != "$1" ]; then
# remove the copy of the target file
rm -f "$theFile"
fi
unset theFile
esac esac
# Target string does not contain a >.
# Ignore > and '> ' in the file.
# NOTE: if $1 does not end with a new line, piping it to sed doesn't include the
# chars on the last line. Detect this case, and add a new line.
cp $1 $1.tmp
if [ `tail -1 $1.tmp | wc -l | sed -e 's@ @@g'` = 0 ] ; then
echo >> $1.tmp
fi
$theCmd $1.tmp | sed -e 's@> @@g' -e 's@>@@g' | $grep -s "$2" > $devnull 2>&1
stat=$?
rm -f $1.tmp
return $stat return $stat
} }
...@@ -1037,6 +1064,11 @@ pass() ...@@ -1037,6 +1064,11 @@ pass()
echo echo
echo "--Done: test passed" echo "--Done: test passed"
exit 0 exit 0
else
ls -l "$failFile" >&2
echo "<pass:_begin_failFile_contents>" >&2
cat "$failFile" >&2
echo "<pass:_end_failFile_contents>" >&2
fi fi
} }
......
/*
* Copyright (c) 2010, 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.
*/
/*
* @test
* @bug 6676075
* @summary RegistryContext (com.sun.jndi.url.rmi.rmiURLContext) coding problem
*/
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import com.sun.jndi.rmi.registry.*;
public class ContextWithNullProperties {
public static void main(String[] args) throws Exception {
// Create registry on port 1099 if one is not already running.
try {
LocateRegistry.createRegistry(1099);
} catch (RemoteException e) {
}
System.out.println("Connecting to the default Registry...");
// Connect to the default Registry.
// Pass null as the JNDI environment properties (see final argument)
RegistryContext ctx = new RegistryContext(null, -1, null);
}
}
...@@ -24,17 +24,15 @@ ...@@ -24,17 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test1
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/* basic http/s connectivity test /* basic http/s connectivity test
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
*/ */
import java.net.*; import java.net.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
...@@ -52,22 +51,25 @@ public class Test11 { ...@@ -52,22 +51,25 @@ public class Test11 {
public static void main (String[] args) throws Exception { public static void main (String[] args) throws Exception {
System.out.print ("Test 11: "); System.out.print ("Test 11: ");
HttpServer server = HttpServer.create (new InetSocketAddress(0), 0); HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
HttpContext ctx = server.createContext ( ExecutorService s = Executors.newCachedThreadPool();
"/foo/bar/", new Handler () try {
); HttpContext ctx = server.createContext (
ExecutorService s = Executors.newCachedThreadPool(); "/foo/bar/", new Handler ()
server.setExecutor (s); );
server.start (); s = Executors.newCachedThreadPool();
URL url = new URL ("http://localhost:" + server.getAddress().getPort()+ server.start ();
"/Foo/bar/test.html"); URL url = new URL ("http://localhost:" + server.getAddress().getPort()+
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); "/Foo/bar/test.html");
int r = urlc.getResponseCode(); HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
System.out.println ("OK"); int r = urlc.getResponseCode();
s.shutdown(); if (r == 200) {
server.stop(5); throw new RuntimeException ("wrong response received");
if (r == 200) { }
throw new RuntimeException ("wrong response received"); System.out.println ("OK");
} finally {
s.shutdown();
server.stop(2);
} }
} }
} }
...@@ -24,17 +24,15 @@ ...@@ -24,17 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test12
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/* basic http/s connectivity test /* basic http/s connectivity test
......
...@@ -24,17 +24,16 @@ ...@@ -24,17 +24,16 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test13
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/* basic http/s connectivity test /* basic http/s connectivity test
......
...@@ -24,17 +24,15 @@ ...@@ -24,17 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test6a
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/** /**
......
...@@ -24,18 +24,15 @@ ...@@ -24,18 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test7a
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.logging.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/** /**
......
...@@ -24,18 +24,15 @@ ...@@ -24,18 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test8a
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.logging.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/** /**
...@@ -50,46 +47,50 @@ public class Test8a extends Test { ...@@ -50,46 +47,50 @@ public class Test8a extends Test {
//h.setLevel (Level.INFO); //h.setLevel (Level.INFO);
//log.addHandler (h); //log.addHandler (h);
//log.setLevel (Level.INFO); //log.setLevel (Level.INFO);
Handler handler = new Handler(); HttpsServer server = null;
InetSocketAddress addr = new InetSocketAddress (0); ExecutorService executor = null;
HttpsServer server = HttpsServer.create (addr, 0); try {
HttpContext ctx = server.createContext ("/test", handler); Handler handler = new Handler();
ExecutorService executor = Executors.newCachedThreadPool(); InetSocketAddress addr = new InetSocketAddress (0);
SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get(); server = HttpsServer.create (addr, 0);
server.setHttpsConfigurator(new HttpsConfigurator (ssl)); HttpContext ctx = server.createContext ("/test", handler);
server.setExecutor (executor); executor = Executors.newCachedThreadPool();
server.start (); SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
server.setExecutor (executor);
server.start ();
URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html"); URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");
System.out.print ("Test8a: " ); System.out.print ("Test8a: " );
HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection (); HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();
urlc.setDoOutput (true); urlc.setDoOutput (true);
urlc.setRequestMethod ("POST"); urlc.setRequestMethod ("POST");
urlc.setHostnameVerifier (new DummyVerifier()); urlc.setHostnameVerifier (new DummyVerifier());
urlc.setSSLSocketFactory (ssl.getSocketFactory()); urlc.setSSLSocketFactory (ssl.getSocketFactory());
OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000); OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000);
for (int i=0; i<SIZE; i++) { for (int i=0; i<SIZE; i++) {
os.write (i % 250); os.write (i % 250);
} }
os.close(); os.close();
int resp = urlc.getResponseCode(); int resp = urlc.getResponseCode();
if (resp != 200) { if (resp != 200) {
throw new RuntimeException ("test failed response code"); throw new RuntimeException ("test failed response code");
}
InputStream is = urlc.getInputStream ();
for (int i=0; i<SIZE; i++) {
int f = is.read();
if (f != (i % 250)) {
System.out.println ("Setting error(" +f +")("+i+")" );
error = true;
break;
} }
InputStream is = urlc.getInputStream ();
for (int i=0; i<SIZE; i++) {
int f = is.read();
if (f != (i % 250)) {
System.out.println ("Setting error(" +f +")("+i+")" );
error = true;
break;
}
}
is.close();
} finally {
delay();
if (server != null) server.stop(2);
if (executor != null) executor.shutdown();
} }
is.close();
delay();
server.stop(2);
executor.shutdown();
if (error) { if (error) {
throw new RuntimeException ("test failed error"); throw new RuntimeException ("test failed error");
} }
......
...@@ -24,17 +24,15 @@ ...@@ -24,17 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test9
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/* Same as Test1 but requests run in parallel. /* Same as Test1 but requests run in parallel.
......
...@@ -24,17 +24,15 @@ ...@@ -24,17 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test9a
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/* Same as Test1 but requests run in parallel. /* Same as Test1 but requests run in parallel.
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
/** /**
* @test * @test
* @bug 6361557 * @bug 6361557
* @run main/othervm B6361557
* @summary Lightweight HTTP server quickly runs out of file descriptors on Linux * @summary Lightweight HTTP server quickly runs out of file descriptors on Linux
*/ */
...@@ -35,12 +36,9 @@ import java.io.*; ...@@ -35,12 +36,9 @@ import java.io.*;
import java.nio.*; import java.nio.*;
import java.nio.channels.*; import java.nio.channels.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*;
/** /**
* The test simply opens 10,000 separate connections * The test simply opens 1,000 separate connections
* and invokes one http request on each. The client does * and invokes one http request on each. The client does
* not close any sockets until after they are closed * not close any sockets until after they are closed
* by the server. This verifies the basic ability * by the server. This verifies the basic ability
...@@ -49,6 +47,7 @@ import javax.net.ssl.*; ...@@ -49,6 +47,7 @@ import javax.net.ssl.*;
public class B6361557 { public class B6361557 {
public static boolean error = false; public static boolean error = false;
static final int NUM = 1000;
static class Handler implements HttpHandler { static class Handler implements HttpHandler {
int invocation = 1; int invocation = 1;
...@@ -65,6 +64,9 @@ public class B6361557 { ...@@ -65,6 +64,9 @@ public class B6361557 {
} }
} }
final static String request = "GET /test/foo.html HTTP/1.1\r\nContent-length: 0\r\n\r\n";
final static ByteBuffer requestBuf = ByteBuffer.allocate(64).put(request.getBytes());
public static void main (String[] args) throws Exception { public static void main (String[] args) throws Exception {
Handler handler = new Handler(); Handler handler = new Handler();
InetSocketAddress addr = new InetSocketAddress (0); InetSocketAddress addr = new InetSocketAddress (0);
...@@ -75,49 +77,72 @@ public class B6361557 { ...@@ -75,49 +77,72 @@ public class B6361557 {
server.setExecutor (executor); server.setExecutor (executor);
server.start (); server.start ();
final int NUM = 10000;
ByteBuffer buf = ByteBuffer.allocate (4096);
InetSocketAddress destaddr = new InetSocketAddress ( InetSocketAddress destaddr = new InetSocketAddress (
"127.0.0.1", server.getAddress().getPort() "127.0.0.1", server.getAddress().getPort()
); );
System.out.println ("destaddr " + destaddr); System.out.println ("destaddr " + destaddr);
Selector selector = Selector.open (); Selector selector = Selector.open ();
int i = 0; int requests = 0;
int responses = 0;
while (true) { while (true) {
i ++;
int selres = selector.select (1); int selres = selector.select (1);
Set<SelectionKey> selkeys = selector.selectedKeys(); Set<SelectionKey> selkeys = selector.selectedKeys();
for (SelectionKey key : selkeys) { for (SelectionKey key : selkeys) {
if (key.isReadable()) { if (key.isReadable()) {
SocketChannel chan = (SocketChannel)key.channel(); SocketChannel chan = (SocketChannel)key.channel();
buf.clear(); ByteBuffer buf = (ByteBuffer)key.attachment();
try { try {
int x = chan.read (buf); int x = chan.read(buf);
if (x == -1) { if (x == -1 || responseComplete(buf)) {
key.attach(null);
chan.close(); chan.close();
responses++;
} }
} catch (IOException e) {} } catch (IOException e) {}
} }
} }
if (i< NUM) { if (requests < NUM) {
SocketChannel schan = SocketChannel.open (destaddr); SocketChannel schan = SocketChannel.open(destaddr);
String cmd = "GET /test/foo.html HTTP/1.1\r\nContent-length: 0\r\n\r\n"; requestBuf.rewind();
buf.rewind ();
buf.put (cmd.getBytes());
buf.flip();
int c = 0; int c = 0;
while (buf.remaining() > 0) { while (requestBuf.remaining() > 0) {
c += schan.write (buf); c += schan.write(requestBuf);
} }
schan.configureBlocking (false); schan.configureBlocking(false);
schan.register (selector, SelectionKey.OP_READ, null); schan.register(selector, SelectionKey.OP_READ, ByteBuffer.allocate(100));
} else { requests++;
}
if (responses == NUM) {
System.out.println ("Finished clients"); System.out.println ("Finished clients");
server.stop (1); break;
executor.shutdown (); }
return; }
server.stop (1);
selector.close();
executor.shutdown ();
}
/* Look for CR LF CR LF */
static boolean responseComplete(ByteBuffer buf) {
int pos = buf.position();
buf.flip();
byte[] lookingFor = new byte[] {'\r', '\n', '\r', '\n' };
int lookingForCount = 0;
while (buf.hasRemaining()) {
byte b = buf.get();
if (b == lookingFor[lookingForCount]) {
lookingForCount++;
if (lookingForCount == 4) {
return true;
}
} else {
lookingForCount = 0;
} }
} }
buf.position(pos);
buf.limit(buf.capacity());
return false;
} }
} }
...@@ -46,7 +46,7 @@ public class B6373555 { ...@@ -46,7 +46,7 @@ public class B6373555 {
private static Object lock; private static Object lock;
static HttpServer httpServer; static HttpServer httpServer;
static ExecutorService pool, execs; static ExecutorService pool, execs;
static int NUM = 4000; static int NUM = 1000;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
try { try {
...@@ -125,7 +125,7 @@ public class B6373555 { ...@@ -125,7 +125,7 @@ public class B6373555 {
} }
} }
catch(Exception e) { catch(Exception e) {
//e.printStackTrace(); e.printStackTrace();
System.out.print ("."); System.out.print (".");
error = true; error = true;
} }
......
/* /*
* Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 4631471 * @bug 4631471 6972468
* @summary Tests DefaultTreeModel encoding * @summary Tests DefaultTreeModel encoding
* @author Sergey Malenkov, Mark Davidson * @author Sergey Malenkov, Mark Davidson
*/ */
...@@ -37,6 +37,12 @@ import javax.swing.tree.TreeNode; ...@@ -37,6 +37,12 @@ import javax.swing.tree.TreeNode;
public abstract class Test4631471 extends AbstractTest { public abstract class Test4631471 extends AbstractTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
main();
System.setSecurityManager(new SecurityManager());
main();
}
private static void main() throws Exception {
// the DefaultMutableTreeNode will archive correctly // the DefaultMutableTreeNode will archive correctly
new Test4631471() { new Test4631471() {
protected Object getObject() { protected Object getObject() {
......
/* /*
* Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 4903007 * @bug 4903007 6972468
* @summary Tests encoding of container with boxes and BoxLayout * @summary Tests encoding of container with boxes and BoxLayout
* @author Sergey Malenkov, Mark Davidson * @author Sergey Malenkov, Mark Davidson
*/ */
...@@ -36,7 +36,7 @@ import javax.swing.JPanel; ...@@ -36,7 +36,7 @@ import javax.swing.JPanel;
public class Test4903007 extends AbstractTest<JPanel> { public class Test4903007 extends AbstractTest<JPanel> {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
new Test4903007().test(false); // TODO: could not encode with security manager new Test4903007().test(true);
} }
protected JPanel getObject() { protected JPanel getObject() {
......
/* /*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 5023552 * @bug 5023552 6972468
* @summary Tests JLayeredPane encoding * @summary Tests JLayeredPane encoding
* @author Sergey Malenkov * @author Sergey Malenkov
*/ */
...@@ -35,7 +35,7 @@ import javax.swing.JPanel; ...@@ -35,7 +35,7 @@ import javax.swing.JPanel;
public final class javax_swing_JLayeredPane extends AbstractTest<JLayeredPane> { public final class javax_swing_JLayeredPane extends AbstractTest<JLayeredPane> {
public static void main(String[] args) { public static void main(String[] args) {
new javax_swing_JLayeredPane().test(false); // TODO: could not encode with security manager new javax_swing_JLayeredPane().test(true);
} }
private static void init(JLayeredPane pane, int layer, int x, int y, int w, int h, Color color) { private static void init(JLayeredPane pane, int layer, int x, int y, int w, int h, Color color) {
......
...@@ -26,7 +26,7 @@ import java.util.*; ...@@ -26,7 +26,7 @@ import java.util.*;
/* /*
* @test * @test
* @bug 6911258 6962571 * @bug 6911258 6962571 6963622
* @summary Basic tests of suppressed exceptions * @summary Basic tests of suppressed exceptions
* @author Joseph D. Darcy * @author Joseph D. Darcy
*/ */
...@@ -35,11 +35,22 @@ public class SuppressedExceptions { ...@@ -35,11 +35,22 @@ public class SuppressedExceptions {
private static String message = "Bad suppressed exception information"; private static String message = "Bad suppressed exception information";
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
noSelfSuppression();
basicSupressionTest(); basicSupressionTest();
serializationTest(); serializationTest();
selfReference(); selfReference();
} }
private static void noSelfSuppression() {
Throwable throwable = new Throwable();
try {
throwable.addSuppressedException(throwable);
throw new RuntimeException("IllegalArgumentException for self-suppresion not thrown.");
} catch (IllegalArgumentException iae) {
; // Expected
}
}
private static void basicSupressionTest() { private static void basicSupressionTest() {
Throwable throwable = new Throwable(); Throwable throwable = new Throwable();
RuntimeException suppressed = new RuntimeException("A suppressed exception."); RuntimeException suppressed = new RuntimeException("A suppressed exception.");
...@@ -156,9 +167,8 @@ public class SuppressedExceptions { ...@@ -156,9 +167,8 @@ public class SuppressedExceptions {
throwable1.printStackTrace(); throwable1.printStackTrace();
throwable1.addSuppressedException(throwable1);
throwable1.addSuppressedException(throwable2); throwable1.addSuppressedException(throwable2);
throwable2.addSuppressedException(throwable1);
throwable1.printStackTrace(); throwable1.printStackTrace();
} }
......
...@@ -27,25 +27,25 @@ ...@@ -27,25 +27,25 @@
* @summary test to see if timeout hangs * @summary test to see if timeout hangs
* @run main/timeout=15 DatagramTimeout * @run main/timeout=15 DatagramTimeout
*/ */
import java.net.*; import java.net.DatagramPacket;
import java.io.*; import java.net.DatagramSocket;
import java.net.SocketTimeoutException;
public class DatagramTimeout { public class DatagramTimeout {
public static ServerSocket sock;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
boolean success = false; boolean success = false;
DatagramSocket sock = new DatagramSocket();
try { try {
DatagramSocket sock;
DatagramPacket p; DatagramPacket p;
byte[] buffer = new byte[50]; byte[] buffer = new byte[50];
p = new DatagramPacket(buffer, buffer.length); p = new DatagramPacket(buffer, buffer.length);
sock = new DatagramSocket(2333);
sock.setSoTimeout(2); sock.setSoTimeout(2);
sock.receive(p); sock.receive(p);
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
success = true; success = true;
} finally {
sock.close();
} }
if (!success) if (!success)
throw new RuntimeException("Socket timeout failure."); throw new RuntimeException("Socket timeout failure.");
......
...@@ -32,35 +32,26 @@ ...@@ -32,35 +32,26 @@
* @author Benjamin Renaud * @author Benjamin Renaud
*/ */
import java.io.*; import java.io.IOException;
import java.net.*; import java.net.DatagramPacket;
import java.util.*; import java.net.DatagramSocket;
import java.net.InetAddress;
public class SendSize { public class SendSize {
static final int clientPort = 8989;
static final int serverPort = 9999;
static final int bufferLength = 512; static final int bufferLength = 512;
static final int packetLength = 256; static final int packetLength = 256;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
new ServerThread().start(); DatagramSocket serverSocket = new DatagramSocket();
new ClientThread().start(); new ServerThread(serverSocket).start();
new ClientThread(serverSocket.getLocalPort()).start();
} }
static class ServerThread extends Thread { static class ServerThread extends Thread {
int port;
DatagramSocket server; DatagramSocket server;
ServerThread(int port) throws IOException { ServerThread(DatagramSocket server) {
this.port = port; this.server = server;
this.server = new DatagramSocket(port);
}
ServerThread() throws IOException {
this(SendSize.serverPort);
} }
public void run() { public void run() {
...@@ -85,33 +76,22 @@ public class SendSize { ...@@ -85,33 +76,22 @@ public class SendSize {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("caugth: " + e); throw new RuntimeException("caugth: " + e);
} finally {
if (server != null) { server.close(); }
} }
} }
} }
static class ClientThread extends Thread { static class ClientThread extends Thread {
int port;
int serverPort; int serverPort;
int bufferLength;
int packetLength;
DatagramSocket client; DatagramSocket client;
InetAddress host; InetAddress host;
ClientThread(int port, int serverPort, ClientThread(int serverPort)throws IOException {
int bufferLength, int packetLength) throws IOException {
this.port = port;
this.serverPort = serverPort; this.serverPort = serverPort;
this.host = InetAddress.getLocalHost(); this.host = InetAddress.getLocalHost();
this.bufferLength = bufferLength; this.client = new DatagramSocket();
this.packetLength = packetLength;
this.client = new DatagramSocket(port, host);
}
ClientThread() throws IOException {
this(SendSize.clientPort, SendSize.serverPort,
SendSize.bufferLength, SendSize.packetLength);
} }
public void run() { public void run() {
...@@ -129,6 +109,8 @@ public class SendSize { ...@@ -129,6 +109,8 @@ public class SendSize {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("caught: " + e); throw new RuntimeException("caught: " + e);
} finally {
if (client != null) { client.close(); }
} }
} }
} }
......
...@@ -43,6 +43,9 @@ public class B6558853 implements Runnable { ...@@ -43,6 +43,9 @@ public class B6558853 implements Runnable {
InetAddress dest = null; InetAddress dest = null;
while (l.hasMoreElements() && dest == null) { while (l.hasMoreElements() && dest == null) {
NetworkInterface nif = l.nextElement(); NetworkInterface nif = l.nextElement();
if (!nif.isUp())
continue;
for (InterfaceAddress a : nif.getInterfaceAddresses()) { for (InterfaceAddress a : nif.getInterfaceAddresses()) {
if (a.getAddress() instanceof Inet6Address) { if (a.getAddress() instanceof Inet6Address) {
Inet6Address a6 = (Inet6Address) a.getAddress(); Inet6Address a6 = (Inet6Address) a.getAddress();
...@@ -53,6 +56,7 @@ public class B6558853 implements Runnable { ...@@ -53,6 +56,7 @@ public class B6558853 implements Runnable {
} }
} }
} }
System.out.println("Using " + dest);
if (dest != null) { if (dest != null) {
B6558853 test = new B6558853(dest, port); B6558853 test = new B6558853(dest, port);
Thread thread = new Thread(test); Thread thread = new Thread(test);
......
...@@ -72,6 +72,7 @@ public class Serialize { ...@@ -72,6 +72,7 @@ public class Serialize {
File file = new File (System.getProperty("test.src"), "serial1.4.2.ser"); File file = new File (System.getProperty("test.src"), "serial1.4.2.ser");
ois = new ObjectInputStream(new FileInputStream(file)); ois = new ObjectInputStream(new FileInputStream(file));
nobj = (Inet6Address) ois.readObject(); nobj = (Inet6Address) ois.readObject();
ois.close();
if (!nobj.equals (InetAddress.getByName ("::1"))) { if (!nobj.equals (InetAddress.getByName ("::1"))) {
throw new RuntimeException ("old ::1 not deserialized right"); throw new RuntimeException ("old ::1 not deserialized right");
} }
...@@ -90,6 +91,8 @@ public class Serialize { ...@@ -90,6 +91,8 @@ public class Serialize {
nobj = (Inet6Address) ois.readObject(); nobj = (Inet6Address) ois.readObject();
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new RuntimeException("6656849 Not fixed: NullPointer when deserializing"); throw new RuntimeException("6656849 Not fixed: NullPointer when deserializing");
} finally {
ois.close();
} }
System.out.println(nobj); System.out.println(nobj);
System.out.println("All tests passed"); System.out.println("All tests passed");
...@@ -102,6 +105,7 @@ public class Serialize { ...@@ -102,6 +105,7 @@ public class Serialize {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("i6a1.ser")); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("i6a1.ser"));
Inet6Address nobj = (Inet6Address) ois.readObject(); Inet6Address nobj = (Inet6Address) ois.readObject();
ois.close();
if (nobj.equals(obj)) { if (nobj.equals(obj)) {
return true; return true;
......
...@@ -56,6 +56,8 @@ public class CheckJNI { ...@@ -56,6 +56,8 @@ public class CheckJNI {
while (ifs.hasMoreElements()) { while (ifs.hasMoreElements()) {
NetworkInterface nif = (NetworkInterface)ifs.nextElement(); NetworkInterface nif = (NetworkInterface)ifs.nextElement();
if (!nif.isUp())
continue;
Enumeration addrs = nif.getInetAddresses(); Enumeration addrs = nif.getInetAddresses();
while (addrs.hasMoreElements()) { while (addrs.hasMoreElements()) {
InetAddress addr = (InetAddress) addrs.nextElement(); InetAddress addr = (InetAddress) addrs.nextElement();
......
...@@ -76,6 +76,10 @@ public class SetOutgoingIf { ...@@ -76,6 +76,10 @@ public class SetOutgoingIf {
// now determine what (if any) type of addresses are assigned to this interface // now determine what (if any) type of addresses are assigned to this interface
for (InetAddress addr : Collections.list(nic.getInetAddresses())) { for (InetAddress addr : Collections.list(nic.getInetAddresses())) {
if (addr.isAnyLocalAddress())
continue;
System.out.println(" addr " + addr);
if (addr instanceof Inet4Address) { if (addr instanceof Inet4Address) {
netIf.ipv4Address(true); netIf.ipv4Address(true);
} else if (addr instanceof Inet6Address) { } else if (addr instanceof Inet6Address) {
......
/*
* Copyright (c) 2010, 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.
*/
/* @test
* @bug 6964714
* @run main/othervm IPv4Only
* @summary Test the networkinterface listing with java.net.preferIPv4Stack=true.
*/
import java.net.*;
import java.util.*;
public class IPv4Only {
public static void main(String[] args) throws Exception {
System.setProperty("java.net.preferIPv4Stack","true");
Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
while (nifs.hasMoreElements()) {
NetworkInterface nif = nifs.nextElement();
Enumeration<InetAddress> addrs = nif.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress hostAddr = addrs.nextElement();
if ( hostAddr instanceof Inet6Address ){
throw new RuntimeException( "NetworkInterfaceV6List failed - found v6 address " + hostAddr.getHostAddress() );
}
}
}
}
}
...@@ -67,9 +67,10 @@ public class B6181108 implements Runnable { ...@@ -67,9 +67,10 @@ public class B6181108 implements Runnable {
out.flush(); out.flush();
s.close(); s.close();
ss.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try { ss.close(); } catch (IOException unused) {}
} }
} }
...@@ -100,6 +101,7 @@ public class B6181108 implements Runnable { ...@@ -100,6 +101,7 @@ public class B6181108 implements Runnable {
URLConnection urlc = url.openConnection(); URLConnection urlc = url.openConnection();
int i = ((HttpURLConnection)(urlc)).getResponseCode(); int i = ((HttpURLConnection)(urlc)).getResponseCode();
System.out.println ("response code = " + i); System.out.println ("response code = " + i);
ResponseCache.setDefault(null);
} }
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import java.io.*; import java.io.*;
import java.nio.*;
import sun.net.www.ParseUtil; import sun.net.www.ParseUtil;
import javax.net.ssl.*; import javax.net.ssl.*;
...@@ -43,11 +42,16 @@ public class ResponseCacheTest implements Runnable { ...@@ -43,11 +42,16 @@ public class ResponseCacheTest implements Runnable {
static URL url1; static URL url1;
static URL url2; static URL url2;
static String FNPrefix, OutFNPrefix; static String FNPrefix, OutFNPrefix;
static List<Closeable> streams = new ArrayList<>();
static List<File> files = new ArrayList<>();
/* /*
* Our "http" server to return a 404 */ * Our "http" server to return a 404 */
public void run() { public void run() {
Socket s = null;
FileInputStream fis = null;
try { try {
Socket s = ss.accept(); s = ss.accept();
InputStream is = s.getInputStream (); InputStream is = s.getInputStream ();
BufferedReader r = new BufferedReader(new InputStreamReader(is)); BufferedReader r = new BufferedReader(new InputStreamReader(is));
...@@ -68,7 +72,7 @@ public class ResponseCacheTest implements Runnable { ...@@ -68,7 +72,7 @@ public class ResponseCacheTest implements Runnable {
out.print("Content-Length: "+file2.length()+"\r\n"); out.print("Content-Length: "+file2.length()+"\r\n");
out.print("Connection: close\r\n"); out.print("Connection: close\r\n");
out.print("\r\n"); out.print("\r\n");
FileInputStream fis = new FileInputStream(file2); fis = new FileInputStream(file2);
byte[] buf = new byte[(int)file2.length()]; byte[] buf = new byte[(int)file2.length()];
int len; int len;
while ((len = fis.read(buf)) != -1) { while ((len = fis.read(buf)) != -1) {
...@@ -81,6 +85,10 @@ public class ResponseCacheTest implements Runnable { ...@@ -81,6 +85,10 @@ public class ResponseCacheTest implements Runnable {
ss.close(); ss.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try { ss.close(); } catch (IOException unused) {}
try { s.close(); } catch (IOException unused) {}
try { fis.close(); } catch (IOException unused) {}
} }
} }
static class NameVerifier implements HostnameVerifier { static class NameVerifier implements HostnameVerifier {
...@@ -144,11 +152,14 @@ static class NameVerifier implements HostnameVerifier { ...@@ -144,11 +152,14 @@ static class NameVerifier implements HostnameVerifier {
// assert (headers1 == headers2 && file1 == file2.2) // assert (headers1 == headers2 && file1 == file2.2)
File file1 = new File(OutFNPrefix+"file1"); File file1 = new File(OutFNPrefix+"file1");
File file2 = new File(OutFNPrefix+"file2.2"); File file2 = new File(OutFNPrefix+"file2.2");
files.add(file1);
files.add(file2);
System.out.println("headers1"+headers1+"\nheaders2="+headers2); System.out.println("headers1"+headers1+"\nheaders2="+headers2);
if (!headers1.equals(headers2) || file1.length() != file2.length()) { if (!headers1.equals(headers2) || file1.length() != file2.length()) {
throw new RuntimeException("test failed"); throw new RuntimeException("test failed");
} }
} }
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
try { try {
ResponseCache.setDefault(new MyResponseCache()); ResponseCache.setDefault(new MyResponseCache());
...@@ -157,6 +168,12 @@ static class NameVerifier implements HostnameVerifier { ...@@ -157,6 +168,12 @@ static class NameVerifier implements HostnameVerifier {
new ResponseCacheTest(); new ResponseCacheTest();
} finally{ } finally{
ResponseCache.setDefault(null); ResponseCache.setDefault(null);
for (Closeable c: streams) {
try { c.close(); } catch (IOException unused) {}
}
for (File f: files) {
f.delete();
}
} }
} }
...@@ -184,6 +201,7 @@ static class NameVerifier implements HostnameVerifier { ...@@ -184,6 +201,7 @@ static class NameVerifier implements HostnameVerifier {
public MyCacheResponse(String filename) { public MyCacheResponse(String filename) {
try { try {
fis = new FileInputStream(new File(filename)); fis = new FileInputStream(new File(filename));
streams.add(fis);
ObjectInputStream ois = new ObjectInputStream(fis); ObjectInputStream ois = new ObjectInputStream(fis);
headers = (Map<String,List<String>>)ois.readObject(); headers = (Map<String,List<String>>)ois.readObject();
} catch (Exception ex) { } catch (Exception ex) {
...@@ -206,6 +224,8 @@ static class NameVerifier implements HostnameVerifier { ...@@ -206,6 +224,8 @@ static class NameVerifier implements HostnameVerifier {
try { try {
File file = new File(filename); File file = new File(filename);
fos = new FileOutputStream(file); fos = new FileOutputStream(file);
streams.add(fos);
files.add(file);
ObjectOutputStream oos = new ObjectOutputStream(fos); ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(rspHeaders); oos.writeObject(rspHeaders);
} catch (Exception ex) { } catch (Exception ex) {
......
...@@ -39,6 +39,7 @@ import java.io.*; ...@@ -39,6 +39,7 @@ import java.io.*;
public class getResponseCode { public class getResponseCode {
static URL url; static URL url;
static String FNPrefix; static String FNPrefix;
static List<Closeable> resources = new ArrayList<>();
getResponseCode() throws Exception { getResponseCode() throws Exception {
url = new URL("http://localhost/file1.cache"); url = new URL("http://localhost/file1.cache");
...@@ -57,6 +58,9 @@ public class getResponseCode { ...@@ -57,6 +58,9 @@ public class getResponseCode {
new getResponseCode(); new getResponseCode();
} finally{ } finally{
ResponseCache.setDefault(null); ResponseCache.setDefault(null);
for (Closeable c : resources) {
try { c.close(); } catch (IOException unused) {}
}
} }
} }
...@@ -77,6 +81,7 @@ public class getResponseCode { ...@@ -77,6 +81,7 @@ public class getResponseCode {
public MyResponse(String filename) { public MyResponse(String filename) {
try { try {
fis = new FileInputStream(new File(filename)); fis = new FileInputStream(new File(filename));
resources.add(fis);
headers = (Map<String,List<String>>)new ObjectInputStream(fis).readObject(); headers = (Map<String,List<String>>)new ObjectInputStream(fis).readObject();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex.getMessage()); throw new RuntimeException(ex.getMessage());
......
/*
* Copyright (c) 2002, 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.
*/
/* @test
* @bug 4512028
* @summary Check the tolerance on read timeouts.
*/
import java.net.*;
import java.io.*;
public class AccurateTimeout {
static final int TOLERANCE = 100;
static boolean skipTest() {
String os = System.getProperty("os.name");
if (os.equals("Windows 95") ||
os.equals("Windows 98") ||
os.equals("Windows Me")) {
System.out.println("Due to an OS bug timeout tolerance cannot be tested on this OS");
return true;
}
return false;
}
public static void main(String args[]) throws Exception {
if (skipTest()) {
return;
}
int failures = 0;
int timeout;
System.out.println("");
System.out.println("Testing Socket.getInputStream().read() ...");
System.out.println("");
ServerSocket ss = new ServerSocket(0);
Socket s1 = new Socket(InetAddress.getLocalHost(), ss.getLocalPort());
Socket s2 = ss.accept();
InputStream in = s1.getInputStream();
timeout = 100;
while (timeout < 2500) {
s1.setSoTimeout(timeout);
long startTime = System.currentTimeMillis();
try {
in.read();
} catch (SocketTimeoutException e) {
}
long actual = System.currentTimeMillis() - startTime;
System.out.print("excepted: " + timeout + " actual: " + actual);
if (Math.abs(actual-timeout) > TOLERANCE) {
System.out.print(" *** FAIL: outside tolerance");
failures++;
} else {
System.out.print(" PASS.");
}
System.out.println("");
timeout += 200;
}
s1.close();
s2.close();
ss.close();
// ----------
System.out.println("");
System.out.println("Testing DatagramSocket.receive ...");
System.out.println("");
byte b[] = new byte[8];
DatagramPacket p = new DatagramPacket(b, b.length);
DatagramSocket ds = new DatagramSocket();
timeout = 100;
while (timeout < 2500) {
ds.setSoTimeout(timeout);
long startTime = System.currentTimeMillis();
try {
ds.receive(p);
} catch (SocketTimeoutException e) {
}
long actual = System.currentTimeMillis() - startTime;
System.out.print("excepted: " + timeout + " actual: " + actual);
if (Math.abs(actual-timeout) > TOLERANCE) {
System.out.print(" *** FAIL: outside tolerance");
failures++;
} else {
System.out.print(" PASS.");
}
System.out.println("");
timeout += 200;
}
ds.close();
System.out.println("");
// ---------
if (failures > 0) {
throw new Exception("Test failed: " + failures +
" test(s) outside tolerance");
}
}
}
...@@ -47,6 +47,7 @@ public class CloseAvailable implements Runnable { ...@@ -47,6 +47,7 @@ public class CloseAvailable implements Runnable {
t.start(); t.start();
Socket soc = ss.accept(); Socket soc = ss.accept();
ss.close();
DataInputStream is = new DataInputStream(soc.getInputStream()); DataInputStream is = new DataInputStream(soc.getInputStream());
is.close(); is.close();
...@@ -64,7 +65,7 @@ public class CloseAvailable implements Runnable { ...@@ -64,7 +65,7 @@ public class CloseAvailable implements Runnable {
public void run() { public void run() {
try { try {
Socket s = new Socket(addr, port); Socket s = new Socket(addr, port);
s.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -33,29 +33,32 @@ import java.io.*; ...@@ -33,29 +33,32 @@ import java.io.*;
public class DeadlockTest { public class DeadlockTest {
public static void main(String [] argv) throws Exception { public static void main(String [] argv) throws Exception {
ServerSocket ss = new ServerSocket(0);
Socket clientSocket = new Socket();
// Start the server thread try {
Thread s1 = new Thread(new ServerThread()); // Start the server thread
s1.start(); Thread s1 = new Thread(new ServerThread(ss));
s1.start();
// Sleep to make sure s1 has created a server socket
Thread.sleep(1000); // Start the client thread
ClientThread ct = new ClientThread(clientSocket, ss.getLocalPort());
// Start the client thread Thread c1 = new Thread(ct);
ClientThread ct = new ClientThread(); c1.start();
Thread c1 = new Thread(ct);
c1.start(); // Wait for the client thread to finish
c1.join(20000);
// Wait for the client thread to finish
c1.join(40000); // If timeout, we assume there is a deadlock
if (c1.isAlive() == true) {
// If timeout, we assume there is a deadlock // Close the socket to force the server thread
if (c1.isAlive() == true) { // terminate too
// Close the socket to force the server thread s1.stop();
// terminate too throw new Exception("Takes too long. Dead lock");
s1.stop(); }
ct.getSock().close(); } finally {
throw new Exception("Takes too long. Dead lock"); ss.close();
clientSocket.close();
} }
} }
} }
...@@ -71,8 +74,8 @@ class ServerThread implements Runnable { ...@@ -71,8 +74,8 @@ class ServerThread implements Runnable {
Socket sock; Socket sock;
public ServerThread() throws Exception { public ServerThread(ServerSocket serverSocket) throws Exception {
this.server = serverSocket;
} }
public void ping(int cnt) { public void ping(int cnt) {
...@@ -85,7 +88,6 @@ class ServerThread implements Runnable { ...@@ -85,7 +88,6 @@ class ServerThread implements Runnable {
try { try {
if (Thread.currentThread().getName().startsWith("child") == false) { if (Thread.currentThread().getName().startsWith("child") == false) {
server = new ServerSocket(4711);
sock = server.accept(); sock = server.accept();
new Thread(this, "child").start(); new Thread(this, "child").start();
...@@ -107,6 +109,7 @@ class ServerThread implements Runnable { ...@@ -107,6 +109,7 @@ class ServerThread implements Runnable {
} }
} catch (Throwable e) { } catch (Throwable e) {
System.out.println(e);
// If anything goes wrong, just quit. // If anything goes wrong, just quit.
} }
...@@ -141,10 +144,11 @@ class ClientThread implements Runnable { ...@@ -141,10 +144,11 @@ class ClientThread implements Runnable {
Socket sock; Socket sock;
public ClientThread() throws Exception { public ClientThread(Socket sock, int serverPort) throws Exception {
try { try {
System.out.println("About to create a socket"); System.out.println("About to connect the client socket");
sock = new Socket(InetAddress.getLocalHost().getHostName(), 4711); this.sock = sock;
this.sock.connect(new InetSocketAddress("localhost", serverPort));
System.out.println("connected"); System.out.println("connected");
out = new ObjectOutputStream(sock.getOutputStream()); out = new ObjectOutputStream(sock.getOutputStream());
...@@ -156,10 +160,6 @@ class ClientThread implements Runnable { ...@@ -156,10 +160,6 @@ class ClientThread implements Runnable {
} }
} }
public Socket getSock() {
return sock;
}
private int cnt = 1; private int cnt = 1;
public void run() { public void run() {
...@@ -213,6 +213,7 @@ class Message implements java.io.Serializable { ...@@ -213,6 +213,7 @@ class Message implements java.io.Serializable {
System.out.println("write message done " + cnt++); System.out.println("write message done " + cnt++);
} catch (IOException ioe) { } catch (IOException ioe) {
// Ignore the exception // Ignore the exception
System.out.println(ioe);
} }
} }
} }
......
...@@ -81,7 +81,7 @@ public class LingerTest { ...@@ -81,7 +81,7 @@ public class LingerTest {
public void run() { public void run() {
System.out.println ("Another starts"); System.out.println ("Another starts");
try { try {
Thread.currentThread().sleep(delay); Thread.sleep(delay);
Socket s = new Socket("localhost", port); Socket s = new Socket("localhost", port);
synchronized (this) { synchronized (this) {
connected = true; connected = true;
...@@ -105,7 +105,6 @@ public class LingerTest { ...@@ -105,7 +105,6 @@ public class LingerTest {
Socket s1 = new Socket("localhost", ss.getLocalPort()); Socket s1 = new Socket("localhost", ss.getLocalPort());
Socket s2 = ss.accept(); Socket s2 = ss.accept();
// setup conditions for untransmitted data and lengthy // setup conditions for untransmitted data and lengthy
// linger interval // linger interval
s1.setSendBufferSize(128*1024); s1.setSendBufferSize(128*1024);
...@@ -122,14 +121,15 @@ public class LingerTest { ...@@ -122,14 +121,15 @@ public class LingerTest {
thr.start(); thr.start();
// give sender time to queue the data // give sender time to queue the data
Thread.currentThread().sleep(1000); Thread.sleep(1000);
// close the socket asynchronously // close the socket asynchronously
(new Thread(new Closer(s1))).start(); (new Thread(new Closer(s1))).start();
// give another time to run // give another time to run
Thread.currentThread().sleep(10000); Thread.sleep(10000);
ss.close();
// check that another is done // check that another is done
if (!another.connected()) { if (!another.connected()) {
throw new RuntimeException("Another thread is blocked"); throw new RuntimeException("Another thread is blocked");
......
...@@ -58,11 +58,10 @@ public class LinkLocal { ...@@ -58,11 +58,10 @@ public class LinkLocal {
} catch (SocketException e) { } catch (SocketException e) {
failed++; failed++;
System.out.println("Test failed: " + e); System.out.println("Test failed: " + e);
} finally {
s.close();
ss.close();
} }
// clean up
s.close();
ss.close();
} }
static void UdpTest(InetAddress ia, boolean connected) throws Exception { static void UdpTest(InetAddress ia, boolean connected) throws Exception {
...@@ -93,16 +92,16 @@ public class LinkLocal { ...@@ -93,16 +92,16 @@ public class LinkLocal {
ds1.send(p); ds1.send(p);
System.out.println("Packet has been sent."); System.out.println("Packet has been sent.");
ds2.setSoTimeout(1000); ds2.setSoTimeout(5000);
ds2.receive(p); ds2.receive(p);
System.out.println("Test passed - packet received."); System.out.println("Test passed - packet received.");
} catch (SocketException e) { } catch (SocketException e) {
failed++; failed++;
System.out.println("Test failed: " + e); System.out.println("Test failed: " + e);
} finally {
ds1.close();
ds2.close();
} }
ds1.close();
ds2.close();
} }
static void TestAddress(InetAddress ia) throws Exception { static void TestAddress(InetAddress ia) throws Exception {
...@@ -138,6 +137,9 @@ public class LinkLocal { ...@@ -138,6 +137,9 @@ public class LinkLocal {
Enumeration nifs = NetworkInterface.getNetworkInterfaces(); Enumeration nifs = NetworkInterface.getNetworkInterfaces();
while (nifs.hasMoreElements()) { while (nifs.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface)nifs.nextElement(); NetworkInterface ni = (NetworkInterface)nifs.nextElement();
if (!ni.isUp())
continue;
Enumeration addrs = ni.getInetAddresses(); Enumeration addrs = ni.getInetAddresses();
while (addrs.hasMoreElements()) { while (addrs.hasMoreElements()) {
InetAddress addr = (InetAddress)addrs.nextElement(); InetAddress addr = (InetAddress)addrs.nextElement();
......
...@@ -39,6 +39,7 @@ public class ProxyCons { ...@@ -39,6 +39,7 @@ public class ProxyCons {
public void run () { public void run () {
try { try {
Socket s = server.accept (); Socket s = server.accept ();
s.close();
while (!finished ()) { while (!finished ()) {
Thread.sleep (500); Thread.sleep (500);
} }
...@@ -58,10 +59,9 @@ public class ProxyCons { ...@@ -58,10 +59,9 @@ public class ProxyCons {
public ProxyCons() { public ProxyCons() {
} }
void test() { void test() throws Exception {
ServerSocket ss = new ServerSocket(0);
try { try {
ServerSocket ss = new ServerSocket();
ss.bind(new InetSocketAddress(0));
Server s = new Server(ss); Server s = new Server(ss);
s.start(); s.start();
Socket sock = new Socket(Proxy.NO_PROXY); Socket sock = new Socket(Proxy.NO_PROXY);
...@@ -70,10 +70,12 @@ public class ProxyCons { ...@@ -70,10 +70,12 @@ public class ProxyCons {
sock.close(); sock.close();
} catch (java.io.IOException e) { } catch (java.io.IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
ss.close();
} }
} }
public static void main(String[] args) { public static void main(String[] args) throws Exception {
ProxyCons c = new ProxyCons(); ProxyCons c = new ProxyCons();
c.test(); c.test();
} }
......
...@@ -44,7 +44,7 @@ public class ReadTimeout { ...@@ -44,7 +44,7 @@ public class ReadTimeout {
sin = InetAddress.getLocalHost(); sin = InetAddress.getLocalHost();
srv = new ServerSocket(port); srv = new ServerSocket(port);
port = srv.getLocalPort(); port = srv.getLocalPort();
soc = new Socket(sin, port, true); soc = new Socket(sin, port);
soc1 = srv.accept(); soc1 = srv.accept();
soc.setSoTimeout(tout); soc.setSoTimeout(tout);
...@@ -53,10 +53,10 @@ public class ReadTimeout { ...@@ -53,10 +53,10 @@ public class ReadTimeout {
os = soc1.getOutputStream(); os = soc1.getOutputStream();
is.read(); is.read();
} catch(InterruptedIOException e) { } catch(InterruptedIOException e) {
} finally {
soc.close();
soc1.close();
srv.close();
} }
soc.close();
soc1.close();
srv.close();
} }
} }
...@@ -32,29 +32,14 @@ import java.net.Socket; ...@@ -32,29 +32,14 @@ import java.net.Socket;
import java.net.ServerSocket; import java.net.ServerSocket;
public class SetReceiveBufferSize { public class SetReceiveBufferSize {
class Server extends Thread {
private ServerSocket ss;
public Server(ServerSocket ss) {
this.ss = ss;
}
public void run() {
try {
ss.accept();
} catch (Exception e) {
}
}
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
SetReceiveBufferSize s = new SetReceiveBufferSize(); SetReceiveBufferSize s = new SetReceiveBufferSize();
} }
public SetReceiveBufferSize() throws Exception { public SetReceiveBufferSize() throws Exception {
ServerSocket ss = new ServerSocket(0); ServerSocket ss = new ServerSocket(0);
Server serv = new Server(ss);
serv.start();
Socket s = new Socket("localhost", ss.getLocalPort()); Socket s = new Socket("localhost", ss.getLocalPort());
Socket accepted = ss.accept();
try { try {
s.setReceiveBufferSize(0); s.setReceiveBufferSize(0);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
...@@ -62,6 +47,8 @@ public class SetReceiveBufferSize { ...@@ -62,6 +47,8 @@ public class SetReceiveBufferSize {
} catch (Exception ex) { } catch (Exception ex) {
} finally { } finally {
ss.close(); ss.close();
s.close();
accepted.close();
} }
throw new RuntimeException("IllegalArgumentException not thrown!"); throw new RuntimeException("IllegalArgumentException not thrown!");
} }
......
...@@ -30,36 +30,24 @@ ...@@ -30,36 +30,24 @@
import java.net.*; import java.net.*;
public class SetSoLinger implements Runnable { public class SetSoLinger {
static ServerSocket ss; static final int LINGER = 65546;
static InetAddress addr;
static int port;
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
boolean error = true; int value;
int linger = 65546; InetAddress addr = InetAddress.getLocalHost();
int value = 0; ServerSocket ss = new ServerSocket(0);
addr = InetAddress.getLocalHost(); int port = ss.getLocalPort();
ss = new ServerSocket(0);
port = ss.getLocalPort();
Thread t = new Thread(new SetSoLinger()); Socket s = new Socket(addr, port);
t.start();
Socket soc = ss.accept(); Socket soc = ss.accept();
soc.setSoLinger(true, linger); soc.setSoLinger(true, LINGER);
value = soc.getSoLinger(); value = soc.getSoLinger();
soc.close(); soc.close();
s.close();
ss.close();
if(value != 65535) if(value != 65535)
throw new RuntimeException("Failed. Value not properly reduced."); throw new RuntimeException("Failed. Value not properly reduced.");
} }
public void run() {
try {
Socket s = new Socket(addr, port);
} catch (Exception e) {
e.printStackTrace();
}
}
} }
...@@ -36,12 +36,14 @@ public class ShutdownBoth { ...@@ -36,12 +36,14 @@ public class ShutdownBoth {
Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort()); Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort());
Socket s2 = ss.accept(); Socket s2 = ss.accept();
s1.shutdownInput(); try {
s1.shutdownOutput(); // failed b55 s1.shutdownInput();
s1.shutdownOutput(); // failed b55
s1.close(); } finally {
s2.close(); s1.close();
ss.close(); s2.close();
ss.close();
}
} }
} }
...@@ -52,9 +52,10 @@ public class SoTimeout implements Runnable { ...@@ -52,9 +52,10 @@ public class SoTimeout implements Runnable {
t.start(); t.start();
Socket s = serverSocket.accept(); Socket s = serverSocket.accept();
serverSocket.close();
// set a 1 second timeout on the socket // set a 5 second timeout on the socket
s.setSoTimeout(1000); s.setSoTimeout(5000);
s.getInputStream().read(b, 0, b.length); s.getInputStream().read(b, 0, b.length);
s.close(); s.close();
...@@ -64,7 +65,7 @@ public class SoTimeout implements Runnable { ...@@ -64,7 +65,7 @@ public class SoTimeout implements Runnable {
// this sequence should complete fairly quickly and if it // this sequence should complete fairly quickly and if it
// takes something resembling the the SoTimeout value then // takes something resembling the the SoTimeout value then
// we are probably incorrectly blocking and not waking up // we are probably incorrectly blocking and not waking up
if (waited > 500) { if (waited > 2000) {
throw new Exception("shouldn't take " + waited + " to complete"); throw new Exception("shouldn't take " + waited + " to complete");
} }
} }
......
...@@ -31,18 +31,16 @@ import java.net.*; ...@@ -31,18 +31,16 @@ import java.net.*;
import java.io.*; import java.io.*;
public class Timeout { public class Timeout {
public static ServerSocket sock;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
boolean success = false; boolean success = false;
ServerSocket sock = new ServerSocket(0);
try { try {
ServerSocket sock;
sock = new ServerSocket(2333);
sock.setSoTimeout(2); sock.setSoTimeout(2);
sock.accept(); sock.accept();
} catch (InterruptedIOException e) { } catch (InterruptedIOException e) {
success = true; success = true;
} finally {
sock.close();
} }
if (!success) if (!success)
throw new RuntimeException("Socket timeout failure."); throw new RuntimeException("Socket timeout failure.");
......
...@@ -90,63 +90,64 @@ public class UrgentDataTest { ...@@ -90,63 +90,64 @@ public class UrgentDataTest {
} }
public void run () throws Exception { public void run () throws Exception {
if (isClient) { try {
client = new Socket (clHost, clPort); if (isClient) {
clis = client.getInputStream(); client = new Socket (clHost, clPort);
clos = client.getOutputStream(); clis = client.getInputStream();
client.setOOBInline (true); clos = client.getOutputStream();
if (client.getOOBInline() != true) { client.setOOBInline (true);
throw new RuntimeException ("Setting OOBINLINE failed"); if (client.getOOBInline() != true) {
} throw new RuntimeException ("Setting OOBINLINE failed");
}
if (isServer) {
server = listener.accept ();
sis = server.getInputStream();
sos = server.getOutputStream();
}
if (isClient) {
clos.write ("Hello".getBytes ());
client.sendUrgentData (100);
clos.write ("world".getBytes ());
}
// read Hello world from server (during which oob byte must have been dropped)
String s = "Helloworld";
if (isServer) {
for (int y=0; y<s.length(); y++) {
int c = sis.read ();
if (c != (int)s.charAt (y)) {
throw new RuntimeException ("Unexpected character read");
} }
} }
// Do the same from server to client if (isServer) {
sos.write ("Hello".getBytes ()); server = listener.accept ();
server.sendUrgentData (101); sis = server.getInputStream();
sos.write ("World".getBytes ()); sos = server.getOutputStream();
} }
if (isClient) { if (isClient) {
// read Hello world from client (during which oob byte must have been read) clos.write ("Hello".getBytes ());
s="Hello"; client.sendUrgentData (100);
for (int y=0; y<s.length(); y++) { clos.write ("world".getBytes ());
int c = clis.read ();
if (c != (int)s.charAt (y)) {
throw new RuntimeException ("Unexpected character read");
}
} }
if (clis.read() != 101) { // read Hello world from server (during which oob byte must have been dropped)
throw new RuntimeException ("OOB byte not received"); String s = "Helloworld";
if (isServer) {
for (int y=0; y<s.length(); y++) {
int c = sis.read ();
if (c != (int)s.charAt (y)) {
throw new RuntimeException ("Unexpected character read");
}
}
// Do the same from server to client
sos.write ("Hello".getBytes ());
server.sendUrgentData (101);
sos.write ("World".getBytes ());
} }
s="World"; if (isClient) {
for (int y=0; y<s.length(); y++) { // read Hello world from client (during which oob byte must have been read)
int c = clis.read (); s="Hello";
if (c != (int)s.charAt (y)) { for (int y=0; y<s.length(); y++) {
throw new RuntimeException ("Unexpected character read"); int c = clis.read ();
if (c != (int)s.charAt (y)) {
throw new RuntimeException ("Unexpected character read");
}
}
if (clis.read() != 101) {
throw new RuntimeException ("OOB byte not received");
}
s="World";
for (int y=0; y<s.length(); y++) {
int c = clis.read ();
if (c != (int)s.charAt (y)) {
throw new RuntimeException ("Unexpected character read");
}
} }
} }
} finally {
if (listener != null) listener.close();
if (client != null) client.close ();
if (server != null) server.close ();
} }
if (isClient)
client.close ();
if (isServer)
server.close ();
} }
} }
...@@ -61,7 +61,6 @@ public class BrokenPipe { ...@@ -61,7 +61,6 @@ public class BrokenPipe {
try { try {
client.getOutputStream().write(new byte[1000000]); client.getOutputStream().write(new byte[1000000]);
} catch (IOException ioe) { } catch (IOException ioe) {
/* /*
* Check that the exception text doesn't indicate the * Check that the exception text doesn't indicate the
* socket is closed. In tiger we should be able to * socket is closed. In tiger we should be able to
...@@ -71,8 +70,9 @@ public class BrokenPipe { ...@@ -71,8 +70,9 @@ public class BrokenPipe {
if (text.toLowerCase().indexOf("closed") >= 0) { if (text.toLowerCase().indexOf("closed") >= 0) {
throw ioe; throw ioe;
} }
} finally {
server.close();
} }
server.close();
} }
} }
...@@ -39,27 +39,28 @@ public class Restart { ...@@ -39,27 +39,28 @@ public class Restart {
*/ */
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
ServerSocket ss = new ServerSocket(0);
Socket s1 = null, s2 = null;
try {
int port = ss.getLocalPort();
InetSocketAddress isa = new InetSocketAddress(0); s1 = new Socket(InetAddress.getLocalHost(), port);
ServerSocket ss = new ServerSocket(); s2 = ss.accept();
ss.bind(isa);
int port = ss.getLocalPort(); // close server socket and the accepted connection
ss.close();
s2.close();
Socket s1 = new Socket(InetAddress.getLocalHost(), port); ss = new ServerSocket();
Socket s2 = ss.accept(); ss.bind( new InetSocketAddress(port) );
ss.close();
// close server socket and the accepted connection // close the client socket
ss.close(); s1.close();
s2.close(); } finally {
if (ss != null) ss.close();
boolean failed = false; if (s1 != null) s1.close();
if (s2 != null) s2.close();
ss = new ServerSocket(); }
ss.bind( new InetSocketAddress(port) );
ss.close();
// close the client socket
s1.close();
} }
} }
...@@ -32,68 +32,37 @@ import java.io.*; ...@@ -32,68 +32,37 @@ import java.io.*;
import java.net.*; import java.net.*;
public class SocketClosedException { public class SocketClosedException {
/*
* Is the server ready to serve?
*/
volatile static boolean serverReady = false;
/*
* Define the server side of the test.
*
* If the server prematurely exits, serverReady will be set to true
* to avoid infinite hangs.
*/
static void doServerSide() throws Exception { static void doServerSide() throws Exception {
ServerSocket serverSocket = new ServerSocket(serverPort); try {
serverPort = serverSocket.getLocalPort(); Socket socket = serverSocket.accept();
/*
* Signal Client, we're ready for a connect.
*/
serverReady = true;
Socket socket = serverSocket.accept();
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
os.write(85);
os.flush();
socket.close();
}
/* OutputStream os = socket.getOutputStream();
* Define the client side of the test.
*
* If the server prematurely exits, serverReady will be set to true
* to avoid infinite hangs.
*/
static void doClientSide() throws Exception {
/* os.write(85);
* Wait for server to get started. os.flush();
*/ socket.close();
while (!serverReady) { } finally {
Thread.sleep(5000); serverSocket.close();
} }
}
Socket socket = new Socket("localhost", serverPort); static void doClientSide(int port) throws Exception {
Socket socket = new Socket("localhost", port);
InputStream is = socket.getInputStream(); InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
int read = is.read(); is.read();
socket.close(); socket.close();
read = is.read(); is.read();
} }
static int serverPort = 0; static ServerSocket serverSocket;
static Exception serverException = null; static Exception serverException = null;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
serverSocket = new ServerSocket(0);
startServer(); startServer();
try { try {
doClientSide(); doClientSide(serverSocket.getLocalPort());
} catch (SocketException e) { } catch (SocketException e) {
if (!e.getMessage().equalsIgnoreCase("Socket closed")) { if (!e.getMessage().equalsIgnoreCase("Socket closed")) {
throw new Exception("Received a wrong exception message: " + throw new Exception("Received a wrong exception message: " +
...@@ -108,21 +77,14 @@ public class SocketClosedException { ...@@ -108,21 +77,14 @@ public class SocketClosedException {
} }
static void startServer() { static void startServer() {
Thread serverThread = new Thread() { (new Thread() {
public void run() { public void run() {
try { try {
doServerSide(); doServerSide();
} catch (Exception e) { } catch (Exception e) {
/* e.printStackTrace();
* server thread just died.
* Release the client, if not active already...
*/
System.err.println("Server died...");
serverReady = true;
serverException = e;
} }
} }
}; }).start();
serverThread.start();
} }
} }
...@@ -31,26 +31,24 @@ import java.net.*; ...@@ -31,26 +31,24 @@ import java.net.*;
import java.io.*; import java.io.*;
public class SocketTimeout { public class SocketTimeout {
static final int TIMEOUT = 1000;
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
InetAddress sin = null; InetAddress sin = InetAddress.getLocalHost();
Socket soc = null,soc1 = null; Socket soc = null,soc1 = null;
InputStream is = null; InputStream is = null;
OutputStream os = null;
ServerSocket srv = null; ServerSocket srv = null;
int port = 0; int port = 0;
int tout = 1000;
sin = InetAddress.getLocalHost(); srv = new ServerSocket(0);
srv = new ServerSocket(port);
port = srv.getLocalPort(); port = srv.getLocalPort();
soc = new Socket(sin, port); soc = new Socket(sin, port);
soc1 = srv.accept(); soc1 = srv.accept();
soc.setSoTimeout(tout); soc.setSoTimeout(TIMEOUT);
srv.setSoTimeout(tout); srv.setSoTimeout(TIMEOUT);
try { try {
is = soc.getInputStream(); is = soc.getInputStream();
os = soc1.getOutputStream();
is.read(); is.read();
} catch(InterruptedIOException e) { } catch(InterruptedIOException e) {
try { try {
...@@ -59,6 +57,9 @@ public class SocketTimeout { ...@@ -59,6 +57,9 @@ public class SocketTimeout {
} catch(NoClassDefFoundError e1) { } catch(NoClassDefFoundError e1) {
throw new Exception ("SocketTimeoutException: not found"); throw new Exception ("SocketTimeoutException: not found");
} }
} finally {
soc.close();
soc1.close();
} }
// now check accept // now check accept
...@@ -72,12 +73,14 @@ public class SocketTimeout { ...@@ -72,12 +73,14 @@ public class SocketTimeout {
} catch(NoClassDefFoundError e1) { } catch(NoClassDefFoundError e1) {
throw new Exception ("SocketTimeoutException: not found"); throw new Exception ("SocketTimeoutException: not found");
} }
} finally {
srv.close();
} }
// Now check DatagramSocket.receive() // Now check DatagramSocket.receive()
DatagramSocket dg = new DatagramSocket (); DatagramSocket dg = new DatagramSocket ();
dg.setSoTimeout (tout); dg.setSoTimeout (TIMEOUT);
try { try {
dg.receive (new DatagramPacket (new byte [64], 64)); dg.receive (new DatagramPacket (new byte [64], 64));
...@@ -88,11 +91,8 @@ public class SocketTimeout { ...@@ -88,11 +91,8 @@ public class SocketTimeout {
} catch(NoClassDefFoundError e1) { } catch(NoClassDefFoundError e1) {
throw new Exception ("SocketTimeoutException: not found"); throw new Exception ("SocketTimeoutException: not found");
} }
} finally {
dg.close();
} }
soc.close();
soc1.close();
srv.close();
dg.close();
} }
} }
...@@ -53,11 +53,13 @@ public class GetContent implements Runnable { ...@@ -53,11 +53,13 @@ public class GetContent implements Runnable {
// wait for client to read response - otherwise http // wait for client to read response - otherwise http
// client get error and re-establish connection // client get error and re-establish connection
Thread.currentThread().sleep(2000); Thread.sleep(2000);
s.close(); s.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try { ss.close(); } catch (IOException unused) {}
} }
} }
...@@ -81,8 +83,6 @@ public class GetContent implements Runnable { ...@@ -81,8 +83,6 @@ public class GetContent implements Runnable {
error = false; error = false;
} }
ss.close();
if (error) if (error)
throw new RuntimeException("No IOException generated."); throw new RuntimeException("No IOException generated.");
} }
......
...@@ -27,20 +27,45 @@ ...@@ -27,20 +27,45 @@
* @summary Test for FileNotFoundException when loading bogus class * @summary Test for FileNotFoundException when loading bogus class
*/ */
import java.net.*; import java.io.InputStream;
import java.io.*; import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URL;
import java.net.URLClassLoader;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
public class ClassLoad { public class ClassLoad {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
boolean error = true; boolean error = true;
// Start a dummy server to return 404
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
HttpHandler handler = new HttpHandler() {
public void handle(HttpExchange t) throws IOException {
InputStream is = t.getRequestBody();
while (is.read() != -1);
t.sendResponseHeaders (404, -1);
t.close();
}
};
server.createContext("/", handler);
server.start();
// Client request
try { try {
URL url = new URL(args.length >= 1 ? args[0] : "http://jini.east/"); URL url = new URL("http://localhost:" + server.getAddress().getPort());
String name = args.length >= 2 ? args[1] : "foo.bar.Baz"; String name = args.length >= 2 ? args[1] : "foo.bar.Baz";
ClassLoader loader = new URLClassLoader(new URL[] { url }); ClassLoader loader = new URLClassLoader(new URL[] { url });
System.out.println(url);
Class c = loader.loadClass(name); Class c = loader.loadClass(name);
System.out.println("Loaded class \"" + c.getName() + "\"."); System.out.println("Loaded class \"" + c.getName() + "\".");
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
System.out.println(ex);
error = false; error = false;
} finally {
server.stop(0);
} }
if (error) if (error)
throw new RuntimeException("No ClassNotFoundException generated"); throw new RuntimeException("No ClassNotFoundException generated");
......
...@@ -56,7 +56,6 @@ public class DisconnectAfterEOF { ...@@ -56,7 +56,6 @@ public class DisconnectAfterEOF {
int cl = -1; int cl = -1;
int remaining = -1; int remaining = -1;
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
Random r = new Random();
boolean close = false; boolean close = false;
boolean inBody = false; boolean inBody = false;
...@@ -239,8 +238,6 @@ public class DisconnectAfterEOF { ...@@ -239,8 +238,6 @@ public class DisconnectAfterEOF {
} }
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
Random r = new Random();
// start server // start server
ServerSocket ss = new ServerSocket(0); ServerSocket ss = new ServerSocket(0);
Server svr = new Server(ss); Server svr = new Server(ss);
...@@ -273,7 +270,7 @@ public class DisconnectAfterEOF { ...@@ -273,7 +270,7 @@ public class DisconnectAfterEOF {
URLConnection uc1 = doRequest(uri); URLConnection uc1 = doRequest(uri);
doResponse(uc1); doResponse(uc1);
Thread.currentThread().sleep(2000); Thread.sleep(2000);
URLConnection uc2 = doRequest(uri); URLConnection uc2 = doRequest(uri);
......
...@@ -111,9 +111,8 @@ class myHttpServer implements Runnable, Cloneable { ...@@ -111,9 +111,8 @@ class myHttpServer implements Runnable, Cloneable {
} catch(Exception e) { } catch(Exception e) {
System.out.print("Server failure\n"); System.out.print("Server failure\n");
e.printStackTrace(); e.printStackTrace();
try { } finally {
serverSocket.close(); try { serverSocket.close(); } catch(IOException unused) {}
} catch(IOException e2) {}
} }
} else { } else {
try { try {
...@@ -127,10 +126,9 @@ class myHttpServer implements Runnable, Cloneable { ...@@ -127,10 +126,9 @@ class myHttpServer implements Runnable, Cloneable {
} catch(Exception e) { } catch(Exception e) {
// System.out.print("Service handler failure\n"); // System.out.print("Service handler failure\n");
// e.printStackTrace(); // e.printStackTrace();
} finally {
try { close(); } catch(IOException unused) {}
} }
try {
close();
} catch(IOException e2) {}
} }
} }
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
*/ */
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
...@@ -41,61 +41,56 @@ public class HttpContinueStackOverflow { ...@@ -41,61 +41,56 @@ public class HttpContinueStackOverflow {
static class Server implements Runnable { static class Server implements Runnable {
int port; int port;
ServerSocket serverSock ;
Server(int port) { Server() throws IOException {
this.port = port; serverSock = new ServerSocket(0);
}
int getLocalPort() {
return serverSock.getLocalPort();
} }
public void run() { public void run() {
Socket sock = null;
try { try {
/* bind to port and wait for connection */
ServerSocket serverSock = new ServerSocket( port );
serverSock.setSoTimeout(10000); serverSock.setSoTimeout(10000);
Socket sock = serverSock.accept(); sock = serverSock.accept();
/* setup streams and read http request */ /* setup streams and read http request */
BufferedReader in = new BufferedReader( BufferedReader in = new BufferedReader(
new InputStreamReader(sock.getInputStream())); new InputStreamReader(sock.getInputStream()));
PrintStream out = new PrintStream( sock.getOutputStream() ); PrintStream out = new PrintStream( sock.getOutputStream() );
String request = in.readLine(); in.readLine();
/* send continue followed by invalid response */ /* send continue followed by invalid response */
out.println("HTTP/1.1 100 Continue\r"); out.println("HTTP/1.1 100 Continue\r");
out.println("\r"); out.println("\r");
out.println("junk junk junk"); out.println("junk junk junk");
out.flush(); out.flush();
sock.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try { serverSock.close(); } catch (IOException unused) {}
try { sock.close(); } catch (IOException unused) {}
} }
} }
} }
HttpContinueStackOverflow(int port) throws Exception { HttpContinueStackOverflow() throws Exception {
/* create the server */ /* create the server */
Server s = new Server(port); Server s = new Server();
Thread thr = new Thread(s); (new Thread(s)).start();
thr.start();
/* wait for server to bind to port */
try {
Thread.currentThread().sleep(2000);
} catch (Exception e) { }
/* connect to server, connect to server and get response code */ /* connect to server, connect to server and get response code */
URL url = new URL("http", "localhost", port, "anything.html"); URL url = new URL("http", "localhost", s.getLocalPort(), "anything.html");
HttpURLConnection conn = (HttpURLConnection)url.openConnection(); HttpURLConnection conn = (HttpURLConnection)url.openConnection();
int respCode = conn.getResponseCode(); conn.getResponseCode();
System.out.println("TEST PASSED"); System.out.println("TEST PASSED");
} }
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
int port = 4090;
if (args.length > 0) {
port = Integer.parseInt(args[0]);
}
System.out.println("Testing 100-Continue"); System.out.println("Testing 100-Continue");
new HttpContinueStackOverflow(port); new HttpContinueStackOverflow();
} }
} }
...@@ -37,11 +37,11 @@ class RedirServer extends Thread { ...@@ -37,11 +37,11 @@ class RedirServer extends Thread {
OutputStream os; OutputStream os;
int port; int port;
String reply1 = "HTTP/1.1 307 Temporary Redirect\r\n" + String reply1Part1 = "HTTP/1.1 307 Temporary Redirect\r\n" +
"Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" + "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
"Server: Apache/1.3.14 (Unix)\r\n" + "Server: Apache/1.3.14 (Unix)\r\n" +
"Location: http://localhost:"; "Location: http://localhost:";
String reply2 = "/redirected.html\r\n" + String reply1Part2 = "/redirected.html\r\n" +
"Connection: close\r\n" + "Connection: close\r\n" +
"Content-Type: text/html; charset=iso-8859-1\r\n\r\n" + "Content-Type: text/html; charset=iso-8859-1\r\n\r\n" +
"<html>Hello</html>"; "<html>Hello</html>";
...@@ -49,9 +49,10 @@ class RedirServer extends Thread { ...@@ -49,9 +49,10 @@ class RedirServer extends Thread {
RedirServer (ServerSocket y) { RedirServer (ServerSocket y) {
s = y; s = y;
port = s.getLocalPort(); port = s.getLocalPort();
System.out.println("Server created listening on " + port);
} }
String reply3 = "HTTP/1.1 200 Ok\r\n" + String reply2 = "HTTP/1.1 200 Ok\r\n" +
"Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" + "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
"Server: Apache/1.3.14 (Unix)\r\n" + "Server: Apache/1.3.14 (Unix)\r\n" +
"Connection: close\r\n" + "Connection: close\r\n" +
...@@ -64,16 +65,24 @@ class RedirServer extends Thread { ...@@ -64,16 +65,24 @@ class RedirServer extends Thread {
is = s1.getInputStream (); is = s1.getInputStream ();
os = s1.getOutputStream (); os = s1.getOutputStream ();
is.read (); is.read ();
String reply = reply1 + port + reply2; String reply = reply1Part1 + port + reply1Part2;
os.write (reply.getBytes()); os.write (reply.getBytes());
os.close();
/* wait for redirected connection */ /* wait for redirected connection */
s.setSoTimeout (5000); s.setSoTimeout (5000);
s1 = s.accept (); s1 = s.accept ();
is = s1.getInputStream ();
os = s1.getOutputStream (); os = s1.getOutputStream ();
os.write (reply3.getBytes()); is.read();
os.write (reply2.getBytes());
os.close();
} }
catch (Exception e) { catch (Exception e) {
/* Just need thread to terminate */ /* Just need thread to terminate */
System.out.println("Server: caught " + e);
e.printStackTrace();
} finally {
try { s.close(); } catch (IOException unused) {}
} }
} }
}; };
...@@ -84,10 +93,7 @@ public class Redirect307Test { ...@@ -84,10 +93,7 @@ public class Redirect307Test {
public static final int DELAY = 10; public static final int DELAY = 10;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
int nLoops = 1; int port;
int nSize = 10;
int port, n =0;
byte b[] = new byte[nSize];
RedirServer server; RedirServer server;
ServerSocket sock; ServerSocket sock;
...@@ -119,7 +125,8 @@ public class Redirect307Test { ...@@ -119,7 +125,8 @@ public class Redirect307Test {
} }
} }
catch(IOException e) { catch(IOException e) {
throw new RuntimeException ("Exception caught"); e.printStackTrace();
throw new RuntimeException ("Exception caught + " + e);
} }
} }
} }
...@@ -76,15 +76,19 @@ class RedirLimitServer extends Thread { ...@@ -76,15 +76,19 @@ class RedirLimitServer extends Thread {
is.read (); is.read ();
String reply = reply1 + port + "/redirect" + i + reply2; String reply = reply1 + port + "/redirect" + i + reply2;
os.write (reply.getBytes()); os.write (reply.getBytes());
os.close();
} }
s1 = s.accept (); s1 = s.accept ();
is = s1.getInputStream (); is = s1.getInputStream ();
os = s1.getOutputStream (); os = s1.getOutputStream ();
is.read (); is.read ();
os.write (reply3.getBytes()); os.write (reply3.getBytes());
os.close();
} }
catch (Exception e) { catch (Exception e) {
/* Just need thread to terminate */ /* Just need thread to terminate */
} finally {
try { s.close(); } catch (IOException unused) {}
} }
} }
}; };
......
...@@ -109,8 +109,11 @@ public class ResendPostBody { ...@@ -109,8 +109,11 @@ public class ResendPostBody {
while (!finished()) { while (!finished()) {
Thread.sleep (1000); Thread.sleep (1000);
} }
out.close();
} catch (Exception e) { } catch (Exception e) {
System.err.println ("Server Exception: " + e); System.err.println ("Server Exception: " + e);
} finally {
try { server.close(); } catch (IOException unused) {}
} }
} }
} }
...@@ -134,7 +137,7 @@ public class ResendPostBody { ...@@ -134,7 +137,7 @@ public class ResendPostBody {
public void execute () throws Exception { public void execute () throws Exception {
byte b[] = "X=ABCDEFGHZZZ".getBytes(); byte b[] = "X=ABCDEFGHZZZ".getBytes();
ss = new ServerSocket (0); ss = new ServerSocket (0);
server = new Server (ss); server = new Server (ss);
...@@ -163,8 +166,9 @@ public class ResendPostBody { ...@@ -163,8 +166,9 @@ public class ResendPostBody {
/* Read the response */ /* Read the response */
int resp = conURL.getResponseCode (); int resp = conURL.getResponseCode ();
server.setFinished (true);
if (resp != 200) if (resp != 200)
throw new RuntimeException ("Response code was not 200: " + resp); throw new RuntimeException ("Response code was not 200: " + resp);
server.setFinished (true);
} }
} }
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* @test /* @test
* @bug 4397096 * @bug 4397096
* @run main SetIfModifiedSince * @run main/othervm SetIfModifiedSince
* @summary setIfModifiedSince() of HttpURLConnection sets invalid date of default locale * @summary setIfModifiedSince() of HttpURLConnection sets invalid date of default locale
*/ */
......
...@@ -43,8 +43,9 @@ public class TimeoutTest { ...@@ -43,8 +43,9 @@ public class TimeoutTest {
try { try {
Socket s = server.accept (); Socket s = server.accept ();
while (!finished ()) { while (!finished ()) {
Thread.sleep (2000); Thread.sleep (1000);
} }
s.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
...@@ -70,9 +71,12 @@ public class TimeoutTest { ...@@ -70,9 +71,12 @@ public class TimeoutTest {
URL url = new URL ("http://127.0.0.1:"+ss.getLocalPort()); URL url = new URL ("http://127.0.0.1:"+ss.getLocalPort());
URLConnection urlc = url.openConnection (); URLConnection urlc = url.openConnection ();
InputStream is = urlc.getInputStream (); InputStream is = urlc.getInputStream ();
throw new RuntimeException("Should have received timeout");
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
s.done ();
return; return;
} finally {
s.done();
ss.close();
} }
} }
} }
...@@ -70,8 +70,10 @@ public class URLConnectionHeaders { ...@@ -70,8 +70,10 @@ public class URLConnectionHeaders {
w.newLine(); w.newLine();
w.flush(); w.flush();
s.close (); s.close ();
srv.close (); // or else the HTTPURLConnection will retry } catch (IOException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace();} } finally {
try { srv.close(); } catch (IOException unused) {}
}
} }
} }
......
...@@ -58,6 +58,14 @@ public class ZeroContentLength { ...@@ -58,6 +58,14 @@ public class ZeroContentLength {
contentLength = cl; contentLength = cl;
} }
static synchronized String getResponse() {
return response;
}
static synchronized int getContentLength() {
return contentLength;
}
/* /*
* Worker thread to service single connection - can service * Worker thread to service single connection - can service
* multiple http requests on same connection. * multiple http requests on same connection.
...@@ -71,25 +79,44 @@ public class ZeroContentLength { ...@@ -71,25 +79,44 @@ public class ZeroContentLength {
this.id = id; this.id = id;
} }
final int CR = '\r';
final int LF = '\n';
public void run() { public void run() {
try { try {
s.setSoTimeout(2000); s.setSoTimeout(2000);
int max = 100; int max = 20; // there should only be 20 connections
InputStream in = new BufferedInputStream(s.getInputStream());
for (;;) { for (;;) {
// read entire request from client, until CR LF CR LF
// read entire request from client int c, total=0;
byte b[] = new byte[100];
InputStream in = s.getInputStream();
int n, total=0;
try { try {
do { while ((c = in.read()) > 0) {
n = in.read(b); total++;
if (n > 0) total += n; if (c == CR) {
} while (n > 0); if ((c = in.read()) > 0) {
} catch (SocketTimeoutException e) { } total++;
if (c == LF) {
if ((c = in.read()) > 0) {
total++;
if (c == CR) {
if ((c = in.read()) > 0) {
total++;
if (c == LF) {
break;
}
}
}
}
}
}
}
}
} catch (SocketTimeoutException e) {}
debug("worker " + id + debug("worker " + id +
": Read request from client " + ": Read request from client " +
...@@ -105,19 +132,20 @@ public class ZeroContentLength { ...@@ -105,19 +132,20 @@ public class ZeroContentLength {
new BufferedOutputStream( new BufferedOutputStream(
s.getOutputStream() )); s.getOutputStream() ));
out.print("HTTP/1.1 " + response + "\r\n"); out.print("HTTP/1.1 " + getResponse() + "\r\n");
if (contentLength >= 0) { int clen = getContentLength();
out.print("Content-Length: " + contentLength + if (clen >= 0) {
out.print("Content-Length: " + clen +
"\r\n"); "\r\n");
} }
out.print("\r\n"); out.print("\r\n");
for (int i=0; i<contentLength; i++) { for (int i=0; i<clen; i++) {
out.write( (byte)'.' ); out.write( (byte)'.' );
} }
out.flush(); out.flush();
debug("worked " + id + debug("worked " + id +
": Sent response to client, length: " + contentLength); ": Sent response to client, length: " + clen);
if (--max == 0) { if (--max == 0) {
s.close(); s.close();
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册