mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
Merge
This commit is contained in:
commit
ca8b59370b
242 changed files with 5083 additions and 2356 deletions
|
@ -2602,7 +2602,7 @@ public final class String
|
|||
* Returns a string whose value is this string, with all leading
|
||||
* and trailing space removed, where space is defined
|
||||
* as any character whose codepoint is less than or equal to
|
||||
* {@code '\u005Cu0020'} (the space character).
|
||||
* {@code 'U+0020'} (the space character).
|
||||
* <p>
|
||||
* If this {@code String} object represents an empty character
|
||||
* sequence, or the first and last characters of character sequence
|
||||
|
@ -2636,6 +2636,98 @@ public final class String
|
|||
return ret == null ? this : ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string whose value is this string, with all leading
|
||||
* and trailing {@link Character#isWhitespace(int) white space}
|
||||
* removed.
|
||||
* <p>
|
||||
* If this {@code String} object represents an empty string,
|
||||
* or if all code points in this string are
|
||||
* {@link Character#isWhitespace(int) white space}, then an empty string
|
||||
* is returned.
|
||||
* <p>
|
||||
* Otherwise, returns a substring of this string beginning with the first
|
||||
* code point that is not a {@link Character#isWhitespace(int) white space}
|
||||
* up to and including the last code point that is not a
|
||||
* {@link Character#isWhitespace(int) white space}.
|
||||
* <p>
|
||||
* This method may be used to strip
|
||||
* {@link Character#isWhitespace(int) white space} from
|
||||
* the beginning and end of a string.
|
||||
*
|
||||
* @return a string whose value is this string, with all leading
|
||||
* and trailing white space removed
|
||||
*
|
||||
* @see Character#isWhitespace(int)
|
||||
*
|
||||
* @since 11
|
||||
*/
|
||||
public String strip() {
|
||||
String ret = isLatin1() ? StringLatin1.strip(value)
|
||||
: StringUTF16.strip(value);
|
||||
return ret == null ? this : ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string whose value is this string, with all leading
|
||||
* {@link Character#isWhitespace(int) white space} removed.
|
||||
* <p>
|
||||
* If this {@code String} object represents an empty string,
|
||||
* or if all code points in this string are
|
||||
* {@link Character#isWhitespace(int) white space}, then an empty string
|
||||
* is returned.
|
||||
* <p>
|
||||
* Otherwise, returns a substring of this string beginning with the first
|
||||
* code point that is not a {@link Character#isWhitespace(int) white space}
|
||||
* up to to and including the last code point of this string.
|
||||
* <p>
|
||||
* This method may be used to trim
|
||||
* {@link Character#isWhitespace(int) white space} from
|
||||
* the beginning of a string.
|
||||
*
|
||||
* @return a string whose value is this string, with all leading white
|
||||
* space removed
|
||||
*
|
||||
* @see Character#isWhitespace(int)
|
||||
*
|
||||
* @since 11
|
||||
*/
|
||||
public String stripLeading() {
|
||||
String ret = isLatin1() ? StringLatin1.stripLeading(value)
|
||||
: StringUTF16.stripLeading(value);
|
||||
return ret == null ? this : ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string whose value is this string, with all trailing
|
||||
* {@link Character#isWhitespace(int) white space} removed.
|
||||
* <p>
|
||||
* If this {@code String} object represents an empty string,
|
||||
* or if all characters in this string are
|
||||
* {@link Character#isWhitespace(int) white space}, then an empty string
|
||||
* is returned.
|
||||
* <p>
|
||||
* Otherwise, returns a substring of this string beginning with the first
|
||||
* code point of this string up to and including the last code point
|
||||
* that is not a {@link Character#isWhitespace(int) white space}.
|
||||
* <p>
|
||||
* This method may be used to trim
|
||||
* {@link Character#isWhitespace(int) white space} from
|
||||
* the end of a string.
|
||||
*
|
||||
* @return a string whose value is this string, with all trailing white
|
||||
* space removed
|
||||
*
|
||||
* @see Character#isWhitespace(int)
|
||||
*
|
||||
* @since 11
|
||||
*/
|
||||
public String stripTrailing() {
|
||||
String ret = isLatin1() ? StringLatin1.stripTrailing(value)
|
||||
: StringUTF16.stripTrailing(value);
|
||||
return ret == null ? this : ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* This object (which is already a string!) is itself returned.
|
||||
*
|
||||
|
|
|
@ -538,6 +538,57 @@ final class StringLatin1 {
|
|||
newString(value, st, len - st) : null;
|
||||
}
|
||||
|
||||
public static int indexOfNonWhitespace(byte[] value) {
|
||||
int length = value.length;
|
||||
int left = 0;
|
||||
while (left < length) {
|
||||
char ch = (char)(value[left] & 0xff);
|
||||
if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
|
||||
break;
|
||||
}
|
||||
left++;
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
public static int lastIndexOfNonWhitespace(byte[] value) {
|
||||
int length = value.length;
|
||||
int right = length;
|
||||
while (0 < right) {
|
||||
char ch = (char)(value[right - 1] & 0xff);
|
||||
if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
|
||||
break;
|
||||
}
|
||||
right--;
|
||||
}
|
||||
return right;
|
||||
}
|
||||
|
||||
public static String strip(byte[] value) {
|
||||
int left = indexOfNonWhitespace(value);
|
||||
if (left == value.length) {
|
||||
return "";
|
||||
}
|
||||
int right = lastIndexOfNonWhitespace(value);
|
||||
return ((left > 0) || (right < value.length)) ? newString(value, left, right - left) : null;
|
||||
}
|
||||
|
||||
public static String stripLeading(byte[] value) {
|
||||
int left = indexOfNonWhitespace(value);
|
||||
if (left == value.length) {
|
||||
return "";
|
||||
}
|
||||
return (left != 0) ? newString(value, left, value.length - left) : null;
|
||||
}
|
||||
|
||||
public static String stripTrailing(byte[] value) {
|
||||
int right = lastIndexOfNonWhitespace(value);
|
||||
if (right == 0) {
|
||||
return "";
|
||||
}
|
||||
return (right != value.length) ? newString(value, 0, right) : null;
|
||||
}
|
||||
|
||||
public static void putChar(byte[] val, int index, int c) {
|
||||
//assert (canEncode(c));
|
||||
val[index] = (byte)(c);
|
||||
|
|
|
@ -856,6 +856,61 @@ final class StringUTF16 {
|
|||
null;
|
||||
}
|
||||
|
||||
|
||||
public static int indexOfNonWhitespace(byte[] value) {
|
||||
int length = value.length >> 1;
|
||||
int left = 0;
|
||||
while (left < length) {
|
||||
int codepoint = codePointAt(value, left, length);
|
||||
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
|
||||
break;
|
||||
}
|
||||
left += Character.charCount(codepoint);
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
public static int lastIndexOfNonWhitespace(byte[] value) {
|
||||
int length = value.length >> 1;
|
||||
int right = length;
|
||||
while (0 < right) {
|
||||
int codepoint = codePointBefore(value, right);
|
||||
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
|
||||
break;
|
||||
}
|
||||
right -= Character.charCount(codepoint);
|
||||
}
|
||||
return right;
|
||||
}
|
||||
|
||||
public static String strip(byte[] value) {
|
||||
int length = value.length >> 1;
|
||||
int left = indexOfNonWhitespace(value);
|
||||
if (left == length) {
|
||||
return "";
|
||||
}
|
||||
int right = lastIndexOfNonWhitespace(value);
|
||||
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
|
||||
}
|
||||
|
||||
public static String stripLeading(byte[] value) {
|
||||
int length = value.length >> 1;
|
||||
int left = indexOfNonWhitespace(value);
|
||||
if (left == length) {
|
||||
return "";
|
||||
}
|
||||
return (left != 0) ? newString(value, left, length - left) : null;
|
||||
}
|
||||
|
||||
public static String stripTrailing(byte[] value) {
|
||||
int length = value.length >> 1;
|
||||
int right = lastIndexOfNonWhitespace(value);
|
||||
if (right == 0) {
|
||||
return "";
|
||||
}
|
||||
return (right != length) ? newString(value, 0, right) : null;
|
||||
}
|
||||
|
||||
private static void putChars(byte[] val, int index, char[] str, int off, int end) {
|
||||
while (off < end) {
|
||||
putChar(val, index++, str[off++]);
|
||||
|
|
|
@ -564,7 +564,6 @@ public class AccessibleObject implements AnnotatedElement {
|
|||
throw new AssertionError("All subclasses should override this method");
|
||||
}
|
||||
|
||||
|
||||
// Shared access checking logic.
|
||||
|
||||
// For non-public members or members in package-private classes,
|
||||
|
@ -674,4 +673,13 @@ public class AccessibleObject implements AnnotatedElement {
|
|||
}
|
||||
return printStackWhenAccessFails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root AccessibleObject; or null if this object is the root.
|
||||
*
|
||||
* All subclasses override this method.
|
||||
*/
|
||||
AccessibleObject getRoot() {
|
||||
throw new InternalError();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,11 +103,8 @@ public final class Constructor<T> extends Executable {
|
|||
// occur in annotation code.
|
||||
private Constructor<T> root;
|
||||
|
||||
/**
|
||||
* Used by Excecutable for annotation sharing.
|
||||
*/
|
||||
@Override
|
||||
Executable getRoot() {
|
||||
Constructor<T> getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,11 +55,6 @@ public abstract class Executable extends AccessibleObject
|
|||
*/
|
||||
abstract byte[] getAnnotationBytes();
|
||||
|
||||
/**
|
||||
* Accessor method to allow code sharing
|
||||
*/
|
||||
abstract Executable getRoot();
|
||||
|
||||
/**
|
||||
* Does the Executable have generic information.
|
||||
*/
|
||||
|
@ -602,7 +597,7 @@ public abstract class Executable extends AccessibleObject
|
|||
if ((declAnnos = declaredAnnotations) == null) {
|
||||
synchronized (this) {
|
||||
if ((declAnnos = declaredAnnotations) == null) {
|
||||
Executable root = getRoot();
|
||||
Executable root = (Executable)getRoot();
|
||||
if (root != null) {
|
||||
declAnnos = root.declaredAnnotations();
|
||||
} else {
|
||||
|
|
|
@ -1128,6 +1128,11 @@ class Field extends AccessibleObject implements Member {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
Field getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NullPointerException {@inheritDoc}
|
||||
* @since 1.5
|
||||
|
|
|
@ -198,11 +198,8 @@ public final class Method extends Executable {
|
|||
checkCanSetAccessible(caller, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by Excecutable for annotation sharing.
|
||||
*/
|
||||
@Override
|
||||
Executable getRoot() {
|
||||
Method getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
|
@ -154,4 +154,9 @@ class ReflectAccess implements jdk.internal.reflect.LangReflectAccess {
|
|||
public <T> Constructor<T> copyConstructor(Constructor<T> arg) {
|
||||
return arg.copy();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends AccessibleObject> T getRoot(T obj) {
|
||||
return (T) obj.getRoot();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,19 +52,17 @@ import jdk.internal.HotSpotIntrinsicCandidate;
|
|||
* and a few other miscellaneous operations.
|
||||
*
|
||||
* <p>Semantics of arithmetic operations exactly mimic those of Java's integer
|
||||
* arithmetic operators, as defined in <i>The Java Language Specification</i>.
|
||||
* arithmetic operators, as defined in <i>The Java™ Language Specification</i>.
|
||||
* For example, division by zero throws an {@code ArithmeticException}, and
|
||||
* division of a negative by a positive yields a negative (or zero) remainder.
|
||||
* All of the details in the Spec concerning overflow are ignored, as
|
||||
* BigIntegers are made as large as necessary to accommodate the results of an
|
||||
* operation.
|
||||
*
|
||||
* <p>Semantics of shift operations extend those of Java's shift operators
|
||||
* to allow for negative shift distances. A right-shift with a negative
|
||||
* shift distance results in a left shift, and vice-versa. The unsigned
|
||||
* right shift operator ({@code >>>}) is omitted, as this operation makes
|
||||
* little sense in combination with the "infinite word size" abstraction
|
||||
* provided by this class.
|
||||
* right shift operator ({@code >>>}) is omitted since this operation
|
||||
* only makes sense for a fixed sized word and not for a
|
||||
* representation conceptually having an infinite number of leading
|
||||
* virtual sign bits.
|
||||
*
|
||||
* <p>Semantics of bitwise logical operations exactly mimic those of Java's
|
||||
* bitwise integer operators. The binary operators ({@code and},
|
||||
|
@ -84,8 +82,8 @@ import jdk.internal.HotSpotIntrinsicCandidate;
|
|||
* extended so that it contains the designated bit. None of the single-bit
|
||||
* operations can produce a BigInteger with a different sign from the
|
||||
* BigInteger being operated on, as they affect only a single bit, and the
|
||||
* "infinite word size" abstraction provided by this class ensures that there
|
||||
* are infinitely many "virtual sign bits" preceding each BigInteger.
|
||||
* arbitrarily large abstraction provided by this class ensures that conceptually
|
||||
* there are infinitely many "virtual sign bits" preceding each BigInteger.
|
||||
*
|
||||
* <p>For the sake of brevity and clarity, pseudo-code is used throughout the
|
||||
* descriptions of BigInteger methods. The pseudo-code expression
|
||||
|
@ -105,13 +103,18 @@ import jdk.internal.HotSpotIntrinsicCandidate;
|
|||
* +2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive)
|
||||
* and may support values outside of that range.
|
||||
*
|
||||
* An {@code ArithmeticException} is thrown when a BigInteger
|
||||
* constructor or method would generate a value outside of the
|
||||
* supported range.
|
||||
*
|
||||
* The range of probable prime values is limited and may be less than
|
||||
* the full supported positive range of {@code BigInteger}.
|
||||
* The range must be at least 1 to 2<sup>500000000</sup>.
|
||||
*
|
||||
* @implNote
|
||||
* BigInteger constructors and operations throw {@code ArithmeticException} when
|
||||
* the result is out of the supported range of
|
||||
* In the reference implementation, BigInteger constructors and
|
||||
* operations throw {@code ArithmeticException} when the result is out
|
||||
* of the supported range of
|
||||
* -2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive) to
|
||||
* +2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive).
|
||||
*
|
||||
|
|
|
@ -35,16 +35,16 @@ import java.util.function.Supplier;
|
|||
* on objects, or checking certain conditions before operation. These utilities
|
||||
* include {@code null}-safe or {@code null}-tolerant methods for computing the
|
||||
* hash code of an object, returning a string for an object, comparing two
|
||||
* objects, and checking if indexes or sub-range values are out-of-bounds.
|
||||
* objects, and checking if indexes or sub-range values are out of bounds.
|
||||
*
|
||||
* @apiNote
|
||||
* Static methods such as {@link Objects#checkIndex},
|
||||
* {@link Objects#checkFromToIndex}, and {@link Objects#checkFromIndexSize} are
|
||||
* provided for the convenience of checking if values corresponding to indexes
|
||||
* and sub-ranges are out-of-bounds.
|
||||
* and sub-ranges are out of bounds.
|
||||
* Variations of these static methods support customization of the runtime
|
||||
* exception, and corresponding exception detail message, that is thrown when
|
||||
* values are out-of-bounds. Such methods accept a functional interface
|
||||
* values are out of bounds. Such methods accept a functional interface
|
||||
* argument, instances of {@code BiFunction}, that maps out-of-bound values to a
|
||||
* runtime exception. Care should be taken when using such methods in
|
||||
* combination with an argument that is a lambda expression, method reference or
|
||||
|
@ -352,7 +352,7 @@ public final class Objects {
|
|||
* Checks if the {@code index} is within the bounds of the range from
|
||||
* {@code 0} (inclusive) to {@code length} (exclusive).
|
||||
*
|
||||
* <p>The {@code index} is defined to be out-of-bounds if any of the
|
||||
* <p>The {@code index} is defined to be out of bounds if any of the
|
||||
* following inequalities is true:
|
||||
* <ul>
|
||||
* <li>{@code index < 0}</li>
|
||||
|
@ -363,7 +363,7 @@ public final class Objects {
|
|||
* @param index the index
|
||||
* @param length the upper-bound (exclusive) of the range
|
||||
* @return {@code index} if it is within bounds of the range
|
||||
* @throws IndexOutOfBoundsException if the {@code index} is out-of-bounds
|
||||
* @throws IndexOutOfBoundsException if the {@code index} is out of bounds
|
||||
* @since 9
|
||||
*/
|
||||
@ForceInline
|
||||
|
@ -377,7 +377,7 @@ public final class Objects {
|
|||
* {@code toIndex} (exclusive) is within the bounds of range from {@code 0}
|
||||
* (inclusive) to {@code length} (exclusive).
|
||||
*
|
||||
* <p>The sub-range is defined to be out-of-bounds if any of the following
|
||||
* <p>The sub-range is defined to be out of bounds if any of the following
|
||||
* inequalities is true:
|
||||
* <ul>
|
||||
* <li>{@code fromIndex < 0}</li>
|
||||
|
@ -390,7 +390,7 @@ public final class Objects {
|
|||
* @param toIndex the upper-bound (exclusive) of the sub-range
|
||||
* @param length the upper-bound (exclusive) the range
|
||||
* @return {@code fromIndex} if the sub-range within bounds of the range
|
||||
* @throws IndexOutOfBoundsException if the sub-range is out-of-bounds
|
||||
* @throws IndexOutOfBoundsException if the sub-range is out of bounds
|
||||
* @since 9
|
||||
*/
|
||||
public static
|
||||
|
@ -403,7 +403,7 @@ public final class Objects {
|
|||
* {@code fromIndex + size} (exclusive) is within the bounds of range from
|
||||
* {@code 0} (inclusive) to {@code length} (exclusive).
|
||||
*
|
||||
* <p>The sub-range is defined to be out-of-bounds if any of the following
|
||||
* <p>The sub-range is defined to be out of bounds if any of the following
|
||||
* inequalities is true:
|
||||
* <ul>
|
||||
* <li>{@code fromIndex < 0}</li>
|
||||
|
@ -416,7 +416,7 @@ public final class Objects {
|
|||
* @param size the size of the sub-range
|
||||
* @param length the upper-bound (exclusive) of the range
|
||||
* @return {@code fromIndex} if the sub-range within bounds of the range
|
||||
* @throws IndexOutOfBoundsException if the sub-range is out-of-bounds
|
||||
* @throws IndexOutOfBoundsException if the sub-range is out of bounds
|
||||
* @since 9
|
||||
*/
|
||||
public static
|
||||
|
|
|
@ -115,4 +115,7 @@ public interface LangReflectAccess {
|
|||
|
||||
/** Makes a "child" copy of a Constructor */
|
||||
public <T> Constructor<T> copyConstructor(Constructor<T> arg);
|
||||
|
||||
/** Gets the root of the given AccessibleObject object; null if arg is the root */
|
||||
public <T extends AccessibleObject> T getRoot(T obj);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.Permission;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
@ -172,6 +171,15 @@ public class ReflectionFactory {
|
|||
*/
|
||||
public FieldAccessor newFieldAccessor(Field field, boolean override) {
|
||||
checkInitted();
|
||||
|
||||
Field root = langReflectAccess.getRoot(field);
|
||||
if (root != null) {
|
||||
// FieldAccessor will use the root unless the modifiers have
|
||||
// been overrridden
|
||||
if (root.getModifiers() == field.getModifiers() || !override) {
|
||||
field = root;
|
||||
}
|
||||
}
|
||||
return UnsafeFieldAccessorFactory.newFieldAccessor(field, override);
|
||||
}
|
||||
|
||||
|
@ -185,6 +193,12 @@ public class ReflectionFactory {
|
|||
}
|
||||
}
|
||||
|
||||
// use the root Method that will not cache caller class
|
||||
Method root = langReflectAccess.getRoot(method);
|
||||
if (root != null) {
|
||||
method = root;
|
||||
}
|
||||
|
||||
if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
|
||||
return new MethodAccessorGenerator().
|
||||
generateMethod(method.getDeclaringClass(),
|
||||
|
@ -214,6 +228,13 @@ public class ReflectionFactory {
|
|||
return new InstantiationExceptionConstructorAccessorImpl
|
||||
("Can not instantiate java.lang.Class");
|
||||
}
|
||||
|
||||
// use the root Constructor that will not cache caller class
|
||||
Constructor<?> root = langReflectAccess.getRoot(c);
|
||||
if (root != null) {
|
||||
c = root;
|
||||
}
|
||||
|
||||
// Bootstrapping issue: since we use Class.newInstance() in
|
||||
// the ConstructorAccessor generation process, we have to
|
||||
// break the cycle here.
|
||||
|
|
|
@ -185,13 +185,13 @@ public class Preconditions {
|
|||
// Switch to default if fewer or more arguments than required are supplied
|
||||
switch ((args.size() != argSize) ? "" : checkKind) {
|
||||
case "checkIndex":
|
||||
return String.format("Index %d out-of-bounds for length %d",
|
||||
return String.format("Index %d out of bounds for length %d",
|
||||
args.get(0), args.get(1));
|
||||
case "checkFromToIndex":
|
||||
return String.format("Range [%d, %d) out-of-bounds for length %d",
|
||||
return String.format("Range [%d, %d) out of bounds for length %d",
|
||||
args.get(0), args.get(1), args.get(2));
|
||||
case "checkFromIndexSize":
|
||||
return String.format("Range [%d, %<d + %d) out-of-bounds for length %d",
|
||||
return String.format("Range [%d, %<d + %d) out of bounds for length %d",
|
||||
args.get(0), args.get(1), args.get(2));
|
||||
default:
|
||||
return String.format("Range check failed: %s %s", checkKind, args);
|
||||
|
@ -202,7 +202,7 @@ public class Preconditions {
|
|||
* Checks if the {@code index} is within the bounds of the range from
|
||||
* {@code 0} (inclusive) to {@code length} (exclusive).
|
||||
*
|
||||
* <p>The {@code index} is defined to be out-of-bounds if any of the
|
||||
* <p>The {@code index} is defined to be out of bounds if any of the
|
||||
* following inequalities is true:
|
||||
* <ul>
|
||||
* <li>{@code index < 0}</li>
|
||||
|
@ -210,14 +210,14 @@ public class Preconditions {
|
|||
* <li>{@code length < 0}, which is implied from the former inequalities</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>If the {@code index} is out-of-bounds, then a runtime exception is
|
||||
* <p>If the {@code index} is out of bounds, then a runtime exception is
|
||||
* thrown that is the result of applying the following arguments to the
|
||||
* exception formatter: the name of this method, {@code checkIndex};
|
||||
* and an unmodifiable list integers whose values are, in order, the
|
||||
* out-of-bounds arguments {@code index} and {@code length}.
|
||||
*
|
||||
* @param <X> the type of runtime exception to throw if the arguments are
|
||||
* out-of-bounds
|
||||
* out of bounds
|
||||
* @param index the index
|
||||
* @param length the upper-bound (exclusive) of the range
|
||||
* @param oobef the exception formatter that when applied with this
|
||||
|
@ -228,9 +228,9 @@ public class Preconditions {
|
|||
* instead (though it may be more efficient).
|
||||
* Exceptions thrown by the formatter are relayed to the caller.
|
||||
* @return {@code index} if it is within bounds of the range
|
||||
* @throws X if the {@code index} is out-of-bounds and the exception
|
||||
* @throws X if the {@code index} is out of bounds and the exception
|
||||
* formatter is non-{@code null}
|
||||
* @throws IndexOutOfBoundsException if the {@code index} is out-of-bounds
|
||||
* @throws IndexOutOfBoundsException if the {@code index} is out of bounds
|
||||
* and the exception formatter is {@code null}
|
||||
* @since 9
|
||||
*
|
||||
|
@ -254,7 +254,7 @@ public class Preconditions {
|
|||
* {@code toIndex} (exclusive) is within the bounds of range from {@code 0}
|
||||
* (inclusive) to {@code length} (exclusive).
|
||||
*
|
||||
* <p>The sub-range is defined to be out-of-bounds if any of the following
|
||||
* <p>The sub-range is defined to be out of bounds if any of the following
|
||||
* inequalities is true:
|
||||
* <ul>
|
||||
* <li>{@code fromIndex < 0}</li>
|
||||
|
@ -263,14 +263,14 @@ public class Preconditions {
|
|||
* <li>{@code length < 0}, which is implied from the former inequalities</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>If the sub-range is out-of-bounds, then a runtime exception is
|
||||
* <p>If the sub-range is out of bounds, then a runtime exception is
|
||||
* thrown that is the result of applying the following arguments to the
|
||||
* exception formatter: the name of this method, {@code checkFromToIndex};
|
||||
* and an unmodifiable list integers whose values are, in order, the
|
||||
* out-of-bounds arguments {@code fromIndex}, {@code toIndex}, and {@code length}.
|
||||
*
|
||||
* @param <X> the type of runtime exception to throw if the arguments are
|
||||
* out-of-bounds
|
||||
* out of bounds
|
||||
* @param fromIndex the lower-bound (inclusive) of the sub-range
|
||||
* @param toIndex the upper-bound (exclusive) of the sub-range
|
||||
* @param length the upper-bound (exclusive) the range
|
||||
|
@ -282,9 +282,9 @@ public class Preconditions {
|
|||
* instead (though it may be more efficient).
|
||||
* Exceptions thrown by the formatter are relayed to the caller.
|
||||
* @return {@code fromIndex} if the sub-range within bounds of the range
|
||||
* @throws X if the sub-range is out-of-bounds and the exception factory
|
||||
* @throws X if the sub-range is out of bounds and the exception factory
|
||||
* function is non-{@code null}
|
||||
* @throws IndexOutOfBoundsException if the sub-range is out-of-bounds and
|
||||
* @throws IndexOutOfBoundsException if the sub-range is out of bounds and
|
||||
* the exception factory function is {@code null}
|
||||
* @since 9
|
||||
*/
|
||||
|
@ -301,7 +301,7 @@ public class Preconditions {
|
|||
* {@code fromIndex + size} (exclusive) is within the bounds of range from
|
||||
* {@code 0} (inclusive) to {@code length} (exclusive).
|
||||
*
|
||||
* <p>The sub-range is defined to be out-of-bounds if any of the following
|
||||
* <p>The sub-range is defined to be out of bounds if any of the following
|
||||
* inequalities is true:
|
||||
* <ul>
|
||||
* <li>{@code fromIndex < 0}</li>
|
||||
|
@ -310,7 +310,7 @@ public class Preconditions {
|
|||
* <li>{@code length < 0}, which is implied from the former inequalities</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>If the sub-range is out-of-bounds, then a runtime exception is
|
||||
* <p>If the sub-range is out of bounds, then a runtime exception is
|
||||
* thrown that is the result of applying the following arguments to the
|
||||
* exception formatter: the name of this method, {@code checkFromIndexSize};
|
||||
* and an unmodifiable list integers whose values are, in order, the
|
||||
|
@ -318,7 +318,7 @@ public class Preconditions {
|
|||
* {@code length}.
|
||||
*
|
||||
* @param <X> the type of runtime exception to throw if the arguments are
|
||||
* out-of-bounds
|
||||
* out of bounds
|
||||
* @param fromIndex the lower-bound (inclusive) of the sub-interval
|
||||
* @param size the size of the sub-range
|
||||
* @param length the upper-bound (exclusive) of the range
|
||||
|
@ -330,9 +330,9 @@ public class Preconditions {
|
|||
* instead (though it may be more efficient).
|
||||
* Exceptions thrown by the formatter are relayed to the caller.
|
||||
* @return {@code fromIndex} if the sub-range within bounds of the range
|
||||
* @throws X if the sub-range is out-of-bounds and the exception factory
|
||||
* @throws X if the sub-range is out of bounds and the exception factory
|
||||
* function is non-{@code null}
|
||||
* @throws IndexOutOfBoundsException if the sub-range is out-of-bounds and
|
||||
* @throws IndexOutOfBoundsException if the sub-range is out of bounds and
|
||||
* the exception factory function is {@code null}
|
||||
* @since 9
|
||||
*/
|
||||
|
|
|
@ -867,11 +867,22 @@ class SocketChannelImpl
|
|||
// set state to ST_KILLPENDING
|
||||
synchronized (stateLock) {
|
||||
assert state == ST_CLOSING;
|
||||
// if connected, and the channel is registered with a Selector, we
|
||||
// shutdown the output so that the peer reads EOF
|
||||
// if connected and the channel is registered with a Selector then
|
||||
// shutdown the output if possible so that the peer reads EOF. If
|
||||
// SO_LINGER is enabled and set to a non-zero value then it needs to
|
||||
// be disabled so that the Selector does not wait when it closes
|
||||
// the socket.
|
||||
if (connected && isRegistered()) {
|
||||
try {
|
||||
Net.shutdown(fd, Net.SHUT_WR);
|
||||
SocketOption<Integer> opt = StandardSocketOptions.SO_LINGER;
|
||||
int interval = (int) Net.getSocketOption(fd, Net.UNSPEC, opt);
|
||||
if (interval != 0) {
|
||||
if (interval > 0) {
|
||||
// disable SO_LINGER
|
||||
Net.setSocketOption(fd, Net.UNSPEC, opt, -1);
|
||||
}
|
||||
Net.shutdown(fd, Net.SHUT_WR);
|
||||
}
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
state = ST_KILLPENDING;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue