--- a/jdk/make/com/oracle/Makefile Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/make/com/oracle/Makefile Tue Jan 31 19:08:36 2012 -0800
@@ -38,8 +38,14 @@
endif
endif
+JFR =
+ifndef OPENJDK
+ifndef JAVASE_EMBEDDED
+ JFR = jfr
+endif
+endif
-SUBDIRS = net nio util $(UCRYPTO)
+SUBDIRS = $(JFR) net nio util $(UCRYPTO)
include $(BUILDDIR)/common/Subdirs.gmk
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/make/com/oracle/jfr/Makefile Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,73 @@
+#
+# Copyright (c) 2011, 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. Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+BUILDDIR = ../../..
+PACKAGE = oracle.jrockit.jfr
+LIBRARY = jfr
+PRODUCT = oracle
+include $(BUILDDIR)/common/Defs.gmk
+
+#
+# Use mapfile
+#
+FILES_m = $(CLOSED_SHARE_SRC)/native/oracle/jfr/mapfile-vers
+include $(BUILDDIR)/common/Mapfile-vers.gmk
+
+#
+# Files to compile
+#
+FILES_c = VMJFR.c
+
+AUTO_FILES_JAVA_DIRS = com/oracle/jrockit/jfr oracle/jrockit/jfr
+
+# Find C source files
+#
+vpath %.c $(CLOSED_SHARE_SRC)/native/oracle/jfr
+
+#
+# Library to compile.
+#
+include $(BUILDDIR)/common/Library.gmk
+
+JVMLIB =
+JAVALIB =
+OTHER_LDLIBS =
+
+clean clobber::
+ $(RM) -r $(CLASSDESTDIR)/com/oracle/jrockit/jfr
+ $(RM) -r $(CLASSDESTDIR)/oracle/jrockit/jfr
+
+
+# Copy pre-shipped .jfs files
+JFR_LIBDIR = $(LIBDIR)/jfr
+JFR_SRCDIR = $(CLOSED_SHARE_SRC)/lib/jfr
+
+$(JFR_LIBDIR)/%.jfs: $(JFR_SRCDIR)/%.jfs
+ $(install-file)
+
+JFS_FILES := $(subst $(JFR_SRCDIR),$(JFR_LIBDIR),$(wildcard $(JFR_SRCDIR)/*.jfs))
+
+all build : $(JFS_FILES)
+
--- a/jdk/make/common/Defs.gmk Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/make/common/Defs.gmk Tue Jan 31 19:08:36 2012 -0800
@@ -425,7 +425,12 @@
# namely jni.h, jvm.h, and jni_utils.h, plus their platform-specific
# relatives.
#
-VPATH.h = $(PLATFORM_SRC)/javavm/export$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/javavm/export
+VPATH0.h = $(PLATFORM_SRC)/javavm/export$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/javavm/export
+ifdef OPENJDK
+ VPATH.h = $(VPATH0.h)
+else
+ VPATH.h = $(CLOSED_SHARE_SRC)/javavm/export$(CLASSPATH_SEPARATOR)$(VPATH0.h)
+endif
vpath %.h $(VPATH.h)
#
--- a/jdk/make/common/Release.gmk Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/make/common/Release.gmk Tue Jan 31 19:08:36 2012 -0800
@@ -381,6 +381,11 @@
sun/tools/jinfo \
sun/tools/jmap
+# classes that go into jfr.jar
+JFR_CLASSES_DIRS= \
+ com/oracle/jrockit/jfr \
+ oracle/jrockit/jfr
+
# classes that go into jsse.jar
JSSE_CLASSES_DIRS = \
sun/security/provider/Sun.class \
@@ -583,6 +588,23 @@
$(ECHO) "sun/tools/jstack/" >> $@
$(ECHO) "sun/tools/jinfo/" >> $@
$(ECHO) "sun/tools/jmap/" >> $@
+ifndef OPENJDK
+ifndef JAVASE_EMBEDDED
+ $(ECHO) "com/oracle/jrockit/jfr/" >> $@
+ $(ECHO) "com/oracle/jrockit/jfr/client/" >> $@
+ $(ECHO) "com/oracle/jrockit/jfr/management/" >> $@
+ $(ECHO) "oracle/jrockit/jfr/" >> $@
+ $(ECHO) "oracle/jrockit/jfr/events/" >> $@
+ $(ECHO) "oracle/jrockit/jfr/openmbean/" >> $@
+ $(ECHO) "oracle/jrockit/jfr/parser/" >> $@
+ $(ECHO) "oracle/jrockit/jfr/settings/" >> $@
+ $(ECHO) "oracle/jrockit/jfr/tools/" >> $@
+ $(ECHO) "oracle/jrockit/jfr/util/" >> $@
+ $(ECHO) "oracle/jrockit/jfr/util/log/" >> $@
+ $(ECHO) "oracle/jrockit/jfr/util/os/" >> $@
+ $(ECHO) "oracle/jrockit/jfr/util/text/" >> $@
+endif
+endif
# File order list for rt.jar
@@ -607,6 +629,20 @@
$(MV) $@.temp $@
@($(CD) $(CLASSBINDIR) && $(java-vm-cleanup))
+# Create the jfr.jar containing Java Flight Recorder implementation
+JFR_JAR=
+ifndef OPENJDK
+ifndef JAVASE_EMBEDDED
+JFR_JAR=$(ABS_TEMPDIR)/jfr-orig.jar
+$(JFR_JAR): $(OTHER_JAR_MANIFEST_FILE)
+ $(prep-target)
+ $(CD) $(CLASSBINDIR) && \
+ $(BOOT_JAR_CMD) $(CREATE_JAR_OPTS) $(OTHER_JAR_MANIFEST_FILE) $@ \
+ $(JFR_CLASSES_DIRS) $(BOOT_JAR_JFLAGS)
+ @$(CD) $(CLASSBINDIR) && $(java-vm-cleanup)
+endif
+endif
+
# Create the rt.jar file list & non-class files list
JARSPLIT_JARFILE = $(BUILDTOOLJARDIR)/jarsplit.jar
@@ -741,7 +777,7 @@
# drive names like C:
initial-image-jre:: initial-image-jre-setup \
$(JRE_DOCFILES) \
- $(RT_JAR) $(RESOURCES_JAR) $(JSSE_JAR) \
+ $(RT_JAR) $(RESOURCES_JAR) $(JSSE_JAR) $(JFR_JAR) \
$(BUILDMETAINDEX_JARFILE)
@# Copy in bin directory
$(CD) $(OUTPUTDIR) && $(FIND) bin -depth | $(CPIO) -pdum $(JRE_IMAGE_DIR)
@@ -769,6 +805,9 @@
$(CP) $(RT_JAR) $(JRE_IMAGE_DIR)/lib/rt.jar
$(CP) $(RESOURCES_JAR) $(JRE_IMAGE_DIR)/lib/resources.jar
$(CP) $(JSSE_JAR) $(JRE_IMAGE_DIR)/lib/jsse.jar
+ifneq ($(JFR_JAR),)
+ $(CP) $(JFR_JAR) $(JRE_IMAGE_DIR)/lib/jfr.jar
+endif
@# Generate meta-index to make boot and extension class loaders lazier
$(CD) $(JRE_IMAGE_DIR)/lib && \
$(BOOT_JAVA_CMD) -jar $(BUILDMETAINDEX_JARFILE) \
--- a/jdk/make/jprt.properties Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/make/jprt.properties Tue Jan 31 19:08:36 2012 -0800
@@ -62,18 +62,32 @@
# Default jdk test targets (testset=default)
jprt.make.rule.default.test.targets= \
- ${jprt.my.test.target.set:TESTNAME=jdk_beans1}, \
+ ${jprt.my.test.target.set:TESTNAME=jdk_lang}, \
+ ${jprt.my.test.target.set:TESTNAME=jdk_math}
+
+# Default vm test targets (testset=core)
+jprt.vm.core.test.targets= \
+ ${jprt.vm.default.test.targets}
+
+# Core jdk test targets (testset=core)
+jprt.make.rule.core.test.targets= \
+ ${jprt.make.rule.default.test.targets}, \
+ ${jprt.my.test.target.set:TESTNAME=jdk_util}, \
${jprt.my.test.target.set:TESTNAME=jdk_io}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_lang}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_math}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_misc}, \
${jprt.my.test.target.set:TESTNAME=jdk_net}, \
${jprt.my.test.target.set:TESTNAME=jdk_nio1}, \
${jprt.my.test.target.set:TESTNAME=jdk_nio2}, \
${jprt.my.test.target.set:TESTNAME=jdk_nio3}, \
${jprt.my.test.target.set:TESTNAME=jdk_security1}, \
+ ${jprt.my.test.target.set:TESTNAME=jdk_security2}, \
+ ${jprt.my.test.target.set:TESTNAME=jdk_security3}, \
+ ${jprt.my.test.target.set:TESTNAME=jdk_rmi}, \
+ ${jprt.my.test.target.set:TESTNAME=jdk_management1}, \
+ ${jprt.my.test.target.set:TESTNAME=jdk_management2}, \
${jprt.my.test.target.set:TESTNAME=jdk_text}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_util}
+ ${jprt.my.test.target.set:TESTNAME=jdk_tools1}, \
+ ${jprt.my.test.target.set:TESTNAME=jdk_tools2}, \
+ ${jprt.my.test.target.set:TESTNAME=jdk_misc}
# All vm test targets (testset=all)
jprt.vm.all.test.targets= \
@@ -83,19 +97,13 @@
# All jdk test targets (testset=all)
jprt.make.rule.all.test.targets= \
- ${jprt.make.rule.default.test.targets}, \
+ ${jprt.make.rule.core.test.targets}, \
${jprt.my.test.target.set:TESTNAME=jdk_awt}, \
+ ${jprt.my.test.target.set:TESTNAME=jdk_beans1}, \
${jprt.my.test.target.set:TESTNAME=jdk_beans2}, \
${jprt.my.test.target.set:TESTNAME=jdk_beans3}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_management1}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_management2}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_rmi}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_security2}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_security3}, \
${jprt.my.test.target.set:TESTNAME=jdk_sound}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_swing}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_tools1}, \
- ${jprt.my.test.target.set:TESTNAME=jdk_tools2}
+ ${jprt.my.test.target.set:TESTNAME=jdk_swing}
# JCK test targets in test/Makefile (no windows)
jprt.my.jck.test.target.set= \
--- a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/transforms/implementations/TransformXPath2Filter.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/transforms/implementations/TransformXPath2Filter.java Tue Jan 31 19:08:36 2012 -0800
@@ -148,8 +148,8 @@
}
- input.addNodeFilter(new XPath2NodeFilter(convertNodeListToSet(unionNodes),
- convertNodeListToSet(substractNodes),convertNodeListToSet(intersectNodes)));
+ input.addNodeFilter(new XPath2NodeFilter(unionNodes, substractNodes,
+ intersectNodes));
input.setNodeSet(true);
return input;
} catch (TransformerException ex) {
@@ -170,32 +170,20 @@
throw new TransformationException("empty", ex);
}
}
- static Set<Node> convertNodeListToSet(List<NodeList> l){
- Set<Node> result=new HashSet<Node>();
-
- for (NodeList rootNodes : l) {
- int length = rootNodes.getLength();
- for (int i = 0; i < length; i++) {
- Node rootNode = rootNodes.item(i);
- result.add(rootNode);
- }
- }
- return result;
- }
}
class XPath2NodeFilter implements NodeFilter {
- boolean hasUnionNodes;
- boolean hasSubstractNodes;
- boolean hasIntersectNodes;
- XPath2NodeFilter(Set<Node> unionNodes, Set<Node> substractNodes,
- Set<Node> intersectNodes) {
- this.unionNodes=unionNodes;
- hasUnionNodes=!unionNodes.isEmpty();
- this.substractNodes=substractNodes;
- hasSubstractNodes=!substractNodes.isEmpty();
- this.intersectNodes=intersectNodes;
- hasIntersectNodes=!intersectNodes.isEmpty();
+ boolean hasUnionFilter;
+ boolean hasSubstractFilter;
+ boolean hasIntersectFilter;
+ XPath2NodeFilter(List<NodeList> unionNodes, List<NodeList> substractNodes,
+ List<NodeList> intersectNodes) {
+ hasUnionFilter=!unionNodes.isEmpty();
+ this.unionNodes=convertNodeListToSet(unionNodes);
+ hasSubstractFilter=!substractNodes.isEmpty();
+ this.substractNodes=convertNodeListToSet(substractNodes);
+ hasIntersectFilter=!intersectNodes.isEmpty();
+ this.intersectNodes=convertNodeListToSet(intersectNodes);
}
Set<Node> unionNodes;
Set<Node> substractNodes;
@@ -208,16 +196,16 @@
public int isNodeInclude(Node currentNode) {
int result=1;
- if (hasSubstractNodes && rooted(currentNode, substractNodes)) {
+ if (hasSubstractFilter && rooted(currentNode, substractNodes)) {
result = -1;
- } else if (hasIntersectNodes && !rooted(currentNode, intersectNodes)) {
+ } else if (hasIntersectFilter && !rooted(currentNode, intersectNodes)) {
result = 0;
}
//TODO OPTIMIZE
if (result==1)
return 1;
- if (hasUnionNodes) {
+ if (hasUnionFilter) {
if (rooted(currentNode, unionNodes)) {
return 1;
}
@@ -231,7 +219,7 @@
int inUnion=-1;
public int isNodeIncludeDO(Node n, int level) {
int result=1;
- if (hasSubstractNodes) {
+ if (hasSubstractFilter) {
if ((inSubstract==-1) || (level<=inSubstract)) {
if (inList(n, substractNodes)) {
inSubstract=level;
@@ -244,7 +232,7 @@
}
}
if (result!=-1){
- if (hasIntersectNodes) {
+ if (hasIntersectFilter) {
if ((inIntersect==-1) || (level<=inIntersect)) {
if (!inList(n, intersectNodes)) {
inIntersect=-1;
@@ -260,7 +248,7 @@
inUnion=-1;
if (result==1)
return 1;
- if (hasUnionNodes) {
+ if (hasUnionFilter) {
if ((inUnion==-1) && inList(n, unionNodes)) {
inUnion=level;
}
@@ -280,6 +268,9 @@
* @return if rooted bye the rootnodes
*/
static boolean rooted(Node currentNode, Set<Node> nodeList ) {
+ if (nodeList.isEmpty()) {
+ return false;
+ }
if (nodeList.contains(currentNode)) {
return true;
}
@@ -302,4 +293,17 @@
static boolean inList(Node currentNode, Set<Node> nodeList ) {
return nodeList.contains(currentNode);
}
+
+ private static Set<Node> convertNodeListToSet(List<NodeList> l){
+ Set<Node> result=new HashSet<Node>();
+
+ for (NodeList rootNodes : l) {
+ int length = rootNodes.getLength();
+ for (int i = 0; i < length; i++) {
+ Node rootNode = rootNodes.item(i);
+ result.add(rootNode);
+ }
+ }
+ return result;
+ }
}
--- a/jdk/src/share/classes/com/sun/rowset/CachedRowSetImpl.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/com/sun/rowset/CachedRowSetImpl.java Tue Jan 31 19:08:36 2012 -0800
@@ -6431,7 +6431,8 @@
* @see #setKeyColumns
*/
public int[] getKeyColumns() throws SQLException {
- return keyCols;
+ int[]keyColumns = this.keyCols;
+ return (keyColumns == null) ? null : Arrays.copyOf(keyColumns, keyColumns.length);
}
--- a/jdk/src/share/classes/com/sun/rowset/internal/BaseRow.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/com/sun/rowset/internal/BaseRow.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, 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
@@ -27,6 +27,7 @@
import java.sql.*;
import java.io.*;
+import java.util.Arrays;
/**
* The abstract base class from which the classes <code>Row</code>
@@ -65,7 +66,8 @@
* original values
*/
public Object[] getOrigRow() {
- return origVals;
+ Object[] origRow = this.origVals;
+ return (origRow == null) ? null: Arrays.copyOf(origRow, origRow.length);
}
/**
--- a/jdk/src/share/classes/com/sun/rowset/internal/WebRowSetXmlWriter.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/com/sun/rowset/internal/WebRowSetXmlWriter.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, 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
@@ -48,7 +48,7 @@
* for this field is set with the <code>java.io.Writer</code> object given
* as the second argument to the <code>writeXML</code> method.
*/
- private java.io.Writer writer;
+ private transient java.io.Writer writer;
/**
* The <code>java.util.Stack</code> object that this <code>WebRowSetXmlWriter</code>
@@ -205,16 +205,11 @@
//Changed to beginSection and endSection for maps for proper indentation
beginSection("map");
- java.util.Map<?,?> typeMap = caller.getTypeMap();
- if (typeMap != null) {
- Iterator<?> i = typeMap.keySet().iterator();
- Class<?> c;
- String type;
- while (i.hasNext()) {
- type = (String)i.next();
- c = (Class)typeMap.get(type);
- propString("type", type);
- propString("class", c.getName());
+ Map<String, Class<?>> typeMap = caller.getTypeMap();
+ if(typeMap != null) {
+ for(Map.Entry<String, Class<?>> mm : typeMap.entrySet()) {
+ propString("type", mm.getKey());
+ propString("class", mm.getValue().getName());
}
}
endSection("map");
--- a/jdk/src/share/classes/java/io/DataInput.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/io/DataInput.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2012, 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
@@ -26,12 +26,12 @@
package java.io;
/**
- * The <code>DataInput</code> interface provides
+ * The {@code DataInput} interface provides
* for reading bytes from a binary stream and
* reconstructing from them data in any of
* the Java primitive types. There is also
* a
- * facility for reconstructing a <code>String</code>
+ * facility for reconstructing a {@code String}
* from data in
* <a href="#modified-utf-8">modified UTF-8</a>
* format.
@@ -39,12 +39,12 @@
* It is generally true of all the reading
* routines in this interface that if end of
* file is reached before the desired number
- * of bytes has been read, an <code>EOFException</code>
- * (which is a kind of <code>IOException</code>)
+ * of bytes has been read, an {@code EOFException}
+ * (which is a kind of {@code IOException})
* is thrown. If any byte cannot be read for
- * any reason other than end of file, an <code>IOException</code>
- * other than <code>EOFException</code> is
- * thrown. In particular, an <code>IOException</code>
+ * any reason other than end of file, an {@code IOException}
+ * other than {@code EOFException} is
+ * thrown. In particular, an {@code IOException}
* may be thrown if the input stream has been
* closed.
*
@@ -58,8 +58,8 @@
* Note that in the following tables, the most significant bit appears in the
* far left-hand column.
* <p>
- * All characters in the range <code>'\u0001'</code> to
- * <code>'\u007F'</code> are represented by a single byte:
+ * All characters in the range {@code '\u005Cu0001'} to
+ * {@code '\u005Cu007F'} are represented by a single byte:
*
* <blockquote>
* <table border="1" cellspacing="0" cellpadding="8" width="50%"
@@ -83,8 +83,8 @@
* </blockquote>
*
* <p>
- * The null character <code>'\u0000'</code> and characters in the
- * range <code>'\u0080'</code> to <code>'\u07FF'</code> are
+ * The null character {@code '\u005Cu0000'} and characters in the
+ * range {@code '\u005Cu0080'} to {@code '\u005Cu07FF'} are
* represented by a pair of bytes:
*
* <blockquote>
@@ -123,8 +123,8 @@
* </blockquote>
*
* <br>
- * <code>char</code> values in the range <code>'\u0800'</code> to
- * <code>'\uFFFF'</code> are represented by three bytes:
+ * {@code char} values in the range {@code '\u005Cu0800'} to
+ * {@code '\u005CuFFFF'} are represented by three bytes:
*
* <blockquote>
* <table border="1" cellspacing="0" cellpadding="8" width="50%"
@@ -178,7 +178,7 @@
* The differences between this format and the
* standard UTF-8 format are the following:
* <ul>
- * <li>The null byte <code>'\u0000'</code> is encoded in 2-byte format
+ * <li>The null byte {@code '\u005Cu0000'} is encoded in 2-byte format
* rather than 1-byte, so that the encoded strings never have
* embedded nulls.
* <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
@@ -195,36 +195,36 @@
/**
* Reads some bytes from an input
* stream and stores them into the buffer
- * array <code>b</code>. The number of bytes
+ * array {@code b}. The number of bytes
* read is equal
- * to the length of <code>b</code>.
+ * to the length of {@code b}.
* <p>
* This method blocks until one of the
* following conditions occurs:<p>
* <ul>
- * <li><code>b.length</code>
+ * <li>{@code b.length}
* bytes of input data are available, in which
* case a normal return is made.
*
* <li>End of
- * file is detected, in which case an <code>EOFException</code>
+ * file is detected, in which case an {@code EOFException}
* is thrown.
*
* <li>An I/O error occurs, in
- * which case an <code>IOException</code> other
- * than <code>EOFException</code> is thrown.
+ * which case an {@code IOException} other
+ * than {@code EOFException} is thrown.
* </ul>
* <p>
- * If <code>b</code> is <code>null</code>,
- * a <code>NullPointerException</code> is thrown.
- * If <code>b.length</code> is zero, then
+ * If {@code b} is {@code null},
+ * a {@code NullPointerException} is thrown.
+ * If {@code b.length} is zero, then
* no bytes are read. Otherwise, the first
- * byte read is stored into element <code>b[0]</code>,
- * the next one into <code>b[1]</code>, and
+ * byte read is stored into element {@code b[0]},
+ * the next one into {@code b[1]}, and
* so on.
* If an exception is thrown from
* this method, then it may be that some but
- * not all bytes of <code>b</code> have been
+ * not all bytes of {@code b} have been
* updated with data from the input stream.
*
* @param b the buffer into which the data is read.
@@ -236,7 +236,7 @@
/**
*
- * Reads <code>len</code>
+ * Reads {@code len}
* bytes from
* an input stream.
* <p>
@@ -244,32 +244,32 @@
* blocks until one of the following conditions
* occurs:<p>
* <ul>
- * <li><code>len</code> bytes
+ * <li>{@code len} bytes
* of input data are available, in which case
* a normal return is made.
*
* <li>End of file
- * is detected, in which case an <code>EOFException</code>
+ * is detected, in which case an {@code EOFException}
* is thrown.
*
* <li>An I/O error occurs, in
- * which case an <code>IOException</code> other
- * than <code>EOFException</code> is thrown.
+ * which case an {@code IOException} other
+ * than {@code EOFException} is thrown.
* </ul>
* <p>
- * If <code>b</code> is <code>null</code>,
- * a <code>NullPointerException</code> is thrown.
- * If <code>off</code> is negative, or <code>len</code>
- * is negative, or <code>off+len</code> is
- * greater than the length of the array <code>b</code>,
- * then an <code>IndexOutOfBoundsException</code>
+ * If {@code b} is {@code null},
+ * a {@code NullPointerException} is thrown.
+ * If {@code off} is negative, or {@code len}
+ * is negative, or {@code off+len} is
+ * greater than the length of the array {@code b},
+ * then an {@code IndexOutOfBoundsException}
* is thrown.
- * If <code>len</code> is zero,
+ * If {@code len} is zero,
* then no bytes are read. Otherwise, the first
- * byte read is stored into element <code>b[off]</code>,
- * the next one into <code>b[off+1]</code>,
+ * byte read is stored into element {@code b[off]},
+ * the next one into {@code b[off+1]},
* and so on. The number of bytes read is,
- * at most, equal to <code>len</code>.
+ * at most, equal to {@code len}.
*
* @param b the buffer into which the data is read.
* @param off an int specifying the offset into the data.
@@ -282,7 +282,7 @@
/**
* Makes an attempt to skip over
- * <code>n</code> bytes
+ * {@code n} bytes
* of data from the input
* stream, discarding the skipped bytes. However,
* it may skip
@@ -290,10 +290,10 @@
* bytes, possibly zero. This may result from
* any of a
* number of conditions; reaching
- * end of file before <code>n</code> bytes
+ * end of file before {@code n} bytes
* have been skipped is
* only one possibility.
- * This method never throws an <code>EOFException</code>.
+ * This method never throws an {@code EOFException}.
* The actual
* number of bytes skipped is returned.
*
@@ -305,13 +305,13 @@
/**
* Reads one input byte and returns
- * <code>true</code> if that byte is nonzero,
- * <code>false</code> if that byte is zero.
+ * {@code true} if that byte is nonzero,
+ * {@code false} if that byte is zero.
* This method is suitable for reading
- * the byte written by the <code>writeBoolean</code>
- * method of interface <code>DataOutput</code>.
+ * the byte written by the {@code writeBoolean}
+ * method of interface {@code DataOutput}.
*
- * @return the <code>boolean</code> value read.
+ * @return the {@code boolean} value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
@@ -321,11 +321,11 @@
/**
* Reads and returns one input byte.
* The byte is treated as a signed value in
- * the range <code>-128</code> through <code>127</code>,
+ * the range {@code -128} through {@code 127},
* inclusive.
* This method is suitable for
- * reading the byte written by the <code>writeByte</code>
- * method of interface <code>DataOutput</code>.
+ * reading the byte written by the {@code writeByte}
+ * method of interface {@code DataOutput}.
*
* @return the 8-bit value read.
* @exception EOFException if this stream reaches the end before reading
@@ -336,16 +336,16 @@
/**
* Reads one input byte, zero-extends
- * it to type <code>int</code>, and returns
+ * it to type {@code int}, and returns
* the result, which is therefore in the range
- * <code>0</code>
- * through <code>255</code>.
+ * {@code 0}
+ * through {@code 255}.
* This method is suitable for reading
- * the byte written by the <code>writeByte</code>
- * method of interface <code>DataOutput</code>
- * if the argument to <code>writeByte</code>
+ * the byte written by the {@code writeByte}
+ * method of interface {@code DataOutput}
+ * if the argument to {@code writeByte}
* was intended to be a value in the range
- * <code>0</code> through <code>255</code>.
+ * {@code 0} through {@code 255}.
*
* @return the unsigned 8-bit value read.
* @exception EOFException if this stream reaches the end before reading
@@ -356,8 +356,8 @@
/**
* Reads two input bytes and returns
- * a <code>short</code> value. Let <code>a</code>
- * be the first byte read and <code>b</code>
+ * a {@code short} value. Let {@code a}
+ * be the first byte read and {@code b}
* be the second byte. The value
* returned
* is:
@@ -365,8 +365,8 @@
* </code></pre>
* This method
* is suitable for reading the bytes written
- * by the <code>writeShort</code> method of
- * interface <code>DataOutput</code>.
+ * by the {@code writeShort} method of
+ * interface {@code DataOutput}.
*
* @return the 16-bit value read.
* @exception EOFException if this stream reaches the end before reading
@@ -377,19 +377,19 @@
/**
* Reads two input bytes and returns
- * an <code>int</code> value in the range <code>0</code>
- * through <code>65535</code>. Let <code>a</code>
+ * an {@code int} value in the range {@code 0}
+ * through {@code 65535}. Let {@code a}
* be the first byte read and
- * <code>b</code>
+ * {@code b}
* be the second byte. The value returned is:
* <p><pre><code>(((a & 0xff) << 8) | (b & 0xff))
* </code></pre>
* This method is suitable for reading the bytes
- * written by the <code>writeShort</code> method
- * of interface <code>DataOutput</code> if
- * the argument to <code>writeShort</code>
+ * written by the {@code writeShort} method
+ * of interface {@code DataOutput} if
+ * the argument to {@code writeShort}
* was intended to be a value in the range
- * <code>0</code> through <code>65535</code>.
+ * {@code 0} through {@code 65535}.
*
* @return the unsigned 16-bit value read.
* @exception EOFException if this stream reaches the end before reading
@@ -399,19 +399,19 @@
int readUnsignedShort() throws IOException;
/**
- * Reads two input bytes and returns a <code>char</code> value.
- * Let <code>a</code>
- * be the first byte read and <code>b</code>
+ * Reads two input bytes and returns a {@code char} value.
+ * Let {@code a}
+ * be the first byte read and {@code b}
* be the second byte. The value
* returned is:
* <p><pre><code>(char)((a << 8) | (b & 0xff))
* </code></pre>
* This method
* is suitable for reading bytes written by
- * the <code>writeChar</code> method of interface
- * <code>DataOutput</code>.
+ * the {@code writeChar} method of interface
+ * {@code DataOutput}.
*
- * @return the <code>char</code> value read.
+ * @return the {@code char} value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
@@ -420,18 +420,17 @@
/**
* Reads four input bytes and returns an
- * <code>int</code> value. Let <code>a-d</code>
+ * {@code int} value. Let {@code a-d}
* be the first through fourth bytes read. The value returned is:
- * <p><pre>
- * <code>
+ * <p><pre><code>
* (((a & 0xff) << 24) | ((b & 0xff) << 16) |
*  ((c & 0xff) << 8) | (d & 0xff))
* </code></pre>
* This method is suitable
- * for reading bytes written by the <code>writeInt</code>
- * method of interface <code>DataOutput</code>.
+ * for reading bytes written by the {@code writeInt}
+ * method of interface {@code DataOutput}.
*
- * @return the <code>int</code> value read.
+ * @return the {@code int} value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
@@ -440,10 +439,10 @@
/**
* Reads eight input bytes and returns
- * a <code>long</code> value. Let <code>a-h</code>
+ * a {@code long} value. Let {@code a-h}
* be the first through eighth bytes read.
* The value returned is:
- * <p><pre> <code>
+ * <p><pre><code>
* (((long)(a & 0xff) << 56) |
* ((long)(b & 0xff) << 48) |
* ((long)(c & 0xff) << 40) |
@@ -455,10 +454,10 @@
* </code></pre>
* <p>
* This method is suitable
- * for reading bytes written by the <code>writeLong</code>
- * method of interface <code>DataOutput</code>.
+ * for reading bytes written by the {@code writeLong}
+ * method of interface {@code DataOutput}.
*
- * @return the <code>long</code> value read.
+ * @return the {@code long} value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
@@ -467,18 +466,18 @@
/**
* Reads four input bytes and returns
- * a <code>float</code> value. It does this
- * by first constructing an <code>int</code>
+ * a {@code float} value. It does this
+ * by first constructing an {@code int}
* value in exactly the manner
- * of the <code>readInt</code>
- * method, then converting this <code>int</code>
- * value to a <code>float</code> in
- * exactly the manner of the method <code>Float.intBitsToFloat</code>.
+ * of the {@code readInt}
+ * method, then converting this {@code int}
+ * value to a {@code float} in
+ * exactly the manner of the method {@code Float.intBitsToFloat}.
* This method is suitable for reading
- * bytes written by the <code>writeFloat</code>
- * method of interface <code>DataOutput</code>.
+ * bytes written by the {@code writeFloat}
+ * method of interface {@code DataOutput}.
*
- * @return the <code>float</code> value read.
+ * @return the {@code float} value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
@@ -487,18 +486,18 @@
/**
* Reads eight input bytes and returns
- * a <code>double</code> value. It does this
- * by first constructing a <code>long</code>
+ * a {@code double} value. It does this
+ * by first constructing a {@code long}
* value in exactly the manner
- * of the <code>readlong</code>
- * method, then converting this <code>long</code>
- * value to a <code>double</code> in exactly
- * the manner of the method <code>Double.longBitsToDouble</code>.
+ * of the {@code readlong}
+ * method, then converting this {@code long}
+ * value to a {@code double} in exactly
+ * the manner of the method {@code Double.longBitsToDouble}.
* This method is suitable for reading
- * bytes written by the <code>writeDouble</code>
- * method of interface <code>DataOutput</code>.
+ * bytes written by the {@code writeDouble}
+ * method of interface {@code DataOutput}.
*
- * @return the <code>double</code> value read.
+ * @return the {@code double} value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
@@ -512,35 +511,35 @@
* until it encounters a line terminator or
* end of
* file; the characters read are then
- * returned as a <code>String</code>. Note
+ * returned as a {@code String}. Note
* that because this
* method processes bytes,
* it does not support input of the full Unicode
* character set.
* <p>
* If end of file is encountered
- * before even one byte can be read, then <code>null</code>
+ * before even one byte can be read, then {@code null}
* is returned. Otherwise, each byte that is
- * read is converted to type <code>char</code>
- * by zero-extension. If the character <code>'\n'</code>
+ * read is converted to type {@code char}
+ * by zero-extension. If the character {@code '\n'}
* is encountered, it is discarded and reading
- * ceases. If the character <code>'\r'</code>
+ * ceases. If the character {@code '\r'}
* is encountered, it is discarded and, if
* the following byte converts  to the
- * character <code>'\n'</code>, then that is
+ * character {@code '\n'}, then that is
* discarded also; reading then ceases. If
* end of file is encountered before either
- * of the characters <code>'\n'</code> and
- * <code>'\r'</code> is encountered, reading
- * ceases. Once reading has ceased, a <code>String</code>
+ * of the characters {@code '\n'} and
+ * {@code '\r'} is encountered, reading
+ * ceases. Once reading has ceased, a {@code String}
* is returned that contains all the characters
* read and not discarded, taken in order.
* Note that every character in this string
- * will have a value less than <code>\u0100</code>,
- * that is, <code>(char)256</code>.
+ * will have a value less than {@code \u005Cu0100},
+ * that is, {@code (char)256}.
*
* @return the next line of text from the input stream,
- * or <CODE>null</CODE> if the end of file is
+ * or {@code null} if the end of file is
* encountered before a byte can be read.
* @exception IOException if an I/O error occurs.
*/
@@ -550,15 +549,15 @@
* Reads in a string that has been encoded using a
* <a href="#modified-utf-8">modified UTF-8</a>
* format.
- * The general contract of <code>readUTF</code>
+ * The general contract of {@code readUTF}
* is that it reads a representation of a Unicode
* character string encoded in modified
* UTF-8 format; this string of characters
- * is then returned as a <code>String</code>.
+ * is then returned as a {@code String}.
* <p>
* First, two bytes are read and used to
* construct an unsigned 16-bit integer in
- * exactly the manner of the <code>readUnsignedShort</code>
+ * exactly the manner of the {@code readUnsignedShort}
* method . This integer value is called the
* <i>UTF length</i> and specifies the number
* of additional bytes to be read. These bytes
@@ -570,58 +569,58 @@
* next group.
* <p>
* If the first byte of a group
- * matches the bit pattern <code>0xxxxxxx</code>
- * (where <code>x</code> means "may be <code>0</code>
- * or <code>1</code>"), then the group consists
+ * matches the bit pattern {@code 0xxxxxxx}
+ * (where {@code x} means "may be {@code 0}
+ * or {@code 1}"), then the group consists
* of just that byte. The byte is zero-extended
* to form a character.
* <p>
* If the first byte
- * of a group matches the bit pattern <code>110xxxxx</code>,
- * then the group consists of that byte <code>a</code>
- * and a second byte <code>b</code>. If there
- * is no byte <code>b</code> (because byte
- * <code>a</code> was the last of the bytes
- * to be read), or if byte <code>b</code> does
- * not match the bit pattern <code>10xxxxxx</code>,
- * then a <code>UTFDataFormatException</code>
+ * of a group matches the bit pattern {@code 110xxxxx},
+ * then the group consists of that byte {@code a}
+ * and a second byte {@code b}. If there
+ * is no byte {@code b} (because byte
+ * {@code a} was the last of the bytes
+ * to be read), or if byte {@code b} does
+ * not match the bit pattern {@code 10xxxxxx},
+ * then a {@code UTFDataFormatException}
* is thrown. Otherwise, the group is converted
* to the character:<p>
* <pre><code>(char)(((a& 0x1F) << 6) | (b & 0x3F))
* </code></pre>
* If the first byte of a group
- * matches the bit pattern <code>1110xxxx</code>,
- * then the group consists of that byte <code>a</code>
- * and two more bytes <code>b</code> and <code>c</code>.
- * If there is no byte <code>c</code> (because
- * byte <code>a</code> was one of the last
+ * matches the bit pattern {@code 1110xxxx},
+ * then the group consists of that byte {@code a}
+ * and two more bytes {@code b} and {@code c}.
+ * If there is no byte {@code c} (because
+ * byte {@code a} was one of the last
* two of the bytes to be read), or either
- * byte <code>b</code> or byte <code>c</code>
- * does not match the bit pattern <code>10xxxxxx</code>,
- * then a <code>UTFDataFormatException</code>
+ * byte {@code b} or byte {@code c}
+ * does not match the bit pattern {@code 10xxxxxx},
+ * then a {@code UTFDataFormatException}
* is thrown. Otherwise, the group is converted
* to the character:<p>
* <pre><code>
* (char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F))
* </code></pre>
* If the first byte of a group matches the
- * pattern <code>1111xxxx</code> or the pattern
- * <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
+ * pattern {@code 1111xxxx} or the pattern
+ * {@code 10xxxxxx}, then a {@code UTFDataFormatException}
* is thrown.
* <p>
* If end of file is encountered
* at any time during this entire process,
- * then an <code>EOFException</code> is thrown.
+ * then an {@code EOFException} is thrown.
* <p>
* After every group has been converted to
* a character by this process, the characters
* are gathered, in the same order in which
* their corresponding groups were read from
- * the input stream, to form a <code>String</code>,
+ * the input stream, to form a {@code String},
* which is returned.
* <p>
- * The <code>writeUTF</code>
- * method of interface <code>DataOutput</code>
+ * The {@code writeUTF}
+ * method of interface {@code DataOutput}
* may be used to write data that is suitable
* for reading by this method.
* @return a Unicode string.
--- a/jdk/src/share/classes/java/io/LineNumberInputStream.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/io/LineNumberInputStream.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2012, 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
@@ -30,13 +30,13 @@
* functionality of keeping track of the current line number.
* <p>
* A line is a sequence of bytes ending with a carriage return
- * character (<code>'\r'</code>), a newline character
- * (<code>'\n'</code>), or a carriage return character followed
+ * character ({@code '\u005Cr'}), a newline character
+ * ({@code '\u005Cn'}), or a carriage return character followed
* immediately by a linefeed character. In all three cases, the line
* terminating character(s) are returned as a single newline character.
* <p>
- * The line number begins at <code>0</code>, and is incremented by
- * <code>1</code> when a <code>read</code> returns a newline character.
+ * The line number begins at {@code 0}, and is incremented by
+ * {@code 1} when a {@code read} returns a newline character.
*
* @author Arthur van Hoff
* @see java.io.LineNumberReader
@@ -66,22 +66,22 @@
/**
* Reads the next byte of data from this input stream. The value
- * byte is returned as an <code>int</code> in the range
- * <code>0</code> to <code>255</code>. If no byte is available
+ * byte is returned as an {@code int} in the range
+ * {@code 0} to {@code 255}. If no byte is available
* because the end of the stream has been reached, the value
- * <code>-1</code> is returned. This method blocks until input data
+ * {@code -1} is returned. This method blocks until input data
* is available, the end of the stream is detected, or an exception
* is thrown.
* <p>
- * The <code>read</code> method of
- * <code>LineNumberInputStream</code> calls the <code>read</code>
+ * The {@code read} method of
+ * {@code LineNumberInputStream} calls the {@code read}
* method of the underlying input stream. It checks for carriage
* returns and newline characters in the input, and modifies the
* current line number as appropriate. A carriage-return character or
* a carriage return followed by a newline character are both
* converted into a single newline character.
*
- * @return the next byte of data, or <code>-1</code> if the end of this
+ * @return the next byte of data, or {@code -1} if the end of this
* stream is reached.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
@@ -111,18 +111,18 @@
}
/**
- * Reads up to <code>len</code> bytes of data from this input stream
+ * Reads up to {@code len} bytes of data from this input stream
* into an array of bytes. This method blocks until some input is available.
* <p>
- * The <code>read</code> method of
- * <code>LineNumberInputStream</code> repeatedly calls the
- * <code>read</code> method of zero arguments to fill in the byte array.
+ * The {@code read} method of
+ * {@code LineNumberInputStream} repeatedly calls the
+ * {@code read} method of zero arguments to fill in the byte array.
*
* @param b the buffer into which the data is read.
* @param off the start offset of the data.
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
- * <code>-1</code> if there is no more data because the end of
+ * {@code -1} if there is no more data because the end of
* this stream has been reached.
* @exception IOException if an I/O error occurs.
* @see java.io.LineNumberInputStream#read()
@@ -160,15 +160,15 @@
}
/**
- * Skips over and discards <code>n</code> bytes of data from this
- * input stream. The <code>skip</code> method may, for a variety of
+ * Skips over and discards {@code n} bytes of data from this
+ * input stream. The {@code skip} method may, for a variety of
* reasons, end up skipping over some smaller number of bytes,
- * possibly <code>0</code>. The actual number of bytes skipped is
- * returned. If <code>n</code> is negative, no bytes are skipped.
+ * possibly {@code 0}. The actual number of bytes skipped is
+ * returned. If {@code n} is negative, no bytes are skipped.
* <p>
- * The <code>skip</code> method of <code>LineNumberInputStream</code> creates
+ * The {@code skip} method of {@code LineNumberInputStream} creates
* a byte array and then repeatedly reads into it until
- * <code>n</code> bytes have been read or the end of the stream has
+ * {@code n} bytes have been read or the end of the stream has
* been reached.
*
* @param n the number of bytes to be skipped.
@@ -225,12 +225,12 @@
* <p>
* Note that if the underlying input stream is able to supply
* <i>k</i> input characters without blocking, the
- * <code>LineNumberInputStream</code> can guarantee only to provide
+ * {@code LineNumberInputStream} can guarantee only to provide
* <i>k</i>/2 characters without blocking, because the
* <i>k</i> characters from the underlying input stream might
- * consist of <i>k</i>/2 pairs of <code>'\r'</code> and
- * <code>'\n'</code>, which are converted to just
- * <i>k</i>/2 <code>'\n'</code> characters.
+ * consist of <i>k</i>/2 pairs of {@code '\u005Cr'} and
+ * {@code '\u005Cn'}, which are converted to just
+ * <i>k</i>/2 {@code '\u005Cn'} characters.
*
* @return the number of bytes that can be read from this input stream
* without blocking.
@@ -243,12 +243,12 @@
/**
* Marks the current position in this input stream. A subsequent
- * call to the <code>reset</code> method repositions this stream at
+ * call to the {@code reset} method repositions this stream at
* the last marked position so that subsequent reads re-read the same bytes.
* <p>
- * The <code>mark</code> method of
- * <code>LineNumberInputStream</code> remembers the current line
- * number in a private variable, and then calls the <code>mark</code>
+ * The {@code mark} method of
+ * {@code LineNumberInputStream} remembers the current line
+ * number in a private variable, and then calls the {@code mark}
* method of the underlying input stream.
*
* @param readlimit the maximum limit of bytes that can be read before
@@ -264,12 +264,12 @@
/**
* Repositions this stream to the position at the time the
- * <code>mark</code> method was last called on this input stream.
+ * {@code mark} method was last called on this input stream.
* <p>
- * The <code>reset</code> method of
- * <code>LineNumberInputStream</code> resets the line number to be
- * the line number at the time the <code>mark</code> method was
- * called, and then calls the <code>reset</code> method of the
+ * The {@code reset} method of
+ * {@code LineNumberInputStream} resets the line number to be
+ * the line number at the time the {@code mark} method was
+ * called, and then calls the {@code reset} method of the
* underlying input stream.
* <p>
* Stream marks are intended to be used in
--- a/jdk/src/share/classes/java/io/RandomAccessFile.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/io/RandomAccessFile.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2012, 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
@@ -41,16 +41,16 @@
* the file pointer past the bytes written. Output operations that write
* past the current end of the implied array cause the array to be
* extended. The file pointer can be read by the
- * <code>getFilePointer</code> method and set by the <code>seek</code>
+ * {@code getFilePointer} method and set by the {@code seek}
* method.
* <p>
* It is generally true of all the reading routines in this class that
* if end-of-file is reached before the desired number of bytes has been
- * read, an <code>EOFException</code> (which is a kind of
- * <code>IOException</code>) is thrown. If any byte cannot be read for
- * any reason other than end-of-file, an <code>IOException</code> other
- * than <code>EOFException</code> is thrown. In particular, an
- * <code>IOException</code> may be thrown if the stream has been closed.
+ * read, an {@code EOFException} (which is a kind of
+ * {@code IOException}) is thrown. If any byte cannot be read for
+ * any reason other than end-of-file, an {@code IOException} other
+ * than {@code EOFException} is thrown. In particular, an
+ * {@code IOException} may be thrown if the stream has been closed.
*
* @author unascribed
* @since JDK1.0
@@ -82,12 +82,12 @@
* href="#mode"><tt>RandomAccessFile(File,String)</tt></a> constructor.
*
* <p>
- * If there is a security manager, its <code>checkRead</code> method
- * is called with the <code>name</code> argument
+ * If there is a security manager, its {@code checkRead} method
+ * is called with the {@code name} argument
* as its argument to see if read access to the file is allowed.
* If the mode allows writing, the security manager's
- * <code>checkWrite</code> method
- * is also called with the <code>name</code> argument
+ * {@code checkWrite} method
+ * is also called with the {@code name} argument
* as its argument to see if write access to the file is allowed.
*
* @param name the system-dependent filename
@@ -103,9 +103,9 @@
* that name cannot be created, or if some other error occurs
* while opening or creating the file
* @exception SecurityException if a security manager exists and its
- * <code>checkRead</code> method denies read access to the file
+ * {@code checkRead} method denies read access to the file
* or the mode is "rw" and the security manager's
- * <code>checkWrite</code> method denies write access to the file
+ * {@code checkWrite} method denies write access to the file
* @see java.lang.SecurityException
* @see java.lang.SecurityManager#checkRead(java.lang.String)
* @see java.lang.SecurityManager#checkWrite(java.lang.String)
@@ -164,10 +164,10 @@
* updates to both the file's content and its metadata to be written, which
* generally requires at least one more low-level I/O operation.
*
- * <p> If there is a security manager, its <code>checkRead</code> method is
- * called with the pathname of the <code>file</code> argument as its
+ * <p> If there is a security manager, its {@code checkRead} method is
+ * called with the pathname of the {@code file} argument as its
* argument to see if read access to the file is allowed. If the mode
- * allows writing, the security manager's <code>checkWrite</code> method is
+ * allows writing, the security manager's {@code checkWrite} method is
* also called with the path argument to see if write access to the file is
* allowed.
*
@@ -185,9 +185,9 @@
* that name cannot be created, or if some other error occurs
* while opening or creating the file
* @exception SecurityException if a security manager exists and its
- * <code>checkRead</code> method denies read access to the file
+ * {@code checkRead} method denies read access to the file
* or the mode is "rw" and the security manager's
- * <code>checkWrite</code> method denies write access to the file
+ * {@code checkWrite} method denies write access to the file
* @see java.lang.SecurityManager#checkRead(java.lang.String)
* @see java.lang.SecurityManager#checkWrite(java.lang.String)
* @see java.nio.channels.FileChannel#force(boolean)
@@ -253,7 +253,7 @@
* object associated with this file.
*
* <p> The {@link java.nio.channels.FileChannel#position()
- * </code>position<code>} of the returned channel will always be equal to
+ * position} of the returned channel will always be equal to
* this object's file-pointer offset as returned by the {@link
* #getFilePointer getFilePointer} method. Changing this object's
* file-pointer offset, whether explicitly or by reading or writing bytes,
@@ -277,9 +277,9 @@
/**
* Opens a file and returns the file descriptor. The file is
- * opened in read-write mode if the O_RDWR bit in <code>mode</code>
+ * opened in read-write mode if the O_RDWR bit in {@code mode}
* is true, else the file is opened as read-only.
- * If the <code>name</code> refers to a directory, an IOException
+ * If the {@code name} refers to a directory, an IOException
* is thrown.
*
* @param name the name of the file
@@ -293,15 +293,15 @@
/**
* Reads a byte of data from this file. The byte is returned as an
- * integer in the range 0 to 255 (<code>0x00-0x0ff</code>). This
+ * integer in the range 0 to 255 ({@code 0x00-0x0ff}). This
* method blocks if no input is yet available.
* <p>
- * Although <code>RandomAccessFile</code> is not a subclass of
- * <code>InputStream</code>, this method behaves in exactly the same
+ * Although {@code RandomAccessFile} is not a subclass of
+ * {@code InputStream}, this method behaves in exactly the same
* way as the {@link InputStream#read()} method of
- * <code>InputStream</code>.
+ * {@code InputStream}.
*
- * @return the next byte of data, or <code>-1</code> if the end of the
+ * @return the next byte of data, or {@code -1} if the end of the
* file has been reached.
* @exception IOException if an I/O error occurs. Not thrown if
* end-of-file has been reached.
@@ -318,59 +318,59 @@
private native int readBytes(byte b[], int off, int len) throws IOException;
/**
- * Reads up to <code>len</code> bytes of data from this file into an
+ * Reads up to {@code len} bytes of data from this file into an
* array of bytes. This method blocks until at least one byte of input
* is available.
* <p>
- * Although <code>RandomAccessFile</code> is not a subclass of
- * <code>InputStream</code>, this method behaves in exactly the
+ * Although {@code RandomAccessFile} is not a subclass of
+ * {@code InputStream}, this method behaves in exactly the
* same way as the {@link InputStream#read(byte[], int, int)} method of
- * <code>InputStream</code>.
+ * {@code InputStream}.
*
* @param b the buffer into which the data is read.
- * @param off the start offset in array <code>b</code>
+ * @param off the start offset in array {@code b}
* at which the data is written.
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
- * <code>-1</code> if there is no more data because the end of
+ * {@code -1} if there is no more data because the end of
* the file has been reached.
* @exception IOException If the first byte cannot be read for any reason
* other than end of file, or if the random access file has been closed, or if
* some other I/O error occurs.
- * @exception NullPointerException If <code>b</code> is <code>null</code>.
- * @exception IndexOutOfBoundsException If <code>off</code> is negative,
- * <code>len</code> is negative, or <code>len</code> is greater than
- * <code>b.length - off</code>
+ * @exception NullPointerException If {@code b} is {@code null}.
+ * @exception IndexOutOfBoundsException If {@code off} is negative,
+ * {@code len} is negative, or {@code len} is greater than
+ * {@code b.length - off}
*/
public int read(byte b[], int off, int len) throws IOException {
return readBytes(b, off, len);
}
/**
- * Reads up to <code>b.length</code> bytes of data from this file
+ * Reads up to {@code b.length} bytes of data from this file
* into an array of bytes. This method blocks until at least one byte
* of input is available.
* <p>
- * Although <code>RandomAccessFile</code> is not a subclass of
- * <code>InputStream</code>, this method behaves in exactly the
+ * Although {@code RandomAccessFile} is not a subclass of
+ * {@code InputStream}, this method behaves in exactly the
* same way as the {@link InputStream#read(byte[])} method of
- * <code>InputStream</code>.
+ * {@code InputStream}.
*
* @param b the buffer into which the data is read.
* @return the total number of bytes read into the buffer, or
- * <code>-1</code> if there is no more data because the end of
+ * {@code -1} if there is no more data because the end of
* this file has been reached.
* @exception IOException If the first byte cannot be read for any reason
* other than end of file, or if the random access file has been closed, or if
* some other I/O error occurs.
- * @exception NullPointerException If <code>b</code> is <code>null</code>.
+ * @exception NullPointerException If {@code b} is {@code null}.
*/
public int read(byte b[]) throws IOException {
return readBytes(b, 0, b.length);
}
/**
- * Reads <code>b.length</code> bytes from this file into the byte
+ * Reads {@code b.length} bytes from this file into the byte
* array, starting at the current file pointer. This method reads
* repeatedly from the file until the requested number of bytes are
* read. This method blocks until the requested number of bytes are
@@ -386,7 +386,7 @@
}
/**
- * Reads exactly <code>len</code> bytes from this file into the byte
+ * Reads exactly {@code len} bytes from this file into the byte
* array, starting at the current file pointer. This method reads
* repeatedly from the file until the requested number of bytes are
* read. This method blocks until the requested number of bytes are
@@ -410,15 +410,15 @@
}
/**
- * Attempts to skip over <code>n</code> bytes of input discarding the
+ * Attempts to skip over {@code n} bytes of input discarding the
* skipped bytes.
* <p>
*
* This method may skip over some smaller number of bytes, possibly zero.
* This may result from any of a number of conditions; reaching end of
- * file before <code>n</code> bytes have been skipped is only one
- * possibility. This method never throws an <code>EOFException</code>.
- * The actual number of bytes skipped is returned. If <code>n</code>
+ * file before {@code n} bytes have been skipped is only one
+ * possibility. This method never throws an {@code EOFException}.
+ * The actual number of bytes skipped is returned. If {@code n}
* is negative, no bytes are skipped.
*
* @param n the number of bytes to be skipped.
@@ -451,7 +451,7 @@
* Writes the specified byte to this file. The write starts at
* the current file pointer.
*
- * @param b the <code>byte</code> to be written.
+ * @param b the {@code byte} to be written.
* @exception IOException if an I/O error occurs.
*/
public native void write(int b) throws IOException;
@@ -467,7 +467,7 @@
private native void writeBytes(byte b[], int off, int len) throws IOException;
/**
- * Writes <code>b.length</code> bytes from the specified byte array
+ * Writes {@code b.length} bytes from the specified byte array
* to this file, starting at the current file pointer.
*
* @param b the data.
@@ -478,8 +478,8 @@
}
/**
- * Writes <code>len</code> bytes from the specified byte array
- * starting at offset <code>off</code> to this file.
+ * Writes {@code len} bytes from the specified byte array
+ * starting at offset {@code off} to this file.
*
* @param b the data.
* @param off the start offset in the data.
@@ -512,8 +512,8 @@
* @param pos the offset position, measured in bytes from the
* beginning of the file, at which to set the file
* pointer.
- * @exception IOException if <code>pos</code> is less than
- * <code>0</code> or if an I/O error occurs.
+ * @exception IOException if {@code pos} is less than
+ * {@code 0} or if an I/O error occurs.
*/
public native void seek(long pos) throws IOException;
@@ -529,14 +529,14 @@
* Sets the length of this file.
*
* <p> If the present length of the file as returned by the
- * <code>length</code> method is greater than the <code>newLength</code>
+ * {@code length} method is greater than the {@code newLength}
* argument then the file will be truncated. In this case, if the file
- * offset as returned by the <code>getFilePointer</code> method is greater
- * than <code>newLength</code> then after this method returns the offset
- * will be equal to <code>newLength</code>.
+ * offset as returned by the {@code getFilePointer} method is greater
+ * than {@code newLength} then after this method returns the offset
+ * will be equal to {@code newLength}.
*
* <p> If the present length of the file as returned by the
- * <code>length</code> method is smaller than the <code>newLength</code>
+ * {@code length} method is smaller than the {@code newLength}
* argument then the file will be extended. In this case, the contents of
* the extended portion of the file are not defined.
*
@@ -584,14 +584,14 @@
//
/**
- * Reads a <code>boolean</code> from this file. This method reads a
+ * Reads a {@code boolean} from this file. This method reads a
* single byte from the file, starting at the current file pointer.
- * A value of <code>0</code> represents
- * <code>false</code>. Any other value represents <code>true</code>.
+ * A value of {@code 0} represents
+ * {@code false}. Any other value represents {@code true}.
* This method blocks until the byte is read, the end of the stream
* is detected, or an exception is thrown.
*
- * @return the <code>boolean</code> value read.
+ * @return the {@code boolean} value read.
* @exception EOFException if this file has reached the end.
* @exception IOException if an I/O error occurs.
*/
@@ -605,7 +605,7 @@
/**
* Reads a signed eight-bit value from this file. This method reads a
* byte from the file, starting from the current file pointer.
- * If the byte read is <code>b</code>, where
+ * If the byte read is {@code b}, where
* <code>0 <= b <= 255</code>,
* then the result is:
* <blockquote><pre>
@@ -616,7 +616,7 @@
* is detected, or an exception is thrown.
*
* @return the next byte of this file as a signed eight-bit
- * <code>byte</code>.
+ * {@code byte}.
* @exception EOFException if this file has reached the end.
* @exception IOException if an I/O error occurs.
*/
@@ -651,8 +651,8 @@
* Reads a signed 16-bit number from this file. The method reads two
* bytes from this file, starting at the current file pointer.
* If the two bytes read, in order, are
- * <code>b1</code> and <code>b2</code>, where each of the two values is
- * between <code>0</code> and <code>255</code>, inclusive, then the
+ * {@code b1} and {@code b2}, where each of the two values is
+ * between {@code 0} and {@code 255}, inclusive, then the
* result is equal to:
* <blockquote><pre>
* (short)((b1 << 8) | b2)
@@ -679,7 +679,7 @@
* Reads an unsigned 16-bit number from this file. This method reads
* two bytes from the file, starting at the current file pointer.
* If the bytes read, in order, are
- * <code>b1</code> and <code>b2</code>, where
+ * {@code b1} and {@code b2}, where
* <code>0 <= b1, b2 <= 255</code>,
* then the result is equal to:
* <blockquote><pre>
@@ -707,7 +707,7 @@
* Reads a character from this file. This method reads two
* bytes from the file, starting at the current file pointer.
* If the bytes read, in order, are
- * <code>b1</code> and <code>b2</code>, where
+ * {@code b1} and {@code b2}, where
* <code>0 <= b1, b2 <= 255</code>,
* then the result is equal to:
* <blockquote><pre>
@@ -718,7 +718,7 @@
* stream is detected, or an exception is thrown.
*
* @return the next two bytes of this file, interpreted as a
- * <code>char</code>.
+ * {@code char}.
* @exception EOFException if this file reaches the end before reading
* two bytes.
* @exception IOException if an I/O error occurs.
@@ -734,8 +734,8 @@
/**
* Reads a signed 32-bit integer from this file. This method reads 4
* bytes from the file, starting at the current file pointer.
- * If the bytes read, in order, are <code>b1</code>,
- * <code>b2</code>, <code>b3</code>, and <code>b4</code>, where
+ * If the bytes read, in order, are {@code b1},
+ * {@code b2}, {@code b3}, and {@code b4}, where
* <code>0 <= b1, b2, b3, b4 <= 255</code>,
* then the result is equal to:
* <blockquote><pre>
@@ -746,7 +746,7 @@
* stream is detected, or an exception is thrown.
*
* @return the next four bytes of this file, interpreted as an
- * <code>int</code>.
+ * {@code int}.
* @exception EOFException if this file reaches the end before reading
* four bytes.
* @exception IOException if an I/O error occurs.
@@ -765,9 +765,9 @@
* Reads a signed 64-bit integer from this file. This method reads eight
* bytes from the file, starting at the current file pointer.
* If the bytes read, in order, are
- * <code>b1</code>, <code>b2</code>, <code>b3</code>,
- * <code>b4</code>, <code>b5</code>, <code>b6</code>,
- * <code>b7</code>, and <code>b8,</code> where:
+ * {@code b1}, {@code b2}, {@code b3},
+ * {@code b4}, {@code b5}, {@code b6},
+ * {@code b7}, and {@code b8,} where:
* <blockquote><pre>
* 0 <= b1, b2, b3, b4, b5, b6, b7, b8 <=255,
* </pre></blockquote>
@@ -784,7 +784,7 @@
* stream is detected, or an exception is thrown.
*
* @return the next eight bytes of this file, interpreted as a
- * <code>long</code>.
+ * {@code long}.
* @exception EOFException if this file reaches the end before reading
* eight bytes.
* @exception IOException if an I/O error occurs.
@@ -794,18 +794,18 @@
}
/**
- * Reads a <code>float</code> from this file. This method reads an
- * <code>int</code> value, starting at the current file pointer,
- * as if by the <code>readInt</code> method
- * and then converts that <code>int</code> to a <code>float</code>
- * using the <code>intBitsToFloat</code> method in class
- * <code>Float</code>.
+ * Reads a {@code float} from this file. This method reads an
+ * {@code int} value, starting at the current file pointer,
+ * as if by the {@code readInt} method
+ * and then converts that {@code int} to a {@code float}
+ * using the {@code intBitsToFloat} method in class
+ * {@code Float}.
* <p>
* This method blocks until the four bytes are read, the end of the
* stream is detected, or an exception is thrown.
*
* @return the next four bytes of this file, interpreted as a
- * <code>float</code>.
+ * {@code float}.
* @exception EOFException if this file reaches the end before reading
* four bytes.
* @exception IOException if an I/O error occurs.
@@ -817,18 +817,18 @@
}
/**
- * Reads a <code>double</code> from this file. This method reads a
- * <code>long</code> value, starting at the current file pointer,
- * as if by the <code>readLong</code> method
- * and then converts that <code>long</code> to a <code>double</code>
- * using the <code>longBitsToDouble</code> method in
- * class <code>Double</code>.
+ * Reads a {@code double} from this file. This method reads a
+ * {@code long} value, starting at the current file pointer,
+ * as if by the {@code readLong} method
+ * and then converts that {@code long} to a {@code double}
+ * using the {@code longBitsToDouble} method in
+ * class {@code Double}.
* <p>
* This method blocks until the eight bytes are read, the end of the
* stream is detected, or an exception is thrown.
*
* @return the next eight bytes of this file, interpreted as a
- * <code>double</code>.
+ * {@code double}.
* @exception EOFException if this file reaches the end before reading
* eight bytes.
* @exception IOException if an I/O error occurs.
@@ -849,7 +849,7 @@
* therefore, support the full Unicode character set.
*
* <p> A line of text is terminated by a carriage-return character
- * (<code>'\r'</code>), a newline character (<code>'\n'</code>), a
+ * ({@code '\u005Cr'}), a newline character ({@code '\u005Cn'}), a
* carriage-return character immediately followed by a newline character,
* or the end of the file. Line-terminating characters are discarded and
* are not included as part of the string returned.
@@ -901,7 +901,7 @@
* <p>
* The first two bytes are read, starting from the current file
* pointer, as if by
- * <code>readUnsignedShort</code>. This value gives the number of
+ * {@code readUnsignedShort}. This value gives the number of
* following bytes that are in the encoded string, not
* the length of the resulting string. The following bytes are then
* interpreted as bytes encoding characters in the modified UTF-8 format
@@ -923,13 +923,13 @@
}
/**
- * Writes a <code>boolean</code> to the file as a one-byte value. The
- * value <code>true</code> is written out as the value
- * <code>(byte)1</code>; the value <code>false</code> is written out
- * as the value <code>(byte)0</code>. The write starts at
+ * Writes a {@code boolean} to the file as a one-byte value. The
+ * value {@code true} is written out as the value
+ * {@code (byte)1}; the value {@code false} is written out
+ * as the value {@code (byte)0}. The write starts at
* the current position of the file pointer.
*
- * @param v a <code>boolean</code> value to be written.
+ * @param v a {@code boolean} value to be written.
* @exception IOException if an I/O error occurs.
*/
public final void writeBoolean(boolean v) throws IOException {
@@ -938,10 +938,10 @@
}
/**
- * Writes a <code>byte</code> to the file as a one-byte value. The
+ * Writes a {@code byte} to the file as a one-byte value. The
* write starts at the current position of the file pointer.
*
- * @param v a <code>byte</code> value to be written.
+ * @param v a {@code byte} value to be written.
* @exception IOException if an I/O error occurs.
*/
public final void writeByte(int v) throws IOException {
@@ -950,10 +950,10 @@
}
/**
- * Writes a <code>short</code> to the file as two bytes, high byte first.
+ * Writes a {@code short} to the file as two bytes, high byte first.
* The write starts at the current position of the file pointer.
*
- * @param v a <code>short</code> to be written.
+ * @param v a {@code short} to be written.
* @exception IOException if an I/O error occurs.
*/
public final void writeShort(int v) throws IOException {
@@ -963,11 +963,11 @@
}
/**
- * Writes a <code>char</code> to the file as a two-byte value, high
+ * Writes a {@code char} to the file as a two-byte value, high
* byte first. The write starts at the current position of the
* file pointer.
*
- * @param v a <code>char</code> value to be written.
+ * @param v a {@code char} value to be written.
* @exception IOException if an I/O error occurs.
*/
public final void writeChar(int v) throws IOException {
@@ -977,10 +977,10 @@
}
/**
- * Writes an <code>int</code> to the file as four bytes, high byte first.
+ * Writes an {@code int} to the file as four bytes, high byte first.
* The write starts at the current position of the file pointer.
*
- * @param v an <code>int</code> to be written.
+ * @param v an {@code int} to be written.
* @exception IOException if an I/O error occurs.
*/
public final void writeInt(int v) throws IOException {
@@ -992,10 +992,10 @@
}
/**
- * Writes a <code>long</code> to the file as eight bytes, high byte first.
+ * Writes a {@code long} to the file as eight bytes, high byte first.
* The write starts at the current position of the file pointer.
*
- * @param v a <code>long</code> to be written.
+ * @param v a {@code long} to be written.
* @exception IOException if an I/O error occurs.
*/
public final void writeLong(long v) throws IOException {
@@ -1011,13 +1011,13 @@
}
/**
- * Converts the float argument to an <code>int</code> using the
- * <code>floatToIntBits</code> method in class <code>Float</code>,
- * and then writes that <code>int</code> value to the file as a
+ * Converts the float argument to an {@code int} using the
+ * {@code floatToIntBits} method in class {@code Float},
+ * and then writes that {@code int} value to the file as a
* four-byte quantity, high byte first. The write starts at the
* current position of the file pointer.
*
- * @param v a <code>float</code> value to be written.
+ * @param v a {@code float} value to be written.
* @exception IOException if an I/O error occurs.
* @see java.lang.Float#floatToIntBits(float)
*/
@@ -1026,13 +1026,13 @@
}
/**
- * Converts the double argument to a <code>long</code> using the
- * <code>doubleToLongBits</code> method in class <code>Double</code>,
- * and then writes that <code>long</code> value to the file as an
+ * Converts the double argument to a {@code long} using the
+ * {@code doubleToLongBits} method in class {@code Double},
+ * and then writes that {@code long} value to the file as an
* eight-byte quantity, high byte first. The write starts at the current
* position of the file pointer.
*
- * @param v a <code>double</code> value to be written.
+ * @param v a {@code double} value to be written.
* @exception IOException if an I/O error occurs.
* @see java.lang.Double#doubleToLongBits(double)
*/
@@ -1060,10 +1060,10 @@
/**
* Writes a string to the file as a sequence of characters. Each
* character is written to the data output stream as if by the
- * <code>writeChar</code> method. The write starts at the current
+ * {@code writeChar} method. The write starts at the current
* position of the file pointer.
*
- * @param s a <code>String</code> value to be written.
+ * @param s a {@code String} value to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.RandomAccessFile#writeChar(int)
*/
@@ -1087,7 +1087,7 @@
* <p>
* First, two bytes are written to the file, starting at the
* current file pointer, as if by the
- * <code>writeShort</code> method giving the number of bytes to
+ * {@code writeShort} method giving the number of bytes to
* follow. This value is the number of bytes actually written out,
* not the length of the string. Following the length, each character
* of the string is output, in sequence, using the modified UTF-8 encoding
--- a/jdk/src/share/classes/java/io/StreamTokenizer.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/io/StreamTokenizer.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2012, 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
@@ -28,7 +28,7 @@
import java.util.Arrays;
/**
- * The <code>StreamTokenizer</code> class takes an input stream and
+ * The {@code StreamTokenizer} class takes an input stream and
* parses it into "tokens", allowing the tokens to be
* read one at a time. The parsing process is controlled by a table
* and a number of flags that can be set to various states. The
@@ -36,7 +36,7 @@
* strings, and various comment styles.
* <p>
* Each byte read from the input stream is regarded as a character
- * in the range <code>'\u0000'</code> through <code>'\u00FF'</code>.
+ * in the range {@code '\u005Cu0000'} through {@code '\u005Cu00FF'}.
* The character value is used to look up five possible attributes of
* the character: <i>white space</i>, <i>alphabetic</i>,
* <i>numeric</i>, <i>string quote</i>, and <i>comment character</i>.
@@ -53,8 +53,8 @@
* <p>
* A typical application first constructs an instance of this class,
* sets up the syntax tables, and then repeatedly loops calling the
- * <code>nextToken</code> method in each iteration of the loop until
- * it returns the value <code>TT_EOF</code>.
+ * {@code nextToken} method in each iteration of the loop until
+ * it returns the value {@code TT_EOF}.
*
* @author James Gosling
* @see java.io.StreamTokenizer#nextToken()
@@ -99,19 +99,19 @@
private static final byte CT_COMMENT = 16;
/**
- * After a call to the <code>nextToken</code> method, this field
+ * After a call to the {@code nextToken} method, this field
* contains the type of the token just read. For a single character
* token, its value is the single character, converted to an integer.
* For a quoted string token, its value is the quote character.
* Otherwise, its value is one of the following:
* <ul>
- * <li><code>TT_WORD</code> indicates that the token is a word.
- * <li><code>TT_NUMBER</code> indicates that the token is a number.
- * <li><code>TT_EOL</code> indicates that the end of line has been read.
+ * <li>{@code TT_WORD} indicates that the token is a word.
+ * <li>{@code TT_NUMBER} indicates that the token is a number.
+ * <li>{@code TT_EOL} indicates that the end of line has been read.
* The field can only have this value if the
- * <code>eolIsSignificant</code> method has been called with the
- * argument <code>true</code>.
- * <li><code>TT_EOF</code> indicates that the end of the input stream
+ * {@code eolIsSignificant} method has been called with the
+ * argument {@code true}.
+ * <li>{@code TT_EOF} indicates that the end of the input stream
* has been reached.
* </ul>
* <p>
@@ -160,8 +160,8 @@
* the string.
* <p>
* The current token is a word when the value of the
- * <code>ttype</code> field is <code>TT_WORD</code>. The current token is
- * a quoted string token when the value of the <code>ttype</code> field is
+ * {@code ttype} field is {@code TT_WORD}. The current token is
+ * a quoted string token when the value of the {@code ttype} field is
* a quote character.
* <p>
* The initial value of this field is null.
@@ -175,7 +175,7 @@
/**
* If the current token is a number, this field contains the value
* of that number. The current token is a number when the value of
- * the <code>ttype</code> field is <code>TT_NUMBER</code>.
+ * the {@code ttype} field is {@code TT_NUMBER}.
* <p>
* The initial value of this field is 0.0.
*
@@ -201,14 +201,14 @@
* stream. The stream tokenizer is initialized to the following
* default state:
* <ul>
- * <li>All byte values <code>'A'</code> through <code>'Z'</code>,
- * <code>'a'</code> through <code>'z'</code>, and
- * <code>'\u00A0'</code> through <code>'\u00FF'</code> are
+ * <li>All byte values {@code 'A'} through {@code 'Z'},
+ * {@code 'a'} through {@code 'z'}, and
+ * {@code '\u005Cu00A0'} through {@code '\u005Cu00FF'} are
* considered to be alphabetic.
- * <li>All byte values <code>'\u0000'</code> through
- * <code>'\u0020'</code> are considered to be white space.
- * <li><code>'/'</code> is a comment character.
- * <li>Single quote <code>'\''</code> and double quote <code>'"'</code>
+ * <li>All byte values {@code '\u005Cu0000'} through
+ * {@code '\u005Cu0020'} are considered to be white space.
+ * <li>{@code '/'} is a comment character.
+ * <li>Single quote {@code '\u005C''} and double quote {@code '"'}
* are string quote characters.
* <li>Numbers are parsed.
* <li>Ends of lines are treated as white space, not as separate tokens.
@@ -252,7 +252,7 @@
/**
* Resets this tokenizer's syntax table so that all characters are
- * "ordinary." See the <code>ordinaryChar</code> method
+ * "ordinary." See the {@code ordinaryChar} method
* for more information on a character being ordinary.
*
* @see java.io.StreamTokenizer#ordinaryChar(int)
@@ -305,7 +305,7 @@
* Specifies that all characters <i>c</i> in the range
* <code>low <= <i>c</i> <= high</code>
* are "ordinary" in this tokenizer. See the
- * <code>ordinaryChar</code> method for more information on a
+ * {@code ordinaryChar} method for more information on a
* character being ordinary.
*
* @param low the low end of the range.
@@ -327,12 +327,12 @@
* character has as a comment character, word component, string
* delimiter, white space, or number character. When such a character
* is encountered by the parser, the parser treats it as a
- * single-character token and sets <code>ttype</code> field to the
+ * single-character token and sets {@code ttype} field to the
* character value.
*
* <p>Making a line terminator character "ordinary" may interfere
- * with the ability of a <code>StreamTokenizer</code> to count
- * lines. The <code>lineno</code> method may no longer reflect
+ * with the ability of a {@code StreamTokenizer} to count
+ * lines. The {@code lineno} method may no longer reflect
* the presence of such terminator characters in its line count.
*
* @param ch the character.
@@ -361,9 +361,9 @@
* Specifies that matching pairs of this character delimit string
* constants in this tokenizer.
* <p>
- * When the <code>nextToken</code> method encounters a string
- * constant, the <code>ttype</code> field is set to the string
- * delimiter and the <code>sval</code> field is set to the body of
+ * When the {@code nextToken} method encounters a string
+ * constant, the {@code ttype} field is set to the string
+ * delimiter and the {@code sval} field is set to the body of
* the string.
* <p>
* If a string quote character is encountered, then a string is
@@ -371,7 +371,7 @@
* the string quote character, up to (but not including) the next
* occurrence of that same string quote character, or a line
* terminator, or end of file. The usual escape sequences such as
- * <code>"\n"</code> and <code>"\t"</code> are recognized and
+ * {@code "\u005Cn"} and {@code "\u005Ct"} are recognized and
* converted to single characters as the string is parsed.
*
* <p>Any other attribute settings for the specified character are cleared.
@@ -398,9 +398,9 @@
* <p>
* When the parser encounters a word token that has the format of a
* double precision floating-point number, it treats the token as a
- * number rather than a word, by setting the <code>ttype</code>
- * field to the value <code>TT_NUMBER</code> and putting the numeric
- * value of the token into the <code>nval</code> field.
+ * number rather than a word, by setting the {@code ttype}
+ * field to the value {@code TT_NUMBER} and putting the numeric
+ * value of the token into the {@code nval} field.
*
* @see java.io.StreamTokenizer#nval
* @see java.io.StreamTokenizer#TT_NUMBER
@@ -416,21 +416,21 @@
/**
* Determines whether or not ends of line are treated as tokens.
* If the flag argument is true, this tokenizer treats end of lines
- * as tokens; the <code>nextToken</code> method returns
- * <code>TT_EOL</code> and also sets the <code>ttype</code> field to
+ * as tokens; the {@code nextToken} method returns
+ * {@code TT_EOL} and also sets the {@code ttype} field to
* this value when an end of line is read.
* <p>
* A line is a sequence of characters ending with either a
- * carriage-return character (<code>'\r'</code>) or a newline
- * character (<code>'\n'</code>). In addition, a carriage-return
+ * carriage-return character ({@code '\u005Cr'}) or a newline
+ * character ({@code '\u005Cn'}). In addition, a carriage-return
* character followed immediately by a newline character is treated
* as a single end-of-line token.
* <p>
- * If the <code>flag</code> is false, end-of-line characters are
+ * If the {@code flag} is false, end-of-line characters are
* treated as white space and serve only to separate tokens.
*
- * @param flag <code>true</code> indicates that end-of-line characters
- * are separate tokens; <code>false</code> indicates that
+ * @param flag {@code true} indicates that end-of-line characters
+ * are separate tokens; {@code false} indicates that
* end-of-line characters are white space.
* @see java.io.StreamTokenizer#nextToken()
* @see java.io.StreamTokenizer#ttype
@@ -442,14 +442,14 @@
/**
* Determines whether or not the tokenizer recognizes C-style comments.
- * If the flag argument is <code>true</code>, this stream tokenizer
+ * If the flag argument is {@code true}, this stream tokenizer
* recognizes C-style comments. All text between successive
- * occurrences of <code>/*</code> and <code>*/</code> are discarded.
+ * occurrences of {@code /*} and <code>*/</code> are discarded.
* <p>
- * If the flag argument is <code>false</code>, then C-style comments
+ * If the flag argument is {@code false}, then C-style comments
* are not treated specially.
*
- * @param flag <code>true</code> indicates to recognize and ignore
+ * @param flag {@code true} indicates to recognize and ignore
* C-style comments.
*/
public void slashStarComments(boolean flag) {
@@ -458,15 +458,15 @@
/**
* Determines whether or not the tokenizer recognizes C++-style comments.
- * If the flag argument is <code>true</code>, this stream tokenizer
+ * If the flag argument is {@code true}, this stream tokenizer
* recognizes C++-style comments. Any occurrence of two consecutive
- * slash characters (<code>'/'</code>) is treated as the beginning of
+ * slash characters ({@code '/'}) is treated as the beginning of
* a comment that extends to the end of the line.
* <p>
- * If the flag argument is <code>false</code>, then C++-style
+ * If the flag argument is {@code false}, then C++-style
* comments are not treated specially.
*
- * @param flag <code>true</code> indicates to recognize and ignore
+ * @param flag {@code true} indicates to recognize and ignore
* C++-style comments.
*/
public void slashSlashComments(boolean flag) {
@@ -475,16 +475,16 @@
/**
* Determines whether or not word token are automatically lowercased.
- * If the flag argument is <code>true</code>, then the value in the
- * <code>sval</code> field is lowercased whenever a word token is
- * returned (the <code>ttype</code> field has the
- * value <code>TT_WORD</code> by the <code>nextToken</code> method
+ * If the flag argument is {@code true}, then the value in the
+ * {@code sval} field is lowercased whenever a word token is
+ * returned (the {@code ttype} field has the
+ * value {@code TT_WORD} by the {@code nextToken} method
* of this tokenizer.
* <p>
- * If the flag argument is <code>false</code>, then the
- * <code>sval</code> field is not modified.
+ * If the flag argument is {@code false}, then the
+ * {@code sval} field is not modified.
*
- * @param fl <code>true</code> indicates that all word tokens should
+ * @param fl {@code true} indicates that all word tokens should
* be lowercased.
* @see java.io.StreamTokenizer#nextToken()
* @see java.io.StreamTokenizer#ttype
@@ -506,9 +506,9 @@
/**
* Parses the next token from the input stream of this tokenizer.
- * The type of the next token is returned in the <code>ttype</code>
+ * The type of the next token is returned in the {@code ttype}
* field. Additional information about the token may be in the
- * <code>nval</code> field or the <code>sval</code> field of this
+ * {@code nval} field or the {@code sval} field of this
* tokenizer.
* <p>
* Typical clients of this
@@ -516,7 +516,7 @@
* calling nextToken to parse successive tokens until TT_EOF
* is returned.
*
- * @return the value of the <code>ttype</code> field.
+ * @return the value of the {@code ttype} field.
* @exception IOException if an I/O error occurs.
* @see java.io.StreamTokenizer#nval
* @see java.io.StreamTokenizer#sval
@@ -752,10 +752,10 @@
}
/**
- * Causes the next call to the <code>nextToken</code> method of this
- * tokenizer to return the current value in the <code>ttype</code>
- * field, and not to modify the value in the <code>nval</code> or
- * <code>sval</code> field.
+ * Causes the next call to the {@code nextToken} method of this
+ * tokenizer to return the current value in the {@code ttype}
+ * field, and not to modify the value in the {@code nval} or
+ * {@code sval} field.
*
* @see java.io.StreamTokenizer#nextToken()
* @see java.io.StreamTokenizer#nval
--- a/jdk/src/share/classes/java/lang/AbstractStringBuilder.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/lang/AbstractStringBuilder.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, 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
@@ -91,10 +91,10 @@
* array is allocated with greater capacity. The new capacity is the
* larger of:
* <ul>
- * <li>The <code>minimumCapacity</code> argument.
- * <li>Twice the old capacity, plus <code>2</code>.
+ * <li>The {@code minimumCapacity} argument.
+ * <li>Twice the old capacity, plus {@code 2}.
* </ul>
- * If the <code>minimumCapacity</code> argument is nonpositive, this
+ * If the {@code minimumCapacity} argument is nonpositive, this
* method takes no action and simply returns.
*
* @param minimumCapacity the minimum desired capacity.
@@ -147,26 +147,26 @@
* Sets the length of the character sequence.
* The sequence is changed to a new character sequence
* whose length is specified by the argument. For every nonnegative
- * index <i>k</i> less than <code>newLength</code>, the character at
+ * index <i>k</i> less than {@code newLength}, the character at
* index <i>k</i> in the new character sequence is the same as the
* character at index <i>k</i> in the old sequence if <i>k</i> is less
* than the length of the old character sequence; otherwise, it is the
- * null character <code>'\u0000'</code>.
+ * null character {@code '\u005Cu0000'}.
*
- * In other words, if the <code>newLength</code> argument is less than
+ * In other words, if the {@code newLength} argument is less than
* the current length, the length is changed to the specified length.
* <p>
- * If the <code>newLength</code> argument is greater than or equal
+ * If the {@code newLength} argument is greater than or equal
* to the current length, sufficient null characters
- * (<code>'\u0000'</code>) are appended so that
- * length becomes the <code>newLength</code> argument.
+ * ({@code '\u005Cu0000'}) are appended so that
+ * length becomes the {@code newLength} argument.
* <p>
- * The <code>newLength</code> argument must be greater than or equal
- * to <code>0</code>.
+ * The {@code newLength} argument must be greater than or equal
+ * to {@code 0}.
*
* @param newLength the new length
* @throws IndexOutOfBoundsException if the
- * <code>newLength</code> argument is negative.
+ * {@code newLength} argument is negative.
*/
public void setLength(int newLength) {
if (newLength < 0)
@@ -182,21 +182,21 @@
}
/**
- * Returns the <code>char</code> value in this sequence at the specified index.
- * The first <code>char</code> value is at index <code>0</code>, the next at index
- * <code>1</code>, and so on, as in array indexing.
+ * Returns the {@code char} value in this sequence at the specified index.
+ * The first {@code char} value is at index {@code 0}, the next at index
+ * {@code 1}, and so on, as in array indexing.
* <p>
* The index argument must be greater than or equal to
- * <code>0</code>, and less than the length of this sequence.
+ * {@code 0}, and less than the length of this sequence.
*
- * <p>If the <code>char</code> value specified by the index is a
+ * <p>If the {@code char} value specified by the index is a
* <a href="Character.html#unicode">surrogate</a>, the surrogate
* value is returned.
*
- * @param index the index of the desired <code>char</code> value.
- * @return the <code>char</code> value at the specified index.
- * @throws IndexOutOfBoundsException if <code>index</code> is
- * negative or greater than or equal to <code>length()</code>.
+ * @param index the index of the desired {@code char} value.
+ * @return the {@code char} value at the specified index.
+ * @throws IndexOutOfBoundsException if {@code index} is
+ * negative or greater than or equal to {@code length()}.
*/
public char charAt(int index) {
if ((index < 0) || (index >= count))
@@ -206,22 +206,22 @@
/**
* Returns the character (Unicode code point) at the specified
- * index. The index refers to <code>char</code> values
- * (Unicode code units) and ranges from <code>0</code> to
- * {@link #length()}<code> - 1</code>.
+ * index. The index refers to {@code char} values
+ * (Unicode code units) and ranges from {@code 0} to
+ * {@link #length()}{@code - 1}.
*
- * <p> If the <code>char</code> value specified at the given index
+ * <p> If the {@code char} value specified at the given index
* is in the high-surrogate range, the following index is less
* than the length of this sequence, and the
- * <code>char</code> value at the following index is in the
+ * {@code char} value at the following index is in the
* low-surrogate range, then the supplementary code point
* corresponding to this surrogate pair is returned. Otherwise,
- * the <code>char</code> value at the given index is returned.
+ * the {@code char} value at the given index is returned.
*
- * @param index the index to the <code>char</code> values
+ * @param index the index to the {@code char} values
* @return the code point value of the character at the
- * <code>index</code>
- * @exception IndexOutOfBoundsException if the <code>index</code>
+ * {@code index}
+ * @exception IndexOutOfBoundsException if the {@code index}
* argument is negative or not less than the length of this
* sequence.
*/
@@ -234,22 +234,22 @@
/**
* Returns the character (Unicode code point) before the specified
- * index. The index refers to <code>char</code> values
- * (Unicode code units) and ranges from <code>1</code> to {@link
+ * index. The index refers to {@code char} values
+ * (Unicode code units) and ranges from {@code 1} to {@link
* #length()}.
*
- * <p> If the <code>char</code> value at <code>(index - 1)</code>
- * is in the low-surrogate range, <code>(index - 2)</code> is not
- * negative, and the <code>char</code> value at <code>(index -
- * 2)</code> is in the high-surrogate range, then the
+ * <p> If the {@code char} value at {@code (index - 1)}
+ * is in the low-surrogate range, {@code (index - 2)} is not
+ * negative, and the {@code char} value at {@code (index -
+ * 2)} is in the high-surrogate range, then the
* supplementary code point value of the surrogate pair is
- * returned. If the <code>char</code> value at <code>index -
- * 1</code> is an unpaired low-surrogate or a high-surrogate, the
+ * returned. If the {@code char} value at {@code index -
+ * 1} is an unpaired low-surrogate or a high-surrogate, the
* surrogate value is returned.
*
* @param index the index following the code point that should be returned
* @return the Unicode code point value before the given index.
- * @exception IndexOutOfBoundsException if the <code>index</code>
+ * @exception IndexOutOfBoundsException if the {@code index}
* argument is less than 1 or greater than the length
* of this sequence.
*/
@@ -264,22 +264,22 @@
/**
* Returns the number of Unicode code points in the specified text
* range of this sequence. The text range begins at the specified
- * <code>beginIndex</code> and extends to the <code>char</code> at
- * index <code>endIndex - 1</code>. Thus the length (in
- * <code>char</code>s) of the text range is
- * <code>endIndex-beginIndex</code>. Unpaired surrogates within
+ * {@code beginIndex} and extends to the {@code char} at
+ * index {@code endIndex - 1}. Thus the length (in
+ * {@code char}s) of the text range is
+ * {@code endIndex-beginIndex}. Unpaired surrogates within
* this sequence count as one code point each.
*
- * @param beginIndex the index to the first <code>char</code> of
+ * @param beginIndex the index to the first {@code char} of
* the text range.
- * @param endIndex the index after the last <code>char</code> of
+ * @param endIndex the index after the last {@code char} of
* the text range.
* @return the number of Unicode code points in the specified text
* range
* @exception IndexOutOfBoundsException if the
- * <code>beginIndex</code> is negative, or <code>endIndex</code>
+ * {@code beginIndex} is negative, or {@code endIndex}
* is larger than the length of this sequence, or
- * <code>beginIndex</code> is larger than <code>endIndex</code>.
+ * {@code beginIndex} is larger than {@code endIndex}.
*/
public int codePointCount(int beginIndex, int endIndex) {
if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
@@ -290,22 +290,22 @@
/**
* Returns the index within this sequence that is offset from the
- * given <code>index</code> by <code>codePointOffset</code> code
+ * given {@code index} by {@code codePointOffset} code
* points. Unpaired surrogates within the text range given by
- * <code>index</code> and <code>codePointOffset</code> count as
+ * {@code index} and {@code codePointOffset} count as
* one code point each.
*
* @param index the index to be offset
* @param codePointOffset the offset in code points
* @return the index within this sequence
- * @exception IndexOutOfBoundsException if <code>index</code>
+ * @exception IndexOutOfBoundsException if {@code index}
* is negative or larger then the length of this sequence,
- * or if <code>codePointOffset</code> is positive and the subsequence
- * starting with <code>index</code> has fewer than
- * <code>codePointOffset</code> code points,
- * or if <code>codePointOffset</code> is negative and the subsequence
- * before <code>index</code> has fewer than the absolute value of
- * <code>codePointOffset</code> code points.
+ * or if {@code codePointOffset} is positive and the subsequence
+ * starting with {@code index} has fewer than
+ * {@code codePointOffset} code points,
+ * or if {@code codePointOffset} is negative and the subsequence
+ * before {@code index} has fewer than the absolute value of
+ * {@code codePointOffset} code points.
*/
public int offsetByCodePoints(int index, int codePointOffset) {
if (index < 0 || index > count) {
@@ -317,12 +317,12 @@
/**
* Characters are copied from this sequence into the
- * destination character array <code>dst</code>. The first character to
- * be copied is at index <code>srcBegin</code>; the last character to
- * be copied is at index <code>srcEnd-1</code>. The total number of
- * characters to be copied is <code>srcEnd-srcBegin</code>. The
- * characters are copied into the subarray of <code>dst</code> starting
- * at index <code>dstBegin</code> and ending at index:
+ * destination character array {@code dst}. The first character to
+ * be copied is at index {@code srcBegin}; the last character to
+ * be copied is at index {@code srcEnd-1}. The total number of
+ * characters to be copied is {@code srcEnd-srcBegin}. The
+ * characters are copied into the subarray of {@code dst} starting
+ * at index {@code dstBegin} and ending at index:
* <p><blockquote><pre>
* dstbegin + (srcEnd-srcBegin) - 1
* </pre></blockquote>
@@ -330,19 +330,19 @@
* @param srcBegin start copying at this offset.
* @param srcEnd stop copying at this offset.
* @param dst the array to copy the data into.
- * @param dstBegin offset into <code>dst</code>.
- * @throws NullPointerException if <code>dst</code> is
- * <code>null</code>.
+ * @param dstBegin offset into {@code dst}.
+ * @throws NullPointerException if {@code dst} is
+ * {@code null}.
* @throws IndexOutOfBoundsException if any of the following is true:
* <ul>
- * <li><code>srcBegin</code> is negative
- * <li><code>dstBegin</code> is negative
- * <li>the <code>srcBegin</code> argument is greater than
- * the <code>srcEnd</code> argument.
- * <li><code>srcEnd</code> is greater than
- * <code>this.length()</code>.
- * <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
- * <code>dst.length</code>
+ * <li>{@code srcBegin} is negative
+ * <li>{@code dstBegin} is negative
+ * <li>the {@code srcBegin} argument is greater than
+ * the {@code srcEnd} argument.
+ * <li>{@code srcEnd} is greater than
+ * {@code this.length()}.
+ * <li>{@code dstBegin+srcEnd-srcBegin} is greater than
+ * {@code dst.length}
* </ul>
*/
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
@@ -357,18 +357,18 @@
}
/**
- * The character at the specified index is set to <code>ch</code>. This
+ * The character at the specified index is set to {@code ch}. This
* sequence is altered to represent a new character sequence that is
* identical to the old character sequence, except that it contains the
- * character <code>ch</code> at position <code>index</code>.
+ * character {@code ch} at position {@code index}.
* <p>
* The index argument must be greater than or equal to
- * <code>0</code>, and less than the length of this sequence.
+ * {@code 0}, and less than the length of this sequence.
*
* @param index the index of the character to modify.
* @param ch the new character.
- * @throws IndexOutOfBoundsException if <code>index</code> is
- * negative or greater than or equal to <code>length()</code>.
+ * @throws IndexOutOfBoundsException if {@code index} is
+ * negative or greater than or equal to {@code length()}.
*/
public void setCharAt(int index, char ch) {
if ((index < 0) || (index >= count))
@@ -741,21 +741,21 @@
}
/**
- * Removes the <code>char</code> at the specified position in this
- * sequence. This sequence is shortened by one <code>char</code>.
+ * Removes the {@code char} at the specified position in this
+ * sequence. This sequence is shortened by one {@code char}.
*
* <p>Note: If the character at the given index is a supplementary
* character, this method does not remove the entire character. If
* correct handling of supplementary characters is required,
- * determine the number of <code>char</code>s to remove by calling
- * <code>Character.charCount(thisSequence.codePointAt(index))</code>,
- * where <code>thisSequence</code> is this sequence.
+ * determine the number of {@code char}s to remove by calling
+ * {@code Character.charCount(thisSequence.codePointAt(index))},
+ * where {@code thisSequence} is this sequence.
*
- * @param index Index of <code>char</code> to remove
+ * @param index Index of {@code char} to remove
* @return This object.
- * @throws StringIndexOutOfBoundsException if the <code>index</code>
+ * @throws StringIndexOutOfBoundsException if the {@code index}
* is negative or greater than or equal to
- * <code>length()</code>.
+ * {@code length()}.
*/
public AbstractStringBuilder deleteCharAt(int index) {
if ((index < 0) || (index >= count))
@@ -767,12 +767,12 @@
/**
* Replaces the characters in a substring of this sequence
- * with characters in the specified <code>String</code>. The substring
- * begins at the specified <code>start</code> and extends to the character
- * at index <code>end - 1</code> or to the end of the
+ * with characters in the specified {@code String}. The substring
+ * begins at the specified {@code start} and extends to the character
+ * at index {@code end - 1} or to the end of the
* sequence if no such character exists. First the
* characters in the substring are removed and then the specified
- * <code>String</code> is inserted at <code>start</code>. (This
+ * {@code String} is inserted at {@code start}. (This
* sequence will be lengthened to accommodate the
* specified String if necessary.)
*
@@ -780,9 +780,9 @@
* @param end The ending index, exclusive.
* @param str String that will replace previous contents.
* @return This object.
- * @throws StringIndexOutOfBoundsException if <code>start</code>
- * is negative, greater than <code>length()</code>, or
- * greater than <code>end</code>.
+ * @throws StringIndexOutOfBoundsException if {@code start}
+ * is negative, greater than {@code length()}, or
+ * greater than {@code end}.
*/
public AbstractStringBuilder replace(int start, int end, String str) {
if (start < 0)
@@ -805,14 +805,14 @@
}
/**
- * Returns a new <code>String</code> that contains a subsequence of
+ * Returns a new {@code String} that contains a subsequence of
* characters currently contained in this character sequence. The
* substring begins at the specified index and extends to the end of
* this sequence.
*
* @param start The beginning index, inclusive.
* @return The new string.
- * @throws StringIndexOutOfBoundsException if <code>start</code> is
+ * @throws StringIndexOutOfBoundsException if {@code start} is
* less than zero, or greater than the length of this object.
*/
public String substring(int start) {
@@ -850,18 +850,18 @@
}
/**
- * Returns a new <code>String</code> that contains a subsequence of
+ * Returns a new {@code String} that contains a subsequence of
* characters currently contained in this sequence. The
- * substring begins at the specified <code>start</code> and
- * extends to the character at index <code>end - 1</code>.
+ * substring begins at the specified {@code start} and
+ * extends to the character at index {@code end - 1}.
*
* @param start The beginning index, inclusive.
* @param end The ending index, exclusive.
* @return The new string.
- * @throws StringIndexOutOfBoundsException if <code>start</code>
- * or <code>end</code> are negative or greater than
- * <code>length()</code>, or <code>start</code> is
- * greater than <code>end</code>.
+ * @throws StringIndexOutOfBoundsException if {@code start}
+ * or {@code end} are negative or greater than
+ * {@code length()}, or {@code start} is
+ * greater than {@code end}.
*/
public String substring(int start, int end) {
if (start < 0)
@@ -1254,15 +1254,15 @@
* <blockquote><pre>
* this.toString().startsWith(str, <i>k</i>)
* </pre></blockquote>
- * is <code>true</code>.
+ * is {@code true}.
*
* @param str any string.
* @return if the string argument occurs as a substring within this
* object, then the index of the first character of the first
* such substring is returned; if it does not occur as a
- * substring, <code>-1</code> is returned.
- * @throws java.lang.NullPointerException if <code>str</code> is
- * <code>null</code>.
+ * substring, {@code -1} is returned.
+ * @throws java.lang.NullPointerException if {@code str} is
+ * {@code null}.
*/
public int indexOf(String str) {
return indexOf(str, 0);
@@ -1282,8 +1282,8 @@
* @param fromIndex the index from which to start the search.
* @return the index within this string of the first occurrence of the
* specified substring, starting at the specified index.
- * @throws java.lang.NullPointerException if <code>str</code> is
- * <code>null</code>.
+ * @throws java.lang.NullPointerException if {@code str} is
+ * {@code null}.
*/
public int indexOf(String str, int fromIndex) {
return String.indexOf(value, 0, count,
@@ -1293,7 +1293,7 @@
/**
* Returns the index within this string of the rightmost occurrence
* of the specified substring. The rightmost empty string "" is
- * considered to occur at the index value <code>this.length()</code>.
+ * considered to occur at the index value {@code this.length()}.
* The returned index is the largest value <i>k</i> such that
* <blockquote><pre>
* this.toString().startsWith(str, k)
@@ -1304,9 +1304,9 @@
* @return if the string argument occurs one or more times as a substring
* within this object, then the index of the first character of
* the last such substring is returned. If it does not occur as
- * a substring, <code>-1</code> is returned.
- * @throws java.lang.NullPointerException if <code>str</code> is
- * <code>null</code>.
+ * a substring, {@code -1} is returned.
+ * @throws java.lang.NullPointerException if {@code str} is
+ * {@code null}.
*/
public int lastIndexOf(String str) {
return lastIndexOf(str, count);
@@ -1326,8 +1326,8 @@
* @param fromIndex the index to start the search from.
* @return the index within this sequence of the last occurrence of the
* specified substring.
- * @throws java.lang.NullPointerException if <code>str</code> is
- * <code>null</code>.
+ * @throws java.lang.NullPointerException if {@code str} is
+ * {@code null}.
*/
public int lastIndexOf(String str, int fromIndex) {
return String.lastIndexOf(value, 0, count,
@@ -1342,8 +1342,8 @@
* is never reversed.
*
* Let <i>n</i> be the character length of this character sequence
- * (not the length in <code>char</code> values) just prior to
- * execution of the <code>reverse</code> method. Then the
+ * (not the length in {@code char} values) just prior to
+ * execution of the {@code reverse} method. Then the
* character at index <i>k</i> in the new character sequence is
* equal to the character at index <i>n-k-1</i> in the old
* character sequence.
@@ -1351,7 +1351,7 @@
* <p>Note that the reverse operation may result in producing
* surrogate pairs that were unpaired low-surrogates and
* high-surrogates before the operation. For example, reversing
- * "\uDC00\uD800" produces "\uD800\uDC00" which is
+ * "\u005CuDC00\u005CuD800" produces "\u005CuD800\u005CuDC00" which is
* a valid surrogate pair.
*
* @return a reference to this object.
@@ -1387,11 +1387,11 @@
/**
* Returns a string representing the data in this sequence.
- * A new <code>String</code> object is allocated and initialized to
+ * A new {@code String} object is allocated and initialized to
* contain the character sequence currently represented by this
- * object. This <code>String</code> is then returned. Subsequent
+ * object. This {@code String} is then returned. Subsequent
* changes to this sequence do not affect the contents of the
- * <code>String</code>.
+ * {@code String}.
*
* @return a string representation of this sequence of characters.
*/
--- a/jdk/src/share/classes/java/lang/Byte.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/lang/Byte.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2012, 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
@@ -110,8 +110,8 @@
* determined by whether {@link java.lang.Character#digit(char,
* int)} returns a nonnegative value) except that the first
* character may be an ASCII minus sign {@code '-'}
- * (<code>'\u002D'</code>) to indicate a negative value or an
- * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
+ * ({@code '\u005Cu002D'}) to indicate a negative value or an
+ * ASCII plus sign {@code '+'} ({@code '\u005Cu002B'}) to
* indicate a positive value. The resulting {@code byte} value is
* returned.
*
@@ -127,8 +127,8 @@
*
* <li> Any character of the string is not a digit of the
* specified radix, except that the first character may be a minus
- * sign {@code '-'} (<code>'\u002D'</code>) or plus sign
- * {@code '+'} (<code>'\u002B'</code>) provided that the
+ * sign {@code '-'} ({@code '\u005Cu002D'}) or plus sign
+ * {@code '+'} ({@code '\u005Cu002B'}) provided that the
* string is longer than length 1.
*
* <li> The value represented by the string is not a value of type
@@ -157,9 +157,9 @@
* Parses the string argument as a signed decimal {@code
* byte}. The characters in the string must all be decimal digits,
* except that the first character may be an ASCII minus sign
- * {@code '-'} (<code>'\u002D'</code>) to indicate a negative
+ * {@code '-'} ({@code '\u005Cu002D'}) to indicate a negative
* value or an ASCII plus sign {@code '+'}
- * (<code>'\u002B'</code>) to indicate a positive value. The
+ * ({@code '\u005Cu002B'}) to indicate a positive value. The
* resulting {@code byte} value is returned, exactly as if the
* argument and the radix 10 were given as arguments to the {@link
* #parseByte(java.lang.String, int)} method.
@@ -446,6 +446,47 @@
}
/**
+ * Converts the argument to an {@code int} by an unsigned
+ * conversion. In an unsigned conversion to an {@code int}, the
+ * high-order 24 bits of the {@code int} are zero and the
+ * low-order 8 bits are equal to the bits of the {@code byte} argument.
+ *
+ * Consequently, zero and positive {@code byte} values are mapped
+ * to a numerically equal {@code int} value and negative {@code
+ * byte} values are mapped to an {@code int} value equal to the
+ * input plus 2<sup>8</sup>.
+ *
+ * @param x the value to convert to an unsigned {@code int}
+ * @return the argument converted to {@code int} by an unsigned
+ * conversion
+ * @since 1.8
+ */
+ public static int toUnsignedInt(byte x) {
+ return ((int) x) & 0xff;
+ }
+
+ /**
+ * Converts the argument to a {@code long} by an unsigned
+ * conversion. In an unsigned conversion to a {@code long}, the
+ * high-order 56 bits of the {@code long} are zero and the
+ * low-order 8 bits are equal to the bits of the {@code byte} argument.
+ *
+ * Consequently, zero and positive {@code byte} values are mapped
+ * to a numerically equal {@code long} value and negative {@code
+ * byte} values are mapped to a {@code long} value equal to the
+ * input plus 2<sup>8</sup>.
+ *
+ * @param x the value to convert to an unsigned {@code long}
+ * @return the argument converted to {@code long} by an unsigned
+ * conversion
+ * @since 1.8
+ */
+ public static long toUnsignedLong(byte x) {
+ return ((long) x) & 0xffL;
+ }
+
+
+ /**
* The number of bits used to represent a {@code byte} value in two's
* complement binary form.
*
--- a/jdk/src/share/classes/java/lang/Double.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/lang/Double.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2012, 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
@@ -140,7 +140,7 @@
* <li>Otherwise, the result is a string that represents the sign and
* magnitude (absolute value) of the argument. If the sign is negative,
* the first character of the result is '{@code -}'
- * (<code>'\u002D'</code>); if the sign is positive, no sign character
+ * ({@code '\u005Cu002D'}); if the sign is positive, no sign character
* appears in the result. As for the magnitude <i>m</i>:
* <ul>
* <li>If <i>m</i> is infinity, it is represented by the characters
@@ -156,7 +156,7 @@
* <li>If <i>m</i> is greater than or equal to 10<sup>-3</sup> but less
* than 10<sup>7</sup>, then it is represented as the integer part of
* <i>m</i>, in decimal form with no leading zeroes, followed by
- * '{@code .}' (<code>'\u002E'</code>), followed by one or
+ * '{@code .}' ({@code '\u005Cu002E'}), followed by one or
* more decimal digits representing the fractional part of <i>m</i>.
*
* <li>If <i>m</i> is less than 10<sup>-3</sup> or greater than or
@@ -168,9 +168,9 @@
* 10<sup><i>n</i></sup> so that 1 ≤ <i>a</i> {@literal <} 10. The
* magnitude is then represented as the integer part of <i>a</i>,
* as a single decimal digit, followed by '{@code .}'
- * (<code>'\u002E'</code>), followed by decimal digits
+ * ({@code '\u005Cu002E'}), followed by decimal digits
* representing the fractional part of <i>a</i>, followed by the
- * letter '{@code E}' (<code>'\u0045'</code>), followed
+ * letter '{@code E}' ({@code '\u005Cu0045'}), followed
* by a representation of <i>n</i> as a decimal integer, as
* produced by the method {@link Integer#toString(int)}.
* </ul>
@@ -208,7 +208,7 @@
* <li>Otherwise, the result is a string that represents the sign
* and magnitude of the argument. If the sign is negative, the
* first character of the result is '{@code -}'
- * (<code>'\u002D'</code>); if the sign is positive, no sign
+ * ({@code '\u005Cu002D'}); if the sign is positive, no sign
* character appears in the result. As for the magnitude <i>m</i>:
*
* <ul>
--- a/jdk/src/share/classes/java/lang/Float.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/lang/Float.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2012, 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
@@ -138,7 +138,7 @@
* <li>Otherwise, the result is a string that represents the sign and
* magnitude (absolute value) of the argument. If the sign is
* negative, the first character of the result is
- * '{@code -}' (<code>'\u002D'</code>); if the sign is
+ * '{@code -}' ({@code '\u005Cu002D'}); if the sign is
* positive, no sign character appears in the result. As for
* the magnitude <i>m</i>:
* <ul>
@@ -154,7 +154,7 @@
* less than 10<sup>7</sup>, then it is represented as the
* integer part of <i>m</i>, in decimal form with no leading
* zeroes, followed by '{@code .}'
- * (<code>'\u002E'</code>), followed by one or more
+ * ({@code '\u005Cu002E'}), followed by one or more
* decimal digits representing the fractional part of
* <i>m</i>.
* <li> If <i>m</i> is less than 10<sup>-3</sup> or greater than or
@@ -166,10 +166,10 @@
* 10<sup><i>n</i></sup> so that 1 ≤ <i>a</i> {@literal <} 10.
* The magnitude is then represented as the integer part of
* <i>a</i>, as a single decimal digit, followed by
- * '{@code .}' (<code>'\u002E'</code>), followed by
+ * '{@code .}' ({@code '\u005Cu002E'}), followed by
* decimal digits representing the fractional part of
* <i>a</i>, followed by the letter '{@code E}'
- * (<code>'\u0045'</code>), followed by a representation
+ * ({@code '\u005Cu0045'}), followed by a representation
* of <i>n</i> as a decimal integer, as produced by the
* method {@link java.lang.Integer#toString(int)}.
*
@@ -210,7 +210,7 @@
* <li>Otherwise, the result is a string that represents the sign and
* magnitude (absolute value) of the argument. If the sign is negative,
* the first character of the result is '{@code -}'
- * (<code>'\u002D'</code>); if the sign is positive, no sign character
+ * ({@code '\u005Cu002D'}); if the sign is positive, no sign character
* appears in the result. As for the magnitude <i>m</i>:
*
* <ul>
--- a/jdk/src/share/classes/java/lang/Integer.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/lang/Integer.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2012, 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
@@ -93,13 +93,13 @@
*
* <p>If the first argument is negative, the first element of the
* result is the ASCII minus character {@code '-'}
- * (<code>'\u002D'</code>). If the first argument is not
+ * ({@code '\u005Cu002D'}). If the first argument is not
* negative, no sign character appears in the result.
*
* <p>The remaining characters of the result represent the magnitude
* of the first argument. If the magnitude is zero, it is
* represented by a single zero character {@code '0'}
- * (<code>'\u0030'</code>); otherwise, the first character of
+ * ({@code '\u005Cu0030'}); otherwise, the first character of
* the representation of the magnitude will not be the zero
* character. The following ASCII characters are used as digits:
*
@@ -107,9 +107,9 @@
* {@code 0123456789abcdefghijklmnopqrstuvwxyz}
* </blockquote>
*
- * These are <code>'\u0030'</code> through
- * <code>'\u0039'</code> and <code>'\u0061'</code> through
- * <code>'\u007A'</code>. If {@code radix} is
+ * These are {@code '\u005Cu0030'} through
+ * {@code '\u005Cu0039'} and {@code '\u005Cu0061'} through
+ * {@code '\u005Cu007A'}. If {@code radix} is
* <var>N</var>, then the first <var>N</var> of these characters
* are used as radix-<var>N</var> digits in the order shown. Thus,
* the digits for hexadecimal (radix 16) are
@@ -128,7 +128,6 @@
* @see java.lang.Character#MIN_RADIX
*/
public static String toString(int i, int radix) {
-
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
radix = 10;
@@ -159,6 +158,36 @@
}
/**
+ * Returns a string representation of the first argument as an
+ * unsigned integer value in the radix specified by the second
+ * argument.
+ *
+ * <p>If the radix is smaller than {@code Character.MIN_RADIX}
+ * or larger than {@code Character.MAX_RADIX}, then the radix
+ * {@code 10} is used instead.
+ *
+ * <p>Note that since the first argument is treated as an unsigned
+ * value, no leading sign character is printed.
+ *
+ * <p>If the magnitude is zero, it is represented by a single zero
+ * character {@code '0'} ({@code '\u005Cu0030'}); otherwise,
+ * the first character of the representation of the magnitude will
+ * not be the zero character.
+ *
+ * <p>The behavior of radixes and the characters used as digits
+ * are the same as {@link #toString(int, int) toString}.
+ *
+ * @param i an integer to be converted to an unsigned string.
+ * @param radix the radix to use in the string representation.
+ * @return an unsigned string representation of the argument in the specified radix.
+ * @see #toString(int, int)
+ * @since 1.8
+ */
+ public static String toUnsignedString(int i, int radix) {
+ return Long.toString(toUnsignedLong(i), radix);
+ }
+
+ /**
* Returns a string representation of the integer argument as an
* unsigned integer in base 16.
*
@@ -166,20 +195,26 @@
* if the argument is negative; otherwise, it is equal to the
* argument. This value is converted to a string of ASCII digits
* in hexadecimal (base 16) with no extra leading
- * {@code 0}s. If the unsigned magnitude is zero, it is
- * represented by a single zero character {@code '0'}
- * (<code>'\u0030'</code>); otherwise, the first character of
- * the representation of the unsigned magnitude will not be the
- * zero character. The following characters are used as
- * hexadecimal digits:
+ * {@code 0}s.
+ *
+ * <p>The value of the argument can be recovered from the returned
+ * string {@code s} by calling {@link
+ * Integer#parseUnsignedInt(String, int)
+ * Integer.parseUnsignedInt(s, 16)}.
+ *
+ * <p>If the unsigned magnitude is zero, it is represented by a
+ * single zero character {@code '0'} ({@code '\u005Cu0030'});
+ * otherwise, the first character of the representation of the
+ * unsigned magnitude will not be the zero character. The
+ * following characters are used as hexadecimal digits:
*
* <blockquote>
* {@code 0123456789abcdef}
* </blockquote>
*
- * These are the characters <code>'\u0030'</code> through
- * <code>'\u0039'</code> and <code>'\u0061'</code> through
- * <code>'\u0066'</code>. If uppercase letters are
+ * These are the characters {@code '\u005Cu0030'} through
+ * {@code '\u005Cu0039'} and {@code '\u005Cu0061'} through
+ * {@code '\u005Cu0066'}. If uppercase letters are
* desired, the {@link java.lang.String#toUpperCase()} method may
* be called on the result:
*
@@ -190,10 +225,12 @@
* @param i an integer to be converted to a string.
* @return the string representation of the unsigned integer value
* represented by the argument in hexadecimal (base 16).
+ * @see #parseUnsignedInt(String, int)
+ * @see #toUnsignedString(int, int)
* @since JDK1.0.2
*/
public static String toHexString(int i) {
- return toUnsignedString(i, 4);
+ return toUnsignedString0(i, 4);
}
/**
@@ -205,27 +242,33 @@
* argument. This value is converted to a string of ASCII digits
* in octal (base 8) with no extra leading {@code 0}s.
*
+ * <p>The value of the argument can be recovered from the returned
+ * string {@code s} by calling {@link
+ * Integer#parseUnsignedInt(String, int)
+ * Integer.parseUnsignedInt(s, 8)}.
+ *
* <p>If the unsigned magnitude is zero, it is represented by a
- * single zero character {@code '0'}
- * (<code>'\u0030'</code>); otherwise, the first character of
- * the representation of the unsigned magnitude will not be the
- * zero character. The following characters are used as octal
- * digits:
+ * single zero character {@code '0'} ({@code '\u005Cu0030'});
+ * otherwise, the first character of the representation of the
+ * unsigned magnitude will not be the zero character. The
+ * following characters are used as octal digits:
*
* <blockquote>
* {@code 01234567}
* </blockquote>
*
- * These are the characters <code>'\u0030'</code> through
- * <code>'\u0037'</code>.
+ * These are the characters {@code '\u005Cu0030'} through
+ * {@code '\u005Cu0037'}.
*
* @param i an integer to be converted to a string.
* @return the string representation of the unsigned integer value
* represented by the argument in octal (base 8).
+ * @see #parseUnsignedInt(String, int)
+ * @see #toUnsignedString(int, int)
* @since JDK1.0.2
*/
public static String toOctalString(int i) {
- return toUnsignedString(i, 3);
+ return toUnsignedString0(i, 3);
}
/**
@@ -236,27 +279,34 @@
* if the argument is negative; otherwise it is equal to the
* argument. This value is converted to a string of ASCII digits
* in binary (base 2) with no extra leading {@code 0}s.
- * If the unsigned magnitude is zero, it is represented by a
- * single zero character {@code '0'}
- * (<code>'\u0030'</code>); otherwise, the first character of
- * the representation of the unsigned magnitude will not be the
- * zero character. The characters {@code '0'}
- * (<code>'\u0030'</code>) and {@code '1'}
- * (<code>'\u0031'</code>) are used as binary digits.
+ *
+ * <p>The value of the argument can be recovered from the returned
+ * string {@code s} by calling {@link
+ * Integer#parseUnsignedInt(String, int)
+ * Integer.parseUnsignedInt(s, 2)}.
+ *
+ * <p>If the unsigned magnitude is zero, it is represented by a
+ * single zero character {@code '0'} ({@code '\u005Cu0030'});
+ * otherwise, the first character of the representation of the
+ * unsigned magnitude will not be the zero character. The
+ * characters {@code '0'} ({@code '\u005Cu0030'}) and {@code
+ * '1'} ({@code '\u005Cu0031'}) are used as binary digits.
*
* @param i an integer to be converted to a string.
* @return the string representation of the unsigned integer value
* represented by the argument in binary (base 2).
+ * @see #parseUnsignedInt(String, int)
+ * @see #toUnsignedString(int, int)
* @since JDK1.0.2
*/
public static String toBinaryString(int i) {
- return toUnsignedString(i, 1);
+ return toUnsignedString0(i, 1);
}
/**
* Convert the integer to an unsigned number.
*/
- private static String toUnsignedString(int i, int shift) {
+ private static String toUnsignedString0(int i, int shift) {
char[] buf = new char[32];
int charPos = 32;
int radix = 1 << shift;
@@ -335,6 +385,24 @@
}
/**
+ * Returns a string representation of the argument as an unsigned
+ * decimal value.
+ *
+ * The argument is converted to unsigned decimal representation
+ * and returned as a string exactly as if the argument and radix
+ * 10 were given as arguments to the {@link #toUnsignedString(int,
+ * int)} method.
+ *
+ * @param i an integer to be converted to an unsigned string.
+ * @return an unsigned string representation of the argument.
+ * @see #toUnsignedString(int, int)
+ * @since 1.8
+ */
+ public static String toUnsignedString(int i) {
+ return Long.toString(toUnsignedLong(i));
+ }
+
+ /**
* Places characters representing the integer i into the
* character array buf. The characters are placed into
* the buffer backwards starting with the least significant
@@ -393,9 +461,9 @@
* must all be digits of the specified radix (as determined by
* whether {@link java.lang.Character#digit(char, int)} returns a
* nonnegative value), except that the first character may be an
- * ASCII minus sign {@code '-'} (<code>'\u002D'</code>) to
+ * ASCII minus sign {@code '-'} ({@code '\u005Cu002D'}) to
* indicate a negative value or an ASCII plus sign {@code '+'}
- * (<code>'\u002B'</code>) to indicate a positive value. The
+ * ({@code '\u005Cu002B'}) to indicate a positive value. The
* resulting integer value is returned.
*
* <p>An exception of type {@code NumberFormatException} is
@@ -410,8 +478,8 @@
*
* <li>Any character of the string is not a digit of the specified
* radix, except that the first character may be a minus sign
- * {@code '-'} (<code>'\u002D'</code>) or plus sign
- * {@code '+'} (<code>'\u002B'</code>) provided that the
+ * {@code '-'} ({@code '\u005Cu002D'}) or plus sign
+ * {@code '+'} ({@code '\u005Cu002B'}) provided that the
* string is longer than length 1.
*
* <li>The value represented by the string is not a value of type
@@ -511,8 +579,8 @@
* Parses the string argument as a signed decimal integer. The
* characters in the string must all be decimal digits, except
* that the first character may be an ASCII minus sign {@code '-'}
- * (<code>'\u002D'</code>) to indicate a negative value or an
- * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
+ * ({@code '\u005Cu002D'}) to indicate a negative value or an
+ * ASCII plus sign {@code '+'} ({@code '\u005Cu002B'}) to
* indicate a positive value. The resulting integer value is
* returned, exactly as if the argument and the radix 10 were
* given as arguments to the {@link #parseInt(java.lang.String,
@@ -529,6 +597,102 @@
}
/**
+ * Parses the string argument as an unsigned integer in the radix
+ * specified by the second argument. An unsigned integer maps the
+ * values usually associated with negative numbers to positive
+ * numbers larger than {@code MAX_VALUE}.
+ *
+ * The characters in the string must all be digits of the
+ * specified radix (as determined by whether {@link
+ * java.lang.Character#digit(char, int)} returns a nonnegative
+ * value), except that the first character may be an ASCII plus
+ * sign {@code '+'} ({@code '\u005Cu002B'}). The resulting
+ * integer value is returned.
+ *
+ * <p>An exception of type {@code NumberFormatException} is
+ * thrown if any of the following situations occurs:
+ * <ul>
+ * <li>The first argument is {@code null} or is a string of
+ * length zero.
+ *
+ * <li>The radix is either smaller than
+ * {@link java.lang.Character#MIN_RADIX} or
+ * larger than {@link java.lang.Character#MAX_RADIX}.
+ *
+ * <li>Any character of the string is not a digit of the specified
+ * radix, except that the first character may be a plus sign
+ * {@code '+'} ({@code '\u005Cu002B'}) provided that the
+ * string is longer than length 1.
+ *
+ * <li>The value represented by the string is larger than the
+ * largest unsigned {@code int}, 2<sup>32</sup>-1.
+ *
+ * </ul>
+ *
+ *
+ * @param s the {@code String} containing the unsigned integer
+ * representation to be parsed
+ * @param radix the radix to be used while parsing {@code s}.
+ * @return the integer represented by the string argument in the
+ * specified radix.
+ * @throws NumberFormatException if the {@code String}
+ * does not contain a parsable {@code int}.
+ * @since 1.8
+ */
+ public static int parseUnsignedInt(String s, int radix)
+ throws NumberFormatException {
+ if (s == null) {
+ throw new NumberFormatException("null");
+ }
+
+ int len = s.length();
+ if (len > 0) {
+ char firstChar = s.charAt(0);
+ if (firstChar == '-') {
+ throw new
+ NumberFormatException(String.format("Illegal leading minus sign " +
+ "on unsigned string %s.", s));
+ } else {
+ if (len <= 5 || // Integer.MAX_VALUE in Character.MAX_RADIX is 6 digits
+ (radix == 10 && len <= 9) ) { // Integer.MAX_VALUE in base 10 is 10 digits
+ return parseInt(s, radix);
+ } else {
+ long ell = Long.parseLong(s, radix);
+ if ((ell & 0xffff_ffff_0000_0000L) == 0) {
+ return (int) ell;
+ } else {
+ throw new
+ NumberFormatException(String.format("String value %s exceeds " +
+ "range of unsigned int.", s));
+ }
+ }
+ }
+ } else {
+ throw NumberFormatException.forInputString(s);
+ }
+ }
+
+ /**
+ * Parses the string argument as an unsigned decimal integer. The
+ * characters in the string must all be decimal digits, except
+ * that the first character may be an an ASCII plus sign {@code
+ * '+'} ({@code '\u005Cu002B'}). The resulting integer value
+ * is returned, exactly as if the argument and the radix 10 were
+ * given as arguments to the {@link
+ * #parseUnsignedInt(java.lang.String, int)} method.
+ *
+ * @param s a {@code String} containing the unsigned {@code int}
+ * representation to be parsed
+ * @return the unsigned integer value represented by the argument in decimal.
+ * @throws NumberFormatException if the string does not contain a
+ * parsable unsigned integer.
+ * @since 1.8
+ */
+ public static int parseUnsignedInt(String s) throws NumberFormatException {
+ return parseUnsignedInt(s, 10);
+ }
+
+ /**
* Returns an {@code Integer} object holding the value
* extracted from the specified {@code String} when parsed
* with the radix given by the second argument. The first argument
@@ -1030,6 +1194,83 @@
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
+ /**
+ * Compares two {@code int} values numerically treating the values
+ * as unsigned.
+ *
+ * @param x the first {@code int} to compare
+ * @param y the second {@code int} to compare
+ * @return the value {@code 0} if {@code x == y}; a value less
+ * than {@code 0} if {@code x < y} as unsigned values; and
+ * a value greater than {@code 0} if {@code x > y} as
+ * unsigned values
+ * @since 1.8
+ */
+ public static int compareUnsigned(int x, int y) {
+ return compare(x + MIN_VALUE, y + MIN_VALUE);
+ }
+
+ /**
+ * Converts the argument to a {@code long} by an unsigned
+ * conversion. In an unsigned conversion to a {@code long}, the
+ * high-order 32 bits of the {@code long} are zero and the
+ * low-order 32 bits are equal to the bits of the integer
+ * argument.
+ *
+ * Consequently, zero and positive {@code int} values are mapped
+ * to a numerically equal {@code long} value and negative {@code
+ * int} values are mapped to a {@code long} value equal to the
+ * input plus 2<sup>32</sup>.
+ *
+ * @param x the value to convert to an unsigned {@code long}
+ * @return the argument converted to {@code long} by an unsigned
+ * conversion
+ * @since 1.8
+ */
+ public static long toUnsignedLong(int x) {
+ return ((long) x) & 0xffffffffL;
+ }
+
+ /**
+ * Returns the unsigned quotient of dividing the first argument by
+ * the second where each argument and the result is interpreted as
+ * an unsigned value.
+ *
+ * <p>Note that in two's complement arithmetic, the three other
+ * basic arithmetic operations of add, subtract, and multiply are
+ * bit-wise identical if the two operands are regarded as both
+ * being signed or both being unsigned. Therefore separate {@code
+ * addUnsigned}, etc. methods are not provided.
+ *
+ * @param dividend the value to be divided
+ * @param divisor the value doing the dividing
+ * @return the unsigned quotient of the first argument divided by
+ * the second argument
+ * @see #remainderUnsigned
+ * @since 1.8
+ */
+ public static int divideUnsigned(int dividend, int divisor) {
+ // In lieu of tricky code, for now just use long arithmetic.
+ return (int)(toUnsignedLong(dividend) / toUnsignedLong(divisor));
+ }
+
+ /**
+ * Returns the unsigned remainder from dividing the first argument
+ * by the second where each argument and the result is interpreted
+ * as an unsigned value.
+ *
+ * @param dividend the value to be divided
+ * @param divisor the value doing the dividing
+ * @return the unsigned remainder of the first argument divided by
+ * the second argument
+ * @see #divideUnsigned
+ * @since 1.8
+ */
+ public static int remainderUnsigned(int dividend, int divisor) {
+ // In lieu of tricky code, for now just use long arithmetic.
+ return (int)(toUnsignedLong(dividend) % toUnsignedLong(divisor));
+ }
+
// Bit twiddling
--- a/jdk/src/share/classes/java/lang/Long.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/lang/Long.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2012, 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
@@ -25,6 +25,8 @@
package java.lang;
+import java.math.*;
+
/**
* The {@code Long} class wraps a value of the primitive type {@code
* long} in an object. An object of type {@code Long} contains a
@@ -79,13 +81,13 @@
*
* <p>If the first argument is negative, the first element of the
* result is the ASCII minus sign {@code '-'}
- * (<code>'\u002d'</code>). If the first argument is not
+ * ({@code '\u005Cu002d'}). If the first argument is not
* negative, no sign character appears in the result.
*
* <p>The remaining characters of the result represent the magnitude
* of the first argument. If the magnitude is zero, it is
* represented by a single zero character {@code '0'}
- * (<code>'\u0030'</code>); otherwise, the first character of
+ * ({@code '\u005Cu0030'}); otherwise, the first character of
* the representation of the magnitude will not be the zero
* character. The following ASCII characters are used as digits:
*
@@ -93,9 +95,9 @@
* {@code 0123456789abcdefghijklmnopqrstuvwxyz}
* </blockquote>
*
- * These are <code>'\u0030'</code> through
- * <code>'\u0039'</code> and <code>'\u0061'</code> through
- * <code>'\u007a'</code>. If {@code radix} is
+ * These are {@code '\u005Cu0030'} through
+ * {@code '\u005Cu0039'} and {@code '\u005Cu0061'} through
+ * {@code '\u005Cu007a'}. If {@code radix} is
* <var>N</var>, then the first <var>N</var> of these characters
* are used as radix-<var>N</var> digits in the order shown. Thus,
* the digits for hexadecimal (radix 16) are
@@ -140,6 +142,88 @@
}
/**
+ * Returns a string representation of the first argument as an
+ * unsigned integer value in the radix specified by the second
+ * argument.
+ *
+ * <p>If the radix is smaller than {@code Character.MIN_RADIX}
+ * or larger than {@code Character.MAX_RADIX}, then the radix
+ * {@code 10} is used instead.
+ *
+ * <p>Note that since the first argument is treated as an unsigned
+ * value, no leading sign character is printed.
+ *
+ * <p>If the magnitude is zero, it is represented by a single zero
+ * character {@code '0'} ({@code '\u005Cu0030'}); otherwise,
+ * the first character of the representation of the magnitude will
+ * not be the zero character.
+ *
+ * <p>The behavior of radixes and the characters used as digits
+ * are the same as {@link #toString(long, int) toString}.
+ *
+ * @param i an integer to be converted to an unsigned string.
+ * @param radix the radix to use in the string representation.
+ * @return an unsigned string representation of the argument in the specified radix.
+ * @see #toString(long, int)
+ * @since 1.8
+ */
+ public static String toUnsignedString(long i, int radix) {
+ if (i >= 0)
+ return toString(i, radix);
+ else {
+ switch (radix) {
+ case 2:
+ return toBinaryString(i);
+
+ case 4:
+ return toUnsignedString0(i, 2);
+
+ case 8:
+ return toOctalString(i);
+
+ case 10:
+ /*
+ * We can get the effect of an unsigned division by 10
+ * on a long value by first shifting right, yielding a
+ * positive value, and then dividing by 5. This
+ * allows the last digit and preceding digits to be
+ * isolated more quickly than by an initial conversion
+ * to BigInteger.
+ */
+ long quot = (i >>> 1) / 5;
+ long rem = i - quot * 10;
+ return toString(quot) + rem;
+
+ case 16:
+ return toHexString(i);
+
+ case 32:
+ return toUnsignedString0(i, 5);
+
+ default:
+ return toUnsignedBigInteger(i).toString(radix);
+ }
+ }
+ }
+
+ /**
+ * Return a BigInteger equal to the unsigned value of the
+ * argument.
+ */
+ private static BigInteger toUnsignedBigInteger(long i) {
+ if (i >= 0L)
+ return BigInteger.valueOf(i);
+ else {
+ int upper = (int) (i >>> 32);
+ int lower = (int) i;
+
+ // return (upper << 32) + lower
+ return (BigInteger.valueOf(Integer.toUnsignedLong(upper))).shiftLeft(32).
+ add(BigInteger.valueOf(Integer.toUnsignedLong(lower)));
+ }
+ }
+
+ /**
* Returns a string representation of the {@code long}
* argument as an unsigned integer in base 16.
*
@@ -147,20 +231,26 @@
* 2<sup>64</sup> if the argument is negative; otherwise, it is
* equal to the argument. This value is converted to a string of
* ASCII digits in hexadecimal (base 16) with no extra
- * leading {@code 0}s. If the unsigned magnitude is zero, it
- * is represented by a single zero character {@code '0'}
- * (<code>'\u0030'</code>); otherwise, the first character of
- * the representation of the unsigned magnitude will not be the
- * zero character. The following characters are used as
- * hexadecimal digits:
+ * leading {@code 0}s.
+ *
+ * <p>The value of the argument can be recovered from the returned
+ * string {@code s} by calling {@link
+ * Long#parseUnsignedLong(String, int) Long.parseUnsignedLong(s,
+ * 16)}.
+ *
+ * <p>If the unsigned magnitude is zero, it is represented by a
+ * single zero character {@code '0'} ({@code '\u005Cu0030'});
+ * otherwise, the first character of the representation of the
+ * unsigned magnitude will not be the zero character. The
+ * following characters are used as hexadecimal digits:
*
* <blockquote>
* {@code 0123456789abcdef}
* </blockquote>
*
- * These are the characters <code>'\u0030'</code> through
- * <code>'\u0039'</code> and <code>'\u0061'</code> through
- * <code>'\u0066'</code>. If uppercase letters are desired,
+ * These are the characters {@code '\u005Cu0030'} through
+ * {@code '\u005Cu0039'} and {@code '\u005Cu0061'} through
+ * {@code '\u005Cu0066'}. If uppercase letters are desired,
* the {@link java.lang.String#toUpperCase()} method may be called
* on the result:
*
@@ -172,10 +262,12 @@
* @return the string representation of the unsigned {@code long}
* value represented by the argument in hexadecimal
* (base 16).
+ * @see #parseUnsignedLong(String, int)
+ * @see #toUnsignedString(long, int)
* @since JDK 1.0.2
*/
public static String toHexString(long i) {
- return toUnsignedString(i, 4);
+ return toUnsignedString0(i, 4);
}
/**
@@ -188,27 +280,33 @@
* ASCII digits in octal (base 8) with no extra leading
* {@code 0}s.
*
+ * <p>The value of the argument can be recovered from the returned
+ * string {@code s} by calling {@link
+ * Long#parseUnsignedLong(String, int) Long.parseUnsignedLong(s,
+ * 8)}.
+ *
* <p>If the unsigned magnitude is zero, it is represented by a
- * single zero character {@code '0'}
- * (<code>'\u0030'</code>); otherwise, the first character of
- * the representation of the unsigned magnitude will not be the
- * zero character. The following characters are used as octal
- * digits:
+ * single zero character {@code '0'} ({@code '\u005Cu0030'});
+ * otherwise, the first character of the representation of the
+ * unsigned magnitude will not be the zero character. The
+ * following characters are used as octal digits:
*
* <blockquote>
* {@code 01234567}
* </blockquote>
*
- * These are the characters <code>'\u0030'</code> through
- * <code>'\u0037'</code>.
+ * These are the characters {@code '\u005Cu0030'} through
+ * {@code '\u005Cu0037'}.
*
* @param i a {@code long} to be converted to a string.
* @return the string representation of the unsigned {@code long}
* value represented by the argument in octal (base 8).
+ * @see #parseUnsignedLong(String, int)
+ * @see #toUnsignedString(long, int)
* @since JDK 1.0.2
*/
public static String toOctalString(long i) {
- return toUnsignedString(i, 3);
+ return toUnsignedString0(i, 3);
}
/**
@@ -219,27 +317,35 @@
* 2<sup>64</sup> if the argument is negative; otherwise, it is
* equal to the argument. This value is converted to a string of
* ASCII digits in binary (base 2) with no extra leading
- * {@code 0}s. If the unsigned magnitude is zero, it is
- * represented by a single zero character {@code '0'}
- * (<code>'\u0030'</code>); otherwise, the first character of
- * the representation of the unsigned magnitude will not be the
- * zero character. The characters {@code '0'}
- * (<code>'\u0030'</code>) and {@code '1'}
- * (<code>'\u0031'</code>) are used as binary digits.
+ * {@code 0}s.
+ *
+ * <p>The value of the argument can be recovered from the returned
+ * string {@code s} by calling {@link
+ * Long#parseUnsignedLong(String, int) Long.parseUnsignedLong(s,
+ * 2)}.
+ *
+ * <p>If the unsigned magnitude is zero, it is represented by a
+ * single zero character {@code '0'} ({@code '\u005Cu0030'});
+ * otherwise, the first character of the representation of the
+ * unsigned magnitude will not be the zero character. The
+ * characters {@code '0'} ({@code '\u005Cu0030'}) and {@code
+ * '1'} ({@code '\u005Cu0031'}) are used as binary digits.
*
* @param i a {@code long} to be converted to a string.
* @return the string representation of the unsigned {@code long}
* value represented by the argument in binary (base 2).
+ * @see #parseUnsignedLong(String, int)
+ * @see #toUnsignedString(long, int)
* @since JDK 1.0.2
*/
public static String toBinaryString(long i) {
- return toUnsignedString(i, 1);
+ return toUnsignedString0(i, 1);
}
/**
* Convert the integer to an unsigned number.
*/
- private static String toUnsignedString(long i, int shift) {
+ private static String toUnsignedString0(long i, int shift) {
char[] buf = new char[64];
int charPos = 64;
int radix = 1 << shift;
@@ -271,6 +377,24 @@
}
/**
+ * Returns a string representation of the argument as an unsigned
+ * decimal value.
+ *
+ * The argument is converted to unsigned decimal representation
+ * and returned as a string exactly as if the argument and radix
+ * 10 were given as arguments to the {@link #toUnsignedString(long,
+ * int)} method.
+ *
+ * @param i an integer to be converted to an unsigned string.
+ * @return an unsigned string representation of the argument.
+ * @see #toUnsignedString(long, int)
+ * @since 1.8
+ */
+ public static String toUnsignedString(long i) {
+ return toUnsignedString(i, 10);
+ }
+
+ /**
* Places characters representing the integer i into the
* character array buf. The characters are placed into
* the buffer backwards starting with the least significant
@@ -343,14 +467,14 @@
* string must all be digits of the specified radix (as determined
* by whether {@link java.lang.Character#digit(char, int)} returns
* a nonnegative value), except that the first character may be an
- * ASCII minus sign {@code '-'} (<code>'\u002D'</code>) to
+ * ASCII minus sign {@code '-'} ({@code '\u005Cu002D'}) to
* indicate a negative value or an ASCII plus sign {@code '+'}
- * (<code>'\u002B'</code>) to indicate a positive value. The
+ * ({@code '\u005Cu002B'}) to indicate a positive value. The
* resulting {@code long} value is returned.
*
* <p>Note that neither the character {@code L}
- * (<code>'\u004C'</code>) nor {@code l}
- * (<code>'\u006C'</code>) is permitted to appear at the end
+ * ({@code '\u005Cu004C'}) nor {@code l}
+ * ({@code '\u005Cu006C'}) is permitted to appear at the end
* of the string as a type indicator, as would be permitted in
* Java programming language source code - except that either
* {@code L} or {@code l} may appear as a digit for a
@@ -369,8 +493,8 @@
*
* <li>Any character of the string is not a digit of the specified
* radix, except that the first character may be a minus sign
- * {@code '-'} (<code>'\u002d'</code>) or plus sign {@code
- * '+'} (<code>'\u002B'</code>) provided that the string is
+ * {@code '-'} ({@code '\u005Cu002d'}) or plus sign {@code
+ * '+'} ({@code '\u005Cu002B'}) provided that the string is
* longer than length 1.
*
* <li>The value represented by the string is not a value of type
@@ -460,16 +584,16 @@
* Parses the string argument as a signed decimal {@code long}.
* The characters in the string must all be decimal digits, except
* that the first character may be an ASCII minus sign {@code '-'}
- * (<code>\u002D'</code>) to indicate a negative value or an
- * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
+ * ({@code \u005Cu002D'}) to indicate a negative value or an
+ * ASCII plus sign {@code '+'} ({@code '\u005Cu002B'}) to
* indicate a positive value. The resulting {@code long} value is
* returned, exactly as if the argument and the radix {@code 10}
* were given as arguments to the {@link
* #parseLong(java.lang.String, int)} method.
*
* <p>Note that neither the character {@code L}
- * (<code>'\u004C'</code>) nor {@code l}
- * (<code>'\u006C'</code>) is permitted to appear at the end
+ * ({@code '\u005Cu004C'}) nor {@code l}
+ * ({@code '\u005Cu006C'}) is permitted to appear at the end
* of the string as a type indicator, as would be permitted in
* Java programming language source code.
*
@@ -485,6 +609,121 @@
}
/**
+ * Parses the string argument as an unsigned {@code long} in the
+ * radix specified by the second argument. An unsigned integer
+ * maps the values usually associated with negative numbers to
+ * positive numbers larger than {@code MAX_VALUE}.
+ *
+ * The characters in the string must all be digits of the
+ * specified radix (as determined by whether {@link
+ * java.lang.Character#digit(char, int)} returns a nonnegative
+ * value), except that the first character may be an ASCII plus
+ * sign {@code '+'} ({@code '\u005Cu002B'}). The resulting
+ * integer value is returned.
+ *
+ * <p>An exception of type {@code NumberFormatException} is
+ * thrown if any of the following situations occurs:
+ * <ul>
+ * <li>The first argument is {@code null} or is a string of
+ * length zero.
+ *
+ * <li>The radix is either smaller than
+ * {@link java.lang.Character#MIN_RADIX} or
+ * larger than {@link java.lang.Character#MAX_RADIX}.
+ *
+ * <li>Any character of the string is not a digit of the specified
+ * radix, except that the first character may be a plus sign
+ * {@code '+'} ({@code '\u005Cu002B'}) provided that the
+ * string is longer than length 1.
+ *
+ * <li>The value represented by the string is larger than the
+ * largest unsigned {@code long}, 2<sup>64</sup>-1.
+ *
+ * </ul>
+ *
+ *
+ * @param s the {@code String} containing the unsigned integer
+ * representation to be parsed
+ * @param radix the radix to be used while parsing {@code s}.
+ * @return the unsigned {@code long} represented by the string
+ * argument in the specified radix.
+ * @throws NumberFormatException if the {@code String}
+ * does not contain a parsable {@code long}.
+ * @since 1.8
+ */
+ public static long parseUnsignedLong(String s, int radix)
+ throws NumberFormatException {
+ if (s == null) {
+ throw new NumberFormatException("null");
+ }
+
+ int len = s.length();
+ if (len > 0) {
+ char firstChar = s.charAt(0);
+ if (firstChar == '-') {
+ throw new
+ NumberFormatException(String.format("Illegal leading minus sign " +
+ "on unsigned string %s.", s));
+ } else {
+ if (len <= 12 || // Long.MAX_VALUE in Character.MAX_RADIX is 13 digits
+ (radix == 10 && len <= 18) ) { // Long.MAX_VALUE in base 10 is 19 digits
+ return parseLong(s, radix);
+ }
+
+ // No need for range checks on len due to testing above.
+ long first = parseLong(s.substring(0, len - 1), radix);
+ int second = Character.digit(s.charAt(len - 1), radix);
+ if (second < 0) {
+ throw new NumberFormatException("Bad digit at end of " + s);
+ }
+ long result = first * radix + second;
+ if (compareUnsigned(result, first) < 0) {
+ /*
+ * The maximum unsigned value, (2^64)-1, takes at
+ * most one more digit to represent than the
+ * maximum signed value, (2^63)-1. Therefore,
+ * parsing (len - 1) digits will be appropriately
+ * in-range of the signed parsing. In other
+ * words, if parsing (len -1) digits overflows
+ * signed parsing, parsing len digits will
+ * certainly overflow unsigned parsing.
+ *
+ * The compareUnsigned check above catches
+ * situations where an unsigned overflow occurs
+ * incorporating the contribution of the final
+ * digit.
+ */
+ throw new NumberFormatException(String.format("String value %s exceeds " +
+ "range of unsigned long.", s));
+ }
+ return result;
+ }
+ } else {
+ throw NumberFormatException.forInputString(s);
+ }
+ }
+
+ /**
+ * Parses the string argument as an unsigned decimal {@code long}. The
+ * characters in the string must all be decimal digits, except
+ * that the first character may be an an ASCII plus sign {@code
+ * '+'} ({@code '\u005Cu002B'}). The resulting integer value
+ * is returned, exactly as if the argument and the radix 10 were
+ * given as arguments to the {@link
+ * #parseUnsignedLong(java.lang.String, int)} method.
+ *
+ * @param s a {@code String} containing the unsigned {@code long}
+ * representation to be parsed
+ * @return the unsigned {@code long} value represented by the decimal string argument
+ * @throws NumberFormatException if the string does not contain a
+ * parsable unsigned integer.
+ * @since 1.8
+ */
+ public static long parseUnsignedLong(String s) throws NumberFormatException {
+ return parseUnsignedLong(s, 10);
+ }
+
+ /**
* Returns a {@code Long} object holding the value
* extracted from the specified {@code String} when parsed
* with the radix given by the second argument. The first
@@ -909,8 +1148,8 @@
* </ul>
*
* <p>Note that, in every case, neither {@code L}
- * (<code>'\u004C'</code>) nor {@code l}
- * (<code>'\u006C'</code>) is permitted to appear at the end
+ * ({@code '\u005Cu004C'}) nor {@code l}
+ * ({@code '\u005Cu006C'}) is permitted to appear at the end
* of the property value as a type indicator, as would be
* permitted in Java programming language source code.
*
@@ -977,6 +1216,85 @@
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
+ /**
+ * Compares two {@code long} values numerically treating the values
+ * as unsigned.
+ *
+ * @param x the first {@code long} to compare
+ * @param y the second {@code long} to compare
+ * @return the value {@code 0} if {@code x == y}; a value less
+ * than {@code 0} if {@code x < y} as unsigned values; and
+ * a value greater than {@code 0} if {@code x > y} as
+ * unsigned values
+ * @since 1.8
+ */
+ public static int compareUnsigned(long x, long y) {
+ return compare(x + MIN_VALUE, y + MIN_VALUE);
+ }
+
+
+ /**
+ * Returns the unsigned quotient of dividing the first argument by
+ * the second where each argument and the result is interpreted as
+ * an unsigned value.
+ *
+ * <p>Note that in two's complement arithmetic, the three other
+ * basic arithmetic operations of add, subtract, and multiply are
+ * bit-wise identical if the two operands are regarded as both
+ * being signed or both being unsigned. Therefore separate {@code
+ * addUnsigned}, etc. methods are not provided.
+ *
+ * @param dividend the value to be divided
+ * @param divisor the value doing the dividing
+ * @return the unsigned quotient of the first argument divided by
+ * the second argument
+ * @see #remainderUnsigned
+ * @since 1.8
+ */
+ public static long divideUnsigned(long dividend, long divisor) {
+ if (divisor < 0L) { // signed comparison
+ // Answer must be 0 or 1 depending on relative magnitude
+ // of dividend and divisor.
+ return (compareUnsigned(dividend, divisor)) < 0 ? 0L :1L;
+ }
+
+ if (dividend > 0) // Both inputs non-negative
+ return dividend/divisor;
+ else {
+ /*
+ * For simple code, leveraging BigInteger. Longer and faster
+ * code written directly in terms of operations on longs is
+ * possible; see "Hacker's Delight" for divide and remainder
+ * algorithms.
+ */
+ return toUnsignedBigInteger(dividend).
+ divide(toUnsignedBigInteger(divisor)).longValue();
+ }
+ }
+
+ /**
+ * Returns the unsigned remainder from dividing the first argument
+ * by the second where each argument and the result is interpreted
+ * as an unsigned value.
+ *
+ * @param dividend the value to be divided
+ * @param divisor the value doing the dividing
+ * @return the unsigned remainder of the first argument divided by
+ * the second argument
+ * @see #divideUnsigned
+ * @since 1.8
+ */
+ public static long remainderUnsigned(long dividend, long divisor) {
+ if (dividend > 0 && divisor > 0) { // signed comparisons
+ return dividend % divisor;
+ } else {
+ if (compareUnsigned(dividend, divisor) < 0) // Avoid explicit check for 0 divisor
+ return dividend;
+ else
+ return toUnsignedBigInteger(dividend).
+ remainder(toUnsignedBigInteger(divisor)).longValue();
+ }
+ }
// Bit Twiddling
--- a/jdk/src/share/classes/java/lang/Short.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/lang/Short.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2012, 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
@@ -80,8 +80,8 @@
* determined by whether {@link java.lang.Character#digit(char,
* int)} returns a nonnegative value) except that the first
* character may be an ASCII minus sign {@code '-'}
- * (<code>'\u002D'</code>) to indicate a negative value or an
- * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
+ * ({@code '\u005Cu002D'}) to indicate a negative value or an
+ * ASCII plus sign {@code '+'} ({@code '\u005Cu002B'}) to
* indicate a positive value. The resulting {@code short} value
* is returned.
*
@@ -97,8 +97,8 @@
*
* <li> Any character of the string is not a digit of the
* specified radix, except that the first character may be a minus
- * sign {@code '-'} (<code>'\u002D'</code>) or plus sign
- * {@code '+'} (<code>'\u002B'</code>) provided that the
+ * sign {@code '-'} ({@code '\u005Cu002D'}) or plus sign
+ * {@code '+'} ({@code '\u005Cu002B'}) provided that the
* string is longer than length 1.
*
* <li> The value represented by the string is not a value of type
@@ -126,9 +126,9 @@
* Parses the string argument as a signed decimal {@code
* short}. The characters in the string must all be decimal
* digits, except that the first character may be an ASCII minus
- * sign {@code '-'} (<code>'\u002D'</code>) to indicate a
+ * sign {@code '-'} ({@code '\u005Cu002D'}) to indicate a
* negative value or an ASCII plus sign {@code '+'}
- * (<code>'\u002B'</code>) to indicate a positive value. The
+ * ({@code '\u005Cu002B'}) to indicate a positive value. The
* resulting {@code short} value is returned, exactly as if the
* argument and the radix 10 were given as arguments to the {@link
* #parseShort(java.lang.String, int)} method.
@@ -469,6 +469,47 @@
return (short) (((i & 0xFF00) >> 8) | (i << 8));
}
+
+ /**
+ * Converts the argument to an {@code int} by an unsigned
+ * conversion. In an unsigned conversion to an {@code int}, the
+ * high-order 16 bits of the {@code int} are zero and the
+ * low-order 16 bits are equal to the bits of the {@code short} argument.
+ *
+ * Consequently, zero and positive {@code short} values are mapped
+ * to a numerically equal {@code int} value and negative {@code
+ * short} values are mapped to an {@code int} value equal to the
+ * input plus 2<sup>16</sup>.
+ *
+ * @param x the value to convert to an unsigned {@code int}
+ * @return the argument converted to {@code int} by an unsigned
+ * conversion
+ * @since 1.8
+ */
+ public static int toUnsignedInt(short x) {
+ return ((int) x) & 0xffff;
+ }
+
+ /**
+ * Converts the argument to a {@code long} by an unsigned
+ * conversion. In an unsigned conversion to a {@code long}, the
+ * high-order 48 bits of the {@code long} are zero and the
+ * low-order 16 bits are equal to the bits of the {@code short} argument.
+ *
+ * Consequently, zero and positive {@code short} values are mapped
+ * to a numerically equal {@code long} value and negative {@code
+ * short} values are mapped to a {@code long} value equal to the
+ * input plus 2<sup>16</sup>.
+ *
+ * @param x the value to convert to an unsigned {@code long}
+ * @return the argument converted to {@code long} by an unsigned
+ * conversion
+ * @since 1.8
+ */
+ public static long toUnsignedLong(short x) {
+ return ((long) x) & 0xffffL;
+ }
+
/** use serialVersionUID from JDK 1.1. for interoperability */
private static final long serialVersionUID = 7515723908773894738L;
}
--- a/jdk/src/share/classes/java/lang/String.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/lang/String.java Tue Jan 31 19:08:36 2012 -0800
@@ -39,8 +39,8 @@
import java.util.regex.PatternSyntaxException;
/**
- * The <code>String</code> class represents character strings. All
- * string literals in Java programs, such as <code>"abc"</code>, are
+ * The {@code String} class represents character strings. All
+ * string literals in Java programs, such as {@code "abc"}, are
* implemented as instances of this class.
* <p>
* Strings are constant; their values cannot be changed after they
@@ -63,7 +63,7 @@
* String d = cde.substring(1, 2);
* </pre></blockquote>
* <p>
- * The class <code>String</code> includes methods for examining
+ * The class {@code String} includes methods for examining
* individual characters of the sequence, for comparing strings, for
* searching strings, for extracting substrings, and for creating a
* copy of a string with all characters translated to uppercase or to
@@ -73,10 +73,10 @@
* The Java language provides special support for the string
* concatenation operator ( + ), and for conversion of
* other objects to strings. String concatenation is implemented
- * through the <code>StringBuilder</code>(or <code>StringBuffer</code>)
- * class and its <code>append</code> method.
+ * through the {@code StringBuilder}(or {@code StringBuffer})
+ * class and its {@code append} method.
* String conversions are implemented through the method
- * <code>toString</code>, defined by <code>Object</code> and
+ * {@code toString}, defined by {@code Object} and
* inherited by all classes in Java. For additional information on
* string concatenation and conversion, see Gosling, Joy, and Steele,
* <i>The Java Language Specification</i>.
@@ -85,16 +85,16 @@
* or method in this class will cause a {@link NullPointerException} to be
* thrown.
*
- * <p>A <code>String</code> represents a string in the UTF-16 format
+ * <p>A {@code String} represents a string in the UTF-16 format
* in which <em>supplementary characters</em> are represented by <em>surrogate
* pairs</em> (see the section <a href="Character.html#unicode">Unicode
- * Character Representations</a> in the <code>Character</code> class for
+ * Character Representations</a> in the {@code Character} class for
* more information).
- * Index values refer to <code>char</code> code units, so a supplementary
- * character uses two positions in a <code>String</code>.
- * <p>The <code>String</code> class provides methods for dealing with
+ * Index values refer to {@code char} code units, so a supplementary
+ * character uses two positions in a {@code String}.
+ * <p>The {@code String} class provides methods for dealing with
* Unicode code points (i.e., characters), in addition to those for
- * dealing with Unicode code units (i.e., <code>char</code> values).
+ * dealing with Unicode code units (i.e., {@code char} values).
*
* @author Lee Boynton
* @author Arthur van Hoff
@@ -131,9 +131,9 @@
* A String instance is written initially into an ObjectOutputStream in the
* following format:
* <pre>
- * <code>TC_STRING</code> (utf String)
+ * {@code TC_STRING} (utf String)
* </pre>
- * The String is written by method <code>DataOutput.writeUTF</code>.
+ * The String is written by method {@code DataOutput.writeUTF}.
* A new handle is generated to refer to all future references to the
* string instance within the stream.
*/
@@ -673,20 +673,20 @@
}
/**
- * Returns the <code>char</code> value at the
- * specified index. An index ranges from <code>0</code> to
- * <code>length() - 1</code>. The first <code>char</code> value of the sequence
- * is at index <code>0</code>, the next at index <code>1</code>,
+ * Returns the {@code char} value at the
+ * specified index. An index ranges from {@code 0} to
+ * {@code length() - 1}. The first {@code char} value of the sequence
+ * is at index {@code 0}, the next at index {@code 1},
* and so on, as for array indexing.
*
- * <p>If the <code>char</code> value specified by the index is a
+ * <p>If the {@code char} value specified by the index is a
* <a href="Character.html#unicode">surrogate</a>, the surrogate
* value is returned.
*
- * @param index the index of the <code>char</code> value.
- * @return the <code>char</code> value at the specified index of this string.
- * The first <code>char</code> value is at index <code>0</code>.
- * @exception IndexOutOfBoundsException if the <code>index</code>
+ * @param index the index of the {@code char} value.
+ * @return the {@code char} value at the specified index of this string.
+ * The first {@code char} value is at index {@code 0}.
+ * @exception IndexOutOfBoundsException if the {@code index}
* argument is negative or not less than the length of this
* string.
*/
@@ -699,22 +699,22 @@
/**
* Returns the character (Unicode code point) at the specified
- * index. The index refers to <code>char</code> values
- * (Unicode code units) and ranges from <code>0</code> to
- * {@link #length()}<code> - 1</code>.
+ * index. The index refers to {@code char} values
+ * (Unicode code units) and ranges from {@code 0} to
+ * {@link #length()}{@code - 1}.
*
- * <p> If the <code>char</code> value specified at the given index
+ * <p> If the {@code char} value specified at the given index
* is in the high-surrogate range, the following index is less
- * than the length of this <code>String</code>, and the
- * <code>char</code> value at the following index is in the
+ * than the length of this {@code String}, and the
+ * {@code char} value at the following index is in the
* low-surrogate range, then the supplementary code point
* corresponding to this surrogate pair is returned. Otherwise,
- * the <code>char</code> value at the given index is returned.
+ * the {@code char} value at the given index is returned.
*
- * @param index the index to the <code>char</code> values
+ * @param index the index to the {@code char} values
* @return the code point value of the character at the
- * <code>index</code>
- * @exception IndexOutOfBoundsException if the <code>index</code>
+ * {@code index}
+ * @exception IndexOutOfBoundsException if the {@code index}
* argument is negative or not less than the length of this
* string.
* @since 1.5
@@ -728,22 +728,22 @@
/**
* Returns the character (Unicode code point) before the specified
- * index. The index refers to <code>char</code> values
- * (Unicode code units) and ranges from <code>1</code> to {@link
+ * index. The index refers to {@code char} values
+ * (Unicode code units) and ranges from {@code 1} to {@link
* CharSequence#length() length}.
*
- * <p> If the <code>char</code> value at <code>(index - 1)</code>
- * is in the low-surrogate range, <code>(index - 2)</code> is not
- * negative, and the <code>char</code> value at <code>(index -
- * 2)</code> is in the high-surrogate range, then the
+ * <p> If the {@code char} value at {@code (index - 1)}
+ * is in the low-surrogate range, {@code (index - 2)} is not
+ * negative, and the {@code char} value at {@code (index -
+ * 2)} is in the high-surrogate range, then the
* supplementary code point value of the surrogate pair is
- * returned. If the <code>char</code> value at <code>index -
- * 1</code> is an unpaired low-surrogate or a high-surrogate, the
+ * returned. If the {@code char} value at {@code index -
+ * 1} is an unpaired low-surrogate or a high-surrogate, the
* surrogate value is returned.
*
* @param index the index following the code point that should be returned
* @return the Unicode code point value before the given index.
- * @exception IndexOutOfBoundsException if the <code>index</code>
+ * @exception IndexOutOfBoundsException if the {@code index}
* argument is less than 1 or greater than the length
* of this string.
* @since 1.5
@@ -758,23 +758,23 @@
/**
* Returns the number of Unicode code points in the specified text
- * range of this <code>String</code>. The text range begins at the
- * specified <code>beginIndex</code> and extends to the
- * <code>char</code> at index <code>endIndex - 1</code>. Thus the
- * length (in <code>char</code>s) of the text range is
- * <code>endIndex-beginIndex</code>. Unpaired surrogates within
+ * range of this {@code String}. The text range begins at the
+ * specified {@code beginIndex} and extends to the
+ * {@code char} at index {@code endIndex - 1}. Thus the
+ * length (in {@code char}s) of the text range is
+ * {@code endIndex-beginIndex}. Unpaired surrogates within
* the text range count as one code point each.
*
- * @param beginIndex the index to the first <code>char</code> of
+ * @param beginIndex the index to the first {@code char} of
* the text range.
- * @param endIndex the index after the last <code>char</code> of
+ * @param endIndex the index after the last {@code char} of
* the text range.
* @return the number of Unicode code points in the specified text
* range
* @exception IndexOutOfBoundsException if the
- * <code>beginIndex</code> is negative, or <code>endIndex</code>
- * is larger than the length of this <code>String</code>, or
- * <code>beginIndex</code> is larger than <code>endIndex</code>.
+ * {@code beginIndex} is negative, or {@code endIndex}
+ * is larger than the length of this {@code String}, or
+ * {@code beginIndex} is larger than {@code endIndex}.
* @since 1.5
*/
public int codePointCount(int beginIndex, int endIndex) {
@@ -785,23 +785,23 @@
}
/**
- * Returns the index within this <code>String</code> that is
- * offset from the given <code>index</code> by
- * <code>codePointOffset</code> code points. Unpaired surrogates
- * within the text range given by <code>index</code> and
- * <code>codePointOffset</code> count as one code point each.
+ * Returns the index within this {@code String} that is
+ * offset from the given {@code index} by
+ * {@code codePointOffset} code points. Unpaired surrogates
+ * within the text range given by {@code index} and
+ * {@code codePointOffset} count as one code point each.
*
* @param index the index to be offset
* @param codePointOffset the offset in code points
- * @return the index within this <code>String</code>
- * @exception IndexOutOfBoundsException if <code>index</code>
+ * @return the index within this {@code String}
+ * @exception IndexOutOfBoundsException if {@code index}
* is negative or larger then the length of this
- * <code>String</code>, or if <code>codePointOffset</code> is positive
- * and the substring starting with <code>index</code> has fewer
- * than <code>codePointOffset</code> code points,
- * or if <code>codePointOffset</code> is negative and the substring
- * before <code>index</code> has fewer than the absolute value
- * of <code>codePointOffset</code> code points.
+ * {@code String}, or if {@code codePointOffset} is positive
+ * and the substring starting with {@code index} has fewer
+ * than {@code codePointOffset} code points,
+ * or if {@code codePointOffset} is negative and the substring
+ * before {@code index} has fewer than the absolute value
+ * of {@code codePointOffset} code points.
* @since 1.5
*/
public int offsetByCodePoints(int index, int codePointOffset) {
@@ -824,11 +824,11 @@
* Copies characters from this string into the destination character
* array.
* <p>
- * The first character to be copied is at index <code>srcBegin</code>;
- * the last character to be copied is at index <code>srcEnd-1</code>
+ * The first character to be copied is at index {@code srcBegin};
+ * the last character to be copied is at index {@code srcEnd-1}
* (thus the total number of characters to be copied is
- * <code>srcEnd-srcBegin</code>). The characters are copied into the
- * subarray of <code>dst</code> starting at index <code>dstBegin</code>
+ * {@code srcEnd-srcBegin}). The characters are copied into the
+ * subarray of {@code dst} starting at index {@code dstBegin}
* and ending at index:
* <p><blockquote><pre>
* dstbegin + (srcEnd-srcBegin) - 1
@@ -842,13 +842,13 @@
* @param dstBegin the start offset in the destination array.
* @exception IndexOutOfBoundsException If any of the following
* is true:
- * <ul><li><code>srcBegin</code> is negative.
- * <li><code>srcBegin</code> is greater than <code>srcEnd</code>
- * <li><code>srcEnd</code> is greater than the length of this
+ * <ul><li>{@code srcBegin} is negative.
+ * <li>{@code srcBegin} is greater than {@code srcEnd}
+ * <li>{@code srcEnd} is greater than the length of this
* string
- * <li><code>dstBegin</code> is negative
- * <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
- * <code>dst.length</code></ul>
+ * <li>{@code dstBegin} is negative
+ * <li>{@code dstBegin+(srcEnd-srcBegin)} is larger than
+ * {@code dst.length}</ul>
*/
public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
if (srcBegin < 0) {
@@ -1135,14 +1135,14 @@
* Compares two strings lexicographically.
* The comparison is based on the Unicode value of each character in
* the strings. The character sequence represented by this
- * <code>String</code> object is compared lexicographically to the
+ * {@code String} object is compared lexicographically to the
* character sequence represented by the argument string. The result is
- * a negative integer if this <code>String</code> object
+ * a negative integer if this {@code String} object
* lexicographically precedes the argument string. The result is a
- * positive integer if this <code>String</code> object lexicographically
+ * positive integer if this {@code String} object lexicographically
* follows the argument string. The result is zero if the strings
- * are equal; <code>compareTo</code> returns <code>0</code> exactly when
- * the {@link #equals(Object)} method would return <code>true</code>.
+ * are equal; {@code compareTo} returns {@code 0} exactly when
+ * the {@link #equals(Object)} method would return {@code true}.
* <p>
* This is the definition of lexicographic ordering. If two strings are
* different, then either they have different characters at some index
@@ -1151,25 +1151,25 @@
* positions, let <i>k</i> be the smallest such index; then the string
* whose character at position <i>k</i> has the smaller value, as
* determined by using the < operator, lexicographically precedes the
- * other string. In this case, <code>compareTo</code> returns the
- * difference of the two character values at position <code>k</code> in
+ * other string. In this case, {@code compareTo} returns the
+ * difference of the two character values at position {@code k} in
* the two string -- that is, the value:
* <blockquote><pre>
* this.charAt(k)-anotherString.charAt(k)
* </pre></blockquote>
* If there is no index position at which they differ, then the shorter
* string lexicographically precedes the longer string. In this case,
- * <code>compareTo</code> returns the difference of the lengths of the
+ * {@code compareTo} returns the difference of the lengths of the
* strings -- that is, the value:
* <blockquote><pre>
* this.length()-anotherString.length()
* </pre></blockquote>
*
- * @param anotherString the <code>String</code> to be compared.
- * @return the value <code>0</code> if the argument string is equal to
- * this string; a value less than <code>0</code> if this string
+ * @param anotherString the {@code String} to be compared.
+ * @return the value {@code 0} if the argument string is equal to
+ * this string; a value less than {@code 0} if this string
* is lexicographically less than the string argument; and a
- * value greater than <code>0</code> if this string is
+ * value greater than {@code 0} if this string is
* lexicographically greater than the string argument.
*/
public int compareTo(String anotherString) {
@@ -1205,8 +1205,8 @@
}
/**
- * A Comparator that orders <code>String</code> objects as by
- * <code>compareToIgnoreCase</code>. This comparator is serializable.
+ * A Comparator that orders {@code String} objects as by
+ * {@code compareToIgnoreCase}. This comparator is serializable.
* <p>
* Note that this Comparator does <em>not</em> take locale into account,
* and will result in an unsatisfactory ordering for certain locales.
@@ -1253,9 +1253,9 @@
/**
* Compares two strings lexicographically, ignoring case
* differences. This method returns an integer whose sign is that of
- * calling <code>compareTo</code> with normalized versions of the strings
+ * calling {@code compareTo} with normalized versions of the strings
* where case differences have been eliminated by calling
- * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on
+ * {@code Character.toLowerCase(Character.toUpperCase(character))} on
* each character.
* <p>
* Note that this method does <em>not</em> take locale into account,
@@ -1263,7 +1263,7 @@
* The java.text package provides <em>collators</em> to allow
* locale-sensitive ordering.
*
- * @param str the <code>String</code> to be compared.
+ * @param str the {@code String} to be compared.
* @return a negative integer, zero, or a positive integer as the
* specified String is greater than, equal to, or less
* than this String, ignoring case considerations.
@@ -1301,9 +1301,9 @@
* @param ooffset the starting offset of the subregion in the string
* argument.
* @param len the number of characters to compare.
- * @return <code>true</code> if the specified subregion of this string
+ * @return {@code true} if the specified subregion of this string
* exactly matches the specified subregion of the string argument;
- * <code>false</code> otherwise.
+ * {@code false} otherwise.
*/
public boolean regionMatches(int toffset, String other, int ooffset,
int len) {
@@ -1360,7 +1360,7 @@
* </pre></blockquote>
* </ul>
*
- * @param ignoreCase if <code>true</code>, ignore case when comparing
+ * @param ignoreCase if {@code true}, ignore case when comparing
* characters.
* @param toffset the starting offset of the subregion in this
* string.
@@ -1368,10 +1368,10 @@
* @param ooffset the starting offset of the subregion in the string
* argument.
* @param len the number of characters to compare.
- * @return <code>true</code> if the specified subregion of this string
+ * @return {@code true} if the specified subregion of this string
* matches the specified subregion of the string argument;
- * <code>false</code> otherwise. Whether the matching is exact
- * or case insensitive depends on the <code>ignoreCase</code>
+ * {@code false} otherwise. Whether the matching is exact
+ * or case insensitive depends on the {@code ignoreCase}
* argument.
*/
public boolean regionMatches(boolean ignoreCase, int toffset,
@@ -1420,12 +1420,12 @@
*
* @param prefix the prefix.
* @param toffset where to begin looking in this string.
- * @return <code>true</code> if the character sequence represented by the
+ * @return {@code true} if the character sequence represented by the
* argument is a prefix of the substring of this object starting
- * at index <code>toffset</code>; <code>false</code> otherwise.
- * The result is <code>false</code> if <code>toffset</code> is
+ * at index {@code toffset}; {@code false} otherwise.
+ * The result is {@code false} if {@code toffset} is
* negative or greater than the length of this
- * <code>String</code> object; otherwise the result is the same
+ * {@code String} object; otherwise the result is the same
* as the result of the expression
* <pre>
* this.substring(toffset).startsWith(prefix)
@@ -1453,12 +1453,12 @@
* Tests if this string starts with the specified prefix.
*
* @param prefix the prefix.
- * @return <code>true</code> if the character sequence represented by the
+ * @return {@code true} if the character sequence represented by the
* argument is a prefix of the character sequence represented by
- * this string; <code>false</code> otherwise.
- * Note also that <code>true</code> will be returned if the
+ * this string; {@code false} otherwise.
+ * Note also that {@code true} will be returned if the
* argument is an empty string or is equal to this
- * <code>String</code> object as determined by the
+ * {@code String} object as determined by the
* {@link #equals(Object)} method.
* @since 1. 0
*/
@@ -1470,11 +1470,11 @@
* Tests if this string ends with the specified suffix.
*
* @param suffix the suffix.
- * @return <code>true</code> if the character sequence represented by the
+ * @return {@code true} if the character sequence represented by the
* argument is a suffix of the character sequence represented by
- * this object; <code>false</code> otherwise. Note that the
- * result will be <code>true</code> if the argument is the
- * empty string or is equal to this <code>String</code> object
+ * this object; {@code false} otherwise. Note that the
+ * result will be {@code true} if the argument is the
+ * empty string or is equal to this {@code String} object
* as determined by the {@link #equals(Object)} method.
*/
public boolean endsWith(String suffix) {
@@ -1483,13 +1483,13 @@
/**
* Returns a hash code for this string. The hash code for a
- * <code>String</code> object is computed as
+ * {@code String} object is computed as
* <blockquote><pre>
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* </pre></blockquote>
- * using <code>int</code> arithmetic, where <code>s[i]</code> is the
- * <i>i</i>th character of the string, <code>n</code> is the length of
- * the string, and <code>^</code> indicates exponentiation.
+ * using {@code int} arithmetic, where {@code s[i]} is the
+ * <i>i</i>th character of the string, {@code n} is the length of
+ * the string, and {@code ^} indicates exponentiation.
* (The hash value of the empty string is zero.)
*
* @return a hash code value for this object.
@@ -1512,26 +1512,26 @@
/**
* Returns the index within this string of the first occurrence of
* the specified character. If a character with value
- * <code>ch</code> occurs in the character sequence represented by
- * this <code>String</code> object, then the index (in Unicode
+ * {@code ch} occurs in the character sequence represented by
+ * this {@code String} object, then the index (in Unicode
* code units) of the first such occurrence is returned. For
- * values of <code>ch</code> in the range from 0 to 0xFFFF
+ * values of {@code ch} in the range from 0 to 0xFFFF
* (inclusive), this is the smallest value <i>k</i> such that:
* <blockquote><pre>
* this.charAt(<i>k</i>) == ch
* </pre></blockquote>
- * is true. For other values of <code>ch</code>, it is the
+ * is true. For other values of {@code ch}, it is the
* smallest value <i>k</i> such that:
* <blockquote><pre>
* this.codePointAt(<i>k</i>) == ch
* </pre></blockquote>
* is true. In either case, if no such character occurs in this
- * string, then <code>-1</code> is returned.
+ * string, then {@code -1} is returned.
*
* @param ch a character (Unicode code point).
* @return the index of the first occurrence of the character in the
* character sequence represented by this object, or
- * <code>-1</code> if the character does not occur.
+ * {@code -1} if the character does not occur.
*/
public int indexOf(int ch) {
return indexOf(ch, 0);
@@ -1541,39 +1541,39 @@
* Returns the index within this string of the first occurrence of the
* specified character, starting the search at the specified index.
* <p>
- * If a character with value <code>ch</code> occurs in the
- * character sequence represented by this <code>String</code>
- * object at an index no smaller than <code>fromIndex</code>, then
+ * If a character with value {@code ch} occurs in the
+ * character sequence represented by this {@code String}
+ * object at an index no smaller than {@code fromIndex}, then
* the index of the first such occurrence is returned. For values
- * of <code>ch</code> in the range from 0 to 0xFFFF (inclusive),
+ * of {@code ch} in the range from 0 to 0xFFFF (inclusive),
* this is the smallest value <i>k</i> such that:
* <blockquote><pre>
* (this.charAt(<i>k</i>) == ch) && (<i>k</i> >= fromIndex)
* </pre></blockquote>
- * is true. For other values of <code>ch</code>, it is the
+ * is true. For other values of {@code ch}, it is the
* smallest value <i>k</i> such that:
* <blockquote><pre>
* (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> >= fromIndex)
* </pre></blockquote>
* is true. In either case, if no such character occurs in this
- * string at or after position <code>fromIndex</code>, then
- * <code>-1</code> is returned.
+ * string at or after position {@code fromIndex}, then
+ * {@code -1} is returned.
*
* <p>
- * There is no restriction on the value of <code>fromIndex</code>. If it
+ * There is no restriction on the value of {@code fromIndex}. If it
* is negative, it has the same effect as if it were zero: this entire
* string may be searched. If it is greater than the length of this
* string, it has the same effect as if it were equal to the length of
- * this string: <code>-1</code> is returned.
+ * this string: {@code -1} is returned.
*
- * <p>All indices are specified in <code>char</code> values
+ * <p>All indices are specified in {@code char} values
* (Unicode code units).
*
* @param ch a character (Unicode code point).
* @param fromIndex the index to start the search from.
* @return the index of the first occurrence of the character in the
* character sequence represented by this object that is greater
- * than or equal to <code>fromIndex</code>, or <code>-1</code>
+ * than or equal to {@code fromIndex}, or {@code -1}
* if the character does not occur.
*/
public int indexOf(int ch, int fromIndex) {
@@ -1622,26 +1622,26 @@
/**
* Returns the index within this string of the last occurrence of
- * the specified character. For values of <code>ch</code> in the
+ * the specified character. For values of {@code ch} in the
* range from 0 to 0xFFFF (inclusive), the index (in Unicode code
* units) returned is the largest value <i>k</i> such that:
* <blockquote><pre>
* this.charAt(<i>k</i>) == ch
* </pre></blockquote>
- * is true. For other values of <code>ch</code>, it is the
+ * is true. For other values of {@code ch}, it is the
* largest value <i>k</i> such that:
* <blockquote><pre>
* this.codePointAt(<i>k</i>) == ch
* </pre></blockquote>
* is true. In either case, if no such character occurs in this
- * string, then <code>-1</code> is returned. The
- * <code>String</code> is searched backwards starting at the last
+ * string, then {@code -1} is returned. The
+ * {@code String} is searched backwards starting at the last
* character.
*
* @param ch a character (Unicode code point).
* @return the index of the last occurrence of the character in the
* character sequence represented by this object, or
- * <code>-1</code> if the character does not occur.
+ * {@code -1} if the character does not occur.
*/
public int lastIndexOf(int ch) {
return lastIndexOf(ch, count - 1);
@@ -1650,27 +1650,27 @@
/**
* Returns the index within this string of the last occurrence of
* the specified character, searching backward starting at the
- * specified index. For values of <code>ch</code> in the range
+ * specified index. For values of {@code ch} in the range
* from 0 to 0xFFFF (inclusive), the index returned is the largest
* value <i>k</i> such that:
* <blockquote><pre>
* (this.charAt(<i>k</i>) == ch) && (<i>k</i> <= fromIndex)
* </pre></blockquote>
- * is true. For other values of <code>ch</code>, it is the
+ * is true. For other values of {@code ch}, it is the
* largest value <i>k</i> such that:
* <blockquote><pre>
* (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> <= fromIndex)
* </pre></blockquote>
* is true. In either case, if no such character occurs in this
- * string at or before position <code>fromIndex</code>, then
- * <code>-1</code> is returned.
+ * string at or before position {@code fromIndex}, then
+ * {@code -1} is returned.
*
- * <p>All indices are specified in <code>char</code> values
+ * <p>All indices are specified in {@code char} values
* (Unicode code units).
*
* @param ch a character (Unicode code point).
* @param fromIndex the index to start the search from. There is no
- * restriction on the value of <code>fromIndex</code>. If it is
+ * restriction on the value of {@code fromIndex}. If it is
* greater than or equal to the length of this string, it has
* the same effect as if it were equal to one less than the
* length of this string: this entire string may be searched.
@@ -1678,7 +1678,7 @@
* -1 is returned.
* @return the index of the last occurrence of the character in the
* character sequence represented by this object that is less
- * than or equal to <code>fromIndex</code>, or <code>-1</code>
+ * than or equal to {@code fromIndex}, or {@code -1}
* if the character does not occur before that point.
*/
public int lastIndexOf(int ch, int fromIndex) {
@@ -1921,8 +1921,8 @@
* @param beginIndex the beginning index, inclusive.
* @return the specified substring.
* @exception IndexOutOfBoundsException if
- * <code>beginIndex</code> is negative or larger than the
- * length of this <code>String</code> object.
+ * {@code beginIndex} is negative or larger than the
+ * length of this {@code String} object.
*/
public String substring(int beginIndex) {
return substring(beginIndex, count);
@@ -1930,9 +1930,9 @@
/**
* Returns a new string that is a substring of this string. The
- * substring begins at the specified <code>beginIndex</code> and
- * extends to the character at index <code>endIndex - 1</code>.
- * Thus the length of the substring is <code>endIndex-beginIndex</code>.
+ * substring begins at the specified {@code beginIndex} and
+ * extends to the character at index {@code endIndex - 1}.
+ * Thus the length of the substring is {@code endIndex-beginIndex}.
* <p>
* Examples:
* <blockquote><pre>
@@ -1944,11 +1944,11 @@
* @param endIndex the ending index, exclusive.
* @return the specified substring.
* @exception IndexOutOfBoundsException if the
- * <code>beginIndex</code> is negative, or
- * <code>endIndex</code> is larger than the length of
- * this <code>String</code> object, or
- * <code>beginIndex</code> is larger than
- * <code>endIndex</code>.
+ * {@code beginIndex} is negative, or
+ * {@code endIndex} is larger than the length of
+ * this {@code String} object, or
+ * {@code beginIndex} is larger than
+ * {@code endIndex}.
*/
public String substring(int beginIndex, int endIndex) {
if (beginIndex < 0) {
@@ -1999,11 +1999,11 @@
/**
* Concatenates the specified string to the end of this string.
* <p>
- * If the length of the argument string is <code>0</code>, then this
- * <code>String</code> object is returned. Otherwise, a new
- * <code>String</code> object is created, representing a character
+ * If the length of the argument string is {@code 0}, then this
+ * {@code String} object is returned. Otherwise, a new
+ * {@code String} object is created, representing a character
* sequence that is the concatenation of the character sequence
- * represented by this <code>String</code> object and the character
+ * represented by this {@code String} object and the character
* sequence represented by the argument string.<p>
* Examples:
* <blockquote><pre>
@@ -2011,8 +2011,8 @@
* "to".concat("get").concat("her") returns "together"
* </pre></blockquote>
*
- * @param str the <code>String</code> that is concatenated to the end
- * of this <code>String</code>.
+ * @param str the {@code String} that is concatenated to the end
+ * of this {@code String}.
* @return a string that represents the concatenation of this object's
* characters followed by the string argument's characters.
*/
@@ -2029,16 +2029,16 @@
/**
* Returns a new string resulting from replacing all occurrences of
- * <code>oldChar</code> in this string with <code>newChar</code>.
+ * {@code oldChar} in this string with {@code newChar}.
* <p>
- * If the character <code>oldChar</code> does not occur in the
- * character sequence represented by this <code>String</code> object,
- * then a reference to this <code>String</code> object is returned.
- * Otherwise, a new <code>String</code> object is created that
+ * If the character {@code oldChar} does not occur in the
+ * character sequence represented by this {@code String} object,
+ * then a reference to this {@code String} object is returned.
+ * Otherwise, a new {@code String} object is created that
* represents a character sequence identical to the character sequence
- * represented by this <code>String</code> object, except that every
- * occurrence of <code>oldChar</code> is replaced by an occurrence
- * of <code>newChar</code>.
+ * represented by this {@code String} object, except that every
+ * occurrence of {@code oldChar} is replaced by an occurrence
+ * of {@code newChar}.
* <p>
* Examples:
* <blockquote><pre>
@@ -2054,7 +2054,7 @@
* @param oldChar the old character.
* @param newChar the new character.
* @return a string derived from this string by replacing every
- * occurrence of <code>oldChar</code> with <code>newChar</code>.
+ * occurrence of {@code oldChar} with {@code newChar}.
*/
public String replace(char oldChar, char newChar) {
if (oldChar != newChar) {
@@ -2119,8 +2119,8 @@
* sequence of char values.
*
* @param s the sequence to search for
- * @return true if this string contains <code>s</code>, false otherwise
- * @throws NullPointerException if <code>s</code> is <code>null</code>
+ * @return true if this string contains {@code s}, false otherwise
+ * @throws NullPointerException if {@code s} is {@code null}
* @since 1.5
*/
public boolean contains(CharSequence s) {
@@ -2223,8 +2223,8 @@
* @param target The sequence of char values to be replaced
* @param replacement The replacement sequence of char values
* @return The resulting string
- * @throws NullPointerException if <code>target</code> or
- * <code>replacement</code> is <code>null</code>.
+ * @throws NullPointerException if {@code target} or
+ * {@code replacement} is {@code null}.
* @since 1.5
*/
public String replace(CharSequence target, CharSequence replacement) {
@@ -2407,11 +2407,11 @@
}
/**
- * Converts all of the characters in this <code>String</code> to lower
- * case using the rules of the given <code>Locale</code>. Case mapping is based
+ * Converts all of the characters in this {@code String} to lower
+ * case using the rules of the given {@code Locale}. Case mapping is based
* on the Unicode Standard version specified by the {@link java.lang.Character Character}
* class. Since case mappings are not always 1:1 char mappings, the resulting
- * <code>String</code> may be a different length than the original <code>String</code>.
+ * {@code String} may be a different length than the original {@code String}.
* <p>
* Examples of lowercase mappings are in the following table:
* <table border="1" summary="Lowercase mapping examples showing language code of locale, upper case, lower case, and description">
@@ -2452,7 +2452,7 @@
* </table>
*
* @param locale use the case transformation rules for this locale
- * @return the <code>String</code>, converted to lowercase.
+ * @return the {@code String}, converted to lowercase.
* @see java.lang.String#toLowerCase()
* @see java.lang.String#toUpperCase()
* @see java.lang.String#toUpperCase(Locale)
@@ -2553,22 +2553,22 @@
}
/**
- * Converts all of the characters in this <code>String</code> to lower
+ * Converts all of the characters in this {@code String} to lower
* case using the rules of the default locale. This is equivalent to calling
- * <code>toLowerCase(Locale.getDefault())</code>.
+ * {@code toLowerCase(Locale.getDefault())}.
* <p>
* <b>Note:</b> This method is locale sensitive, and may produce unexpected
* results if used for strings that are intended to be interpreted locale
* independently.
* Examples are programming language identifiers, protocol keys, and HTML
* tags.
- * For instance, <code>"TITLE".toLowerCase()</code> in a Turkish locale
- * returns <code>"t\u005Cu0131tle"</code>, where '\u005Cu0131' is the
+ * For instance, {@code "TITLE".toLowerCase()} in a Turkish locale
+ * returns {@code "t\u005Cu0131tle"}, where '\u005Cu0131' is the
* LATIN SMALL LETTER DOTLESS I character.
* To obtain correct results for locale insensitive strings, use
- * <code>toLowerCase(Locale.ENGLISH)</code>.
+ * {@code toLowerCase(Locale.ENGLISH)}.
* <p>
- * @return the <code>String</code>, converted to lowercase.
+ * @return the {@code String}, converted to lowercase.
* @see java.lang.String#toLowerCase(Locale)
*/
public String toLowerCase() {
@@ -2576,11 +2576,11 @@
}
/**
- * Converts all of the characters in this <code>String</code> to upper
- * case using the rules of the given <code>Locale</code>. Case mapping is based
+ * Converts all of the characters in this {@code String} to upper
+ * case using the rules of the given {@code Locale}. Case mapping is based
* on the Unicode Standard version specified by the {@link java.lang.Character Character}
* class. Since case mappings are not always 1:1 char mappings, the resulting
- * <code>String</code> may be a different length than the original <code>String</code>.
+ * {@code String} may be a different length than the original {@code String}.
* <p>
* Examples of locale-sensitive and 1:M case mappings are in the following table.
* <p>
@@ -2617,7 +2617,7 @@
* </tr>
* </table>
* @param locale use the case transformation rules for this locale
- * @return the <code>String</code>, converted to uppercase.
+ * @return the {@code String}, converted to uppercase.
* @see java.lang.String#toUpperCase()
* @see java.lang.String#toLowerCase()
* @see java.lang.String#toLowerCase(Locale)
@@ -2716,22 +2716,22 @@
}
/**
- * Converts all of the characters in this <code>String</code> to upper
+ * Converts all of the characters in this {@code String} to upper
* case using the rules of the default locale. This method is equivalent to
- * <code>toUpperCase(Locale.getDefault())</code>.
+ * {@code toUpperCase(Locale.getDefault())}.
* <p>
* <b>Note:</b> This method is locale sensitive, and may produce unexpected
* results if used for strings that are intended to be interpreted locale
* independently.
* Examples are programming language identifiers, protocol keys, and HTML
* tags.
- * For instance, <code>"title".toUpperCase()</code> in a Turkish locale
- * returns <code>"T\u005Cu0130TLE"</code>, where '\u005Cu0130' is the
+ * For instance, {@code "title".toUpperCase()} in a Turkish locale
+ * returns {@code "T\u005Cu0130TLE"}, where '\u005Cu0130' is the
* LATIN CAPITAL LETTER I WITH DOT ABOVE character.
* To obtain correct results for locale insensitive strings, use
- * <code>toUpperCase(Locale.ENGLISH)</code>.
+ * {@code toUpperCase(Locale.ENGLISH)}.
* <p>
- * @return the <code>String</code>, converted to uppercase.
+ * @return the {@code String}, converted to uppercase.
* @see java.lang.String#toUpperCase(Locale)
*/
public String toUpperCase() {
@@ -2742,21 +2742,21 @@
* Returns a copy of the string, with leading and trailing whitespace
* omitted.
* <p>
- * If this <code>String</code> object represents an empty character
+ * If this {@code String} object represents an empty character
* sequence, or the first and last characters of character sequence
- * represented by this <code>String</code> object both have codes
- * greater than <code>'\u0020'</code> (the space character), then a
- * reference to this <code>String</code> object is returned.
+ * represented by this {@code String} object both have codes
+ * greater than {@code '\u005Cu0020'} (the space character), then a
+ * reference to this {@code String} object is returned.
* <p>
* Otherwise, if there is no character with a code greater than
- * <code>'\u0020'</code> in the string, then a new
- * <code>String</code> object representing an empty string is created
+ * {@code '\u005Cu0020'} in the string, then a new
+ * {@code String} object representing an empty string is created
* and returned.
* <p>
* Otherwise, let <i>k</i> be the index of the first character in the
- * string whose code is greater than <code>'\u0020'</code>, and let
+ * string whose code is greater than {@code '\u005Cu0020'}, and let
* <i>m</i> be the index of the last character in the string whose code
- * is greater than <code>'\u0020'</code>. A new <code>String</code>
+ * is greater than {@code '\u005Cu0020'}. A new {@code String}
* object is created, representing the substring of this string that
* begins with the character at index <i>k</i> and ends with the
* character at index <i>m</i>-that is, the result of
@@ -2893,12 +2893,12 @@
}
/**
- * Returns the string representation of the <code>Object</code> argument.
+ * Returns the string representation of the {@code Object} argument.
*
- * @param obj an <code>Object</code>.
- * @return if the argument is <code>null</code>, then a string equal to
- * <code>"null"</code>; otherwise, the value of
- * <code>obj.toString()</code> is returned.
+ * @param obj an {@code Object}.
+ * @return if the argument is {@code null}, then a string equal to
+ * {@code "null"}; otherwise, the value of
+ * {@code obj.toString()} is returned.
* @see java.lang.Object#toString()
*/
public static String valueOf(Object obj) {
@@ -2906,12 +2906,12 @@
}
/**
- * Returns the string representation of the <code>char</code> array
+ * Returns the string representation of the {@code char} array
* argument. The contents of the character array are copied; subsequent
* modification of the character array does not affect the newly
* created string.
*
- * @param data a <code>char</code> array.
+ * @param data a {@code char} array.
* @return a newly allocated string representing the same sequence of
* characters contained in the character array argument.
*/
@@ -2921,24 +2921,24 @@
/**
* Returns the string representation of a specific subarray of the
- * <code>char</code> array argument.
+ * {@code char} array argument.
* <p>
- * The <code>offset</code> argument is the index of the first
- * character of the subarray. The <code>count</code> argument
+ * The {@code offset} argument is the index of the first
+ * character of the subarray. The {@code count} argument
* specifies the length of the subarray. The contents of the subarray
* are copied; subsequent modification of the character array does not
* affect the newly created string.
*
* @param data the character array.
* @param offset the initial offset into the value of the
- * <code>String</code>.
- * @param count the length of the value of the <code>String</code>.
+ * {@code String}.
+ * @param count the length of the value of the {@code String}.
* @return a string representing the sequence of characters contained
* in the subarray of the character array argument.
- * @exception IndexOutOfBoundsException if <code>offset</code> is
- * negative, or <code>count</code> is negative, or
- * <code>offset+count</code> is larger than
- * <code>data.length</code>.
+ * @exception IndexOutOfBoundsException if {@code offset} is
+ * negative, or {@code count} is negative, or
+ * {@code offset+count} is larger than
+ * {@code data.length}.
*/
public static String valueOf(char data[], int offset, int count) {
return new String(data, offset, count);
@@ -2951,7 +2951,7 @@
* @param data the character array.
* @param offset initial offset of the subarray.
* @param count length of the subarray.
- * @return a <code>String</code> that contains the characters of the
+ * @return a {@code String} that contains the characters of the
* specified subarray of the character array.
*/
public static String copyValueOf(char data[], int offset, int count) {
@@ -2964,7 +2964,7 @@
* array specified.
*
* @param data the character array.
- * @return a <code>String</code> that contains the characters of the
+ * @return a {@code String} that contains the characters of the
* character array.
*/
public static String copyValueOf(char data[]) {
@@ -2972,24 +2972,24 @@
}
/**
- * Returns the string representation of the <code>boolean</code> argument.
+ * Returns the string representation of the {@code boolean} argument.
*
- * @param b a <code>boolean</code>.
- * @return if the argument is <code>true</code>, a string equal to
- * <code>"true"</code> is returned; otherwise, a string equal to
- * <code>"false"</code> is returned.
+ * @param b a {@code boolean}.
+ * @return if the argument is {@code true}, a string equal to
+ * {@code "true"} is returned; otherwise, a string equal to
+ * {@code "false"} is returned.
*/
public static String valueOf(boolean b) {
return b ? "true" : "false";
}
/**
- * Returns the string representation of the <code>char</code>
+ * Returns the string representation of the {@code char}
* argument.
*
- * @param c a <code>char</code>.
- * @return a string of length <code>1</code> containing
- * as its single character the argument <code>c</code>.
+ * @param c a {@code char}.
+ * @return a string of length {@code 1} containing
+ * as its single character the argument {@code c}.
*/
public static String valueOf(char c) {
char data[] = {c};
@@ -2997,13 +2997,13 @@
}
/**
- * Returns the string representation of the <code>int</code> argument.
+ * Returns the string representation of the {@code int} argument.
* <p>
* The representation is exactly the one returned by the
- * <code>Integer.toString</code> method of one argument.
+ * {@code Integer.toString} method of one argument.
*
- * @param i an <code>int</code>.
- * @return a string representation of the <code>int</code> argument.
+ * @param i an {@code int}.
+ * @return a string representation of the {@code int} argument.
* @see java.lang.Integer#toString(int, int)
*/
public static String valueOf(int i) {
@@ -3011,13 +3011,13 @@
}
/**
- * Returns the string representation of the <code>long</code> argument.
+ * Returns the string representation of the {@code long} argument.
* <p>
* The representation is exactly the one returned by the
- * <code>Long.toString</code> method of one argument.
+ * {@code Long.toString} method of one argument.
*
- * @param l a <code>long</code>.
- * @return a string representation of the <code>long</code> argument.
+ * @param l a {@code long}.
+ * @return a string representation of the {@code long} argument.
* @see java.lang.Long#toString(long)
*/
public static String valueOf(long l) {
@@ -3025,13 +3025,13 @@
}
/**
- * Returns the string representation of the <code>float</code> argument.
+ * Returns the string representation of the {@code float} argument.
* <p>
* The representation is exactly the one returned by the
- * <code>Float.toString</code> method of one argument.
+ * {@code Float.toString} method of one argument.
*
- * @param f a <code>float</code>.
- * @return a string representation of the <code>float</code> argument.
+ * @param f a {@code float}.
+ * @return a string representation of the {@code float} argument.
* @see java.lang.Float#toString(float)
*/
public static String valueOf(float f) {
@@ -3039,13 +3039,13 @@
}
/**
- * Returns the string representation of the <code>double</code> argument.
+ * Returns the string representation of the {@code double} argument.
* <p>
* The representation is exactly the one returned by the
- * <code>Double.toString</code> method of one argument.
+ * {@code Double.toString} method of one argument.
*
- * @param d a <code>double</code>.
- * @return a string representation of the <code>double</code> argument.
+ * @param d a {@code double}.
+ * @return a string representation of the {@code double} argument.
* @see java.lang.Double#toString(double)
*/
public static String valueOf(double d) {
@@ -3056,17 +3056,17 @@
* Returns a canonical representation for the string object.
* <p>
* A pool of strings, initially empty, is maintained privately by the
- * class <code>String</code>.
+ * class {@code String}.
* <p>
* When the intern method is invoked, if the pool already contains a
- * string equal to this <code>String</code> object as determined by
+ * string equal to this {@code String} object as determined by
* the {@link #equals(Object)} method, then the string from the pool is
- * returned. Otherwise, this <code>String</code> object is added to the
- * pool and a reference to this <code>String</code> object is returned.
+ * returned. Otherwise, this {@code String} object is added to the
+ * pool and a reference to this {@code String} object is returned.
* <p>
- * It follows that for any two strings <code>s</code> and <code>t</code>,
- * <code>s.intern() == t.intern()</code> is <code>true</code>
- * if and only if <code>s.equals(t)</code> is <code>true</code>.
+ * It follows that for any two strings {@code s} and {@code t},
+ * {@code s.intern() == t.intern()} is {@code true}
+ * if and only if {@code s.equals(t)} is {@code true}.
* <p>
* All literal strings and string-valued constant expressions are
* interned. String literals are defined in section 3.10.5 of the
--- a/jdk/src/share/classes/java/text/SimpleDateFormat.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/text/SimpleDateFormat.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2012, 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
@@ -1646,8 +1646,7 @@
// determine the local time. (6645292)
int dstAmount = (nameIndex >= 3) ? tz.getDSTSavings() : 0;
if (!(useSameName || (nameIndex >= 3 && dstAmount == 0))) {
- calb.set(Calendar.ZONE_OFFSET, tz.getRawOffset())
- .set(Calendar.DST_OFFSET, dstAmount);
+ calb.set(Calendar.DST_OFFSET, dstAmount);
}
return (start + zoneNames[nameIndex].length());
}
--- a/jdk/src/share/classes/java/util/Calendar.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/util/Calendar.java Tue Jan 31 19:08:36 2012 -0800
@@ -2705,7 +2705,7 @@
* removed from the serialization stream; this will probably happen in the
* near future.
*/
- private void writeObject(ObjectOutputStream stream)
+ private synchronized void writeObject(ObjectOutputStream stream)
throws IOException
{
// Try to compute the time correctly, for the future (stream
--- a/jdk/src/share/classes/java/util/EnumMap.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/util/EnumMap.java Tue Jan 31 19:08:36 2012 -0800
@@ -106,7 +106,15 @@
/**
* Distinguished non-null value for representing null values.
*/
- private static final Object NULL = new Integer(0);
+ private static final Object NULL = new Object() {
+ public int hashCode() {
+ return 0;
+ }
+
+ public String toString() {
+ return "java.util.EnumMap.NULL";
+ }
+ };
private Object maskNull(Object value) {
return (value == null ? NULL : value);
--- a/jdk/src/share/classes/java/util/Properties.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/util/Properties.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2012, 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
@@ -37,8 +37,8 @@
import java.lang.reflect.*;
/**
- * The <code>Properties</code> class represents a persistent set of
- * properties. The <code>Properties</code> can be saved to a stream
+ * The {@code Properties} class represents a persistent set of
+ * properties. The {@code Properties} can be saved to a stream
* or loaded from a stream. Each key and its corresponding value in
* the property list is a string.
* <p>
@@ -46,17 +46,17 @@
* "defaults"; this second property list is searched if
* the property key is not found in the original property list.
* <p>
- * Because <code>Properties</code> inherits from <code>Hashtable</code>, the
- * <code>put</code> and <code>putAll</code> methods can be applied to a
- * <code>Properties</code> object. Their use is strongly discouraged as they
+ * Because {@code Properties} inherits from {@code Hashtable}, the
+ * {@code put} and {@code putAll} methods can be applied to a
+ * {@code Properties} object. Their use is strongly discouraged as they
* allow the caller to insert entries whose keys or values are not
- * <code>Strings</code>. The <code>setProperty</code> method should be used
- * instead. If the <code>store</code> or <code>save</code> method is called
- * on a "compromised" <code>Properties</code> object that contains a
- * non-<code>String</code> key or value, the call will fail. Similarly,
- * the call to the <code>propertyNames</code> or <code>list</code> method
- * will fail if it is called on a "compromised" <code>Properties</code>
- * object that contains a non-<code>String</code> key.
+ * {@code Strings}. The {@code setProperty} method should be used
+ * instead. If the {@code store} or {@code save} method is called
+ * on a "compromised" {@code Properties} object that contains a
+ * non-{@code String} key or value, the call will fail. Similarly,
+ * the call to the {@code propertyNames} or {@code list} method
+ * will fail if it is called on a "compromised" {@code Properties}
+ * object that contains a non-{@code String} key.
*
* <p>
* The {@link #load(java.io.Reader) load(Reader)} <tt>/</tt>
@@ -146,15 +146,15 @@
}
/**
- * Calls the <tt>Hashtable</tt> method <code>put</code>. Provided for
+ * Calls the <tt>Hashtable</tt> method {@code put}. Provided for
* parallelism with the <tt>getProperty</tt> method. Enforces use of
* strings for property keys and values. The value returned is the
- * result of the <tt>Hashtable</tt> call to <code>put</code>.
+ * result of the <tt>Hashtable</tt> call to {@code put}.
*
* @param key the key to be placed into this property list.
* @param value the value corresponding to <tt>key</tt>.
* @return the previous value of the specified key in this property
- * list, or <code>null</code> if it did not have one.
+ * list, or {@code null} if it did not have one.
* @see #getProperty
* @since 1.2
*/
@@ -171,13 +171,13 @@
* kinds of line, <i>natural lines</i> and <i>logical lines</i>.
* A natural line is defined as a line of
* characters that is terminated either by a set of line terminator
- * characters (<code>\n</code> or <code>\r</code> or <code>\r\n</code>)
+ * characters ({@code \n} or {@code \r} or {@code \r\n})
* or by the end of the stream. A natural line may be either a blank line,
* a comment line, or hold all or some of a key-element pair. A logical
* line holds all the data of a key-element pair, which may be spread
* out across several adjacent natural lines by escaping
* the line terminator sequence with a backslash character
- * <code>\</code>. Note that a comment line cannot be extended
+ * {@code \}. Note that a comment line cannot be extended
* in this manner; every natural line that is a comment must have
* its own comment indicator, as described below. Lines are read from
* input until the end of the stream is reached.
@@ -185,13 +185,13 @@
* <p>
* A natural line that contains only white space characters is
* considered blank and is ignored. A comment line has an ASCII
- * <code>'#'</code> or <code>'!'</code> as its first non-white
+ * {@code '#'} or {@code '!'} as its first non-white
* space character; comment lines are also ignored and do not
* encode key-element information. In addition to line
* terminators, this format considers the characters space
- * (<code>' '</code>, <code>'\u0020'</code>), tab
- * (<code>'\t'</code>, <code>'\u0009'</code>), and form feed
- * (<code>'\f'</code>, <code>'\u000C'</code>) to be white
+ * ({@code ' '}, {@code '\u005Cu0020'}), tab
+ * ({@code '\t'}, {@code '\u005Cu0009'}), and form feed
+ * ({@code '\f'}, {@code '\u005Cu000C'}) to be white
* space.
*
* <p>
@@ -215,31 +215,31 @@
* <p>
* The key contains all of the characters in the line starting
* with the first non-white space character and up to, but not
- * including, the first unescaped <code>'='</code>,
- * <code>':'</code>, or white space character other than a line
+ * including, the first unescaped {@code '='},
+ * {@code ':'}, or white space character other than a line
* terminator. All of these key termination characters may be
* included in the key by escaping them with a preceding backslash
* character; for example,<p>
*
- * <code>\:\=</code><p>
+ * {@code \:\=}<p>
*
- * would be the two-character key <code>":="</code>. Line
- * terminator characters can be included using <code>\r</code> and
- * <code>\n</code> escape sequences. Any white space after the
+ * would be the two-character key {@code ":="}. Line
+ * terminator characters can be included using {@code \r} and
+ * {@code \n} escape sequences. Any white space after the
* key is skipped; if the first non-white space character after
- * the key is <code>'='</code> or <code>':'</code>, then it is
+ * the key is {@code '='} or {@code ':'}, then it is
* ignored and any white space characters after it are also
* skipped. All remaining characters on the line become part of
* the associated element string; if there are no remaining
* characters, the element is the empty string
- * <code>""</code>. Once the raw character sequences
+ * {@code ""}. Once the raw character sequences
* constituting the key and element are identified, escape
* processing is performed as described above.
*
* <p>
* As an example, each of the following three lines specifies the key
- * <code>"Truth"</code> and the associated element value
- * <code>"Beauty"</code>:
+ * {@code "Truth"} and the associated element value
+ * {@code "Beauty"}:
* <p>
* <pre>
* Truth = Beauty
@@ -254,11 +254,11 @@
* cantaloupe, watermelon, \
* kiwi, mango
* </pre>
- * The key is <code>"fruits"</code> and the associated element is:
+ * The key is {@code "fruits"} and the associated element is:
* <p>
* <pre>"apple, banana, pear, cantaloupe, watermelon, kiwi, mango"</pre>
- * Note that a space appears before each <code>\</code> so that a space
- * will appear after each comma in the final result; the <code>\</code>,
+ * Note that a space appears before each {@code \} so that a space
+ * will appear after each comma in the final result; the {@code \},
* line terminator, and leading white space on the continuation line are
* merely discarded and are <i>not</i> replaced by one or more other
* characters.
@@ -267,8 +267,8 @@
* <p>
* <pre>cheeses
* </pre>
- * specifies that the key is <code>"cheeses"</code> and the associated
- * element is the empty string <code>""</code>.<p>
+ * specifies that the key is {@code "cheeses"} and the associated
+ * element is the empty string {@code ""}.<p>
* <p>
*
* <a name="unicodeescapes"></a>
@@ -283,17 +283,17 @@
* <ul>
* <li> Octal escapes are not recognized.
*
- * <li> The character sequence <code>\b</code> does <i>not</i>
+ * <li> The character sequence {@code \b} does <i>not</i>
* represent a backspace character.
*
* <li> The method does not treat a backslash character,
- * <code>\</code>, before a non-valid escape character as an
+ * {@code \}, before a non-valid escape character as an
* error; the backslash is silently dropped. For example, in a
- * Java string the sequence <code>"\z"</code> would cause a
+ * Java string the sequence {@code "\z"} would cause a
* compile time error. In contrast, this method silently drops
* the backslash. Therefore, this method treats the two character
- * sequence <code>"\b"</code> as equivalent to the single
- * character <code>'b'</code>.
+ * sequence {@code "\b"} as equivalent to the single
+ * character {@code 'b'}.
*
* <li> Escapes are not necessary for single and double quotes;
* however, by the rule above, single and double quote characters
@@ -689,20 +689,20 @@
}
/**
- * Calls the <code>store(OutputStream out, String comments)</code> method
+ * Calls the {@code store(OutputStream out, String comments)} method
* and suppresses IOExceptions that were thrown.
*
* @deprecated This method does not throw an IOException if an I/O error
* occurs while saving the property list. The preferred way to save a
- * properties list is via the <code>store(OutputStream out,
- * String comments)</code> method or the
- * <code>storeToXML(OutputStream os, String comment)</code> method.
+ * properties list is via the {@code store(OutputStream out,
+ * String comments)} method or the
+ * {@code storeToXML(OutputStream os, String comment)} method.
*
* @param out an output stream.
* @param comments a description of the property list.
- * @exception ClassCastException if this <code>Properties</code> object
+ * @exception ClassCastException if this {@code Properties} object
* contains any keys or values that are not
- * <code>Strings</code>.
+ * {@code Strings}.
*/
@Deprecated
public void save(OutputStream out, String comments) {
@@ -714,37 +714,37 @@
/**
* Writes this property list (key and element pairs) in this
- * <code>Properties</code> table to the output character stream in a
+ * {@code Properties} table to the output character stream in a
* format suitable for using the {@link #load(java.io.Reader) load(Reader)}
* method.
* <p>
- * Properties from the defaults table of this <code>Properties</code>
+ * Properties from the defaults table of this {@code Properties}
* table (if any) are <i>not</i> written out by this method.
* <p>
- * If the comments argument is not null, then an ASCII <code>#</code>
+ * If the comments argument is not null, then an ASCII {@code #}
* character, the comments string, and a line separator are first written
- * to the output stream. Thus, the <code>comments</code> can serve as an
+ * to the output stream. Thus, the {@code comments} can serve as an
* identifying comment. Any one of a line feed ('\n'), a carriage
* return ('\r'), or a carriage return followed immediately by a line feed
- * in comments is replaced by a line separator generated by the <code>Writer</code>
- * and if the next character in comments is not character <code>#</code> or
- * character <code>!</code> then an ASCII <code>#</code> is written out
+ * in comments is replaced by a line separator generated by the {@code Writer}
+ * and if the next character in comments is not character {@code #} or
+ * character {@code !} then an ASCII {@code #} is written out
* after that line separator.
* <p>
* Next, a comment line is always written, consisting of an ASCII
- * <code>#</code> character, the current date and time (as if produced
- * by the <code>toString</code> method of <code>Date</code> for the
- * current time), and a line separator as generated by the <code>Writer</code>.
+ * {@code #} character, the current date and time (as if produced
+ * by the {@code toString} method of {@code Date} for the
+ * current time), and a line separator as generated by the {@code Writer}.
* <p>
- * Then every entry in this <code>Properties</code> table is
+ * Then every entry in this {@code Properties} table is
* written out, one per line. For each entry the key string is
- * written, then an ASCII <code>=</code>, then the associated
+ * written, then an ASCII {@code =}, then the associated
* element string. For the key, all space characters are
- * written with a preceding <code>\</code> character. For the
+ * written with a preceding {@code \} character. For the
* element, leading space characters, but not embedded or trailing
- * space characters, are written with a preceding <code>\</code>
- * character. The key and element characters <code>#</code>,
- * <code>!</code>, <code>=</code>, and <code>:</code> are written
+ * space characters, are written with a preceding {@code \}
+ * character. The key and element characters {@code #},
+ * {@code !}, {@code =}, and {@code :} are written
* with a preceding backslash to ensure that they are properly loaded.
* <p>
* After the entries have been written, the output stream is flushed.
@@ -755,9 +755,9 @@
* @param comments a description of the property list.
* @exception IOException if writing this property list to the specified
* output stream throws an <tt>IOException</tt>.
- * @exception ClassCastException if this <code>Properties</code> object
- * contains any keys or values that are not <code>Strings</code>.
- * @exception NullPointerException if <code>writer</code> is null.
+ * @exception ClassCastException if this {@code Properties} object
+ * contains any keys or values that are not {@code Strings}.
+ * @exception NullPointerException if {@code writer} is null.
* @since 1.6
*/
public void store(Writer writer, String comments)
@@ -771,11 +771,11 @@
/**
* Writes this property list (key and element pairs) in this
- * <code>Properties</code> table to the output stream in a format suitable
- * for loading into a <code>Properties</code> table using the
+ * {@code Properties} table to the output stream in a format suitable
+ * for loading into a {@code Properties} table using the
* {@link #load(InputStream) load(InputStream)} method.
* <p>
- * Properties from the defaults table of this <code>Properties</code>
+ * Properties from the defaults table of this {@code Properties}
* table (if any) are <i>not</i> written out by this method.
* <p>
* This method outputs the comments, properties keys and values in
@@ -786,12 +786,12 @@
* <li>The stream is written using the ISO 8859-1 character encoding.
*
* <li>Characters not in Latin-1 in the comments are written as
- * <code>\u</code><i>xxxx</i> for their appropriate unicode
+ * {@code \u005Cu}<i>xxxx</i> for their appropriate unicode
* hexadecimal value <i>xxxx</i>.
*
- * <li>Characters less than <code>\u0020</code> and characters greater
- * than <code>\u007E</code> in property keys or values are written
- * as <code>\u</code><i>xxxx</i> for the appropriate hexadecimal
+ * <li>Characters less than {@code \u005Cu0020} and characters greater
+ * than {@code \u005Cu007E} in property keys or values are written
+ * as {@code \u005Cu}<i>xxxx</i> for the appropriate hexadecimal
* value <i>xxxx</i>.
* </ul>
* <p>
@@ -802,9 +802,9 @@
* @param comments a description of the property list.
* @exception IOException if writing this property list to the specified
* output stream throws an <tt>IOException</tt>.
- * @exception ClassCastException if this <code>Properties</code> object
- * contains any keys or values that are not <code>Strings</code>.
- * @exception NullPointerException if <code>out</code> is null.
+ * @exception ClassCastException if this {@code Properties} object
+ * contains any keys or values that are not {@code Strings}.
+ * @exception NullPointerException if {@code out} is null.
* @since 1.2
*/
public void store(OutputStream out, String comments)
@@ -857,7 +857,7 @@
* results in an <tt>IOException</tt>.
* @throws InvalidPropertiesFormatException Data on input stream does not
* constitute a valid XML document with the mandated document type.
- * @throws NullPointerException if <code>in</code> is null.
+ * @throws NullPointerException if {@code in} is null.
* @see #storeToXML(OutputStream, String, String)
* @since 1.5
*/
@@ -879,14 +879,14 @@
* <tt>props.storeToXML(os, comment, "UTF-8");</tt>.
*
* @param os the output stream on which to emit the XML document.
- * @param comment a description of the property list, or <code>null</code>
+ * @param comment a description of the property list, or {@code null}
* if no comment is desired.
* @throws IOException if writing to the specified output stream
* results in an <tt>IOException</tt>.
- * @throws NullPointerException if <code>os</code> is null.
- * @throws ClassCastException if this <code>Properties</code> object
+ * @throws NullPointerException if {@code os} is null.
+ * @throws ClassCastException if this {@code Properties} object
* contains any keys or values that are not
- * <code>Strings</code>.
+ * {@code Strings}.
* @see #loadFromXML(InputStream)
* @since 1.5
*/
@@ -907,13 +907,13 @@
* <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
* </pre>
*
- *<p>If the specified comment is <code>null</code> then no comment
+ *<p>If the specified comment is {@code null} then no comment
* will be stored in the document.
*
* <p>The specified stream remains open after this method returns.
*
* @param os the output stream on which to emit the XML document.
- * @param comment a description of the property list, or <code>null</code>
+ * @param comment a description of the property list, or {@code null}
* if no comment is desired.
* @param encoding the name of a supported
* <a href="../lang/package-summary.html#charenc">
@@ -921,11 +921,11 @@
*
* @throws IOException if writing to the specified output stream
* results in an <tt>IOException</tt>.
- * @throws NullPointerException if <code>os</code> is <code>null</code>,
- * or if <code>encoding</code> is <code>null</code>.
- * @throws ClassCastException if this <code>Properties</code> object
+ * @throws NullPointerException if {@code os} is {@code null},
+ * or if {@code encoding} is {@code null}.
+ * @throws ClassCastException if this {@code Properties} object
* contains any keys or values that are not
- * <code>Strings</code>.
+ * {@code Strings}.
* @see #loadFromXML(InputStream)
* @since 1.5
*/
@@ -941,7 +941,7 @@
* Searches for the property with the specified key in this property list.
* If the key is not found in this property list, the default property list,
* and its defaults, recursively, are then checked. The method returns
- * <code>null</code> if the property is not found.
+ * {@code null} if the property is not found.
*
* @param key the property key.
* @return the value in this property list with the specified key value.
--- a/jdk/src/share/classes/java/util/concurrent/FutureTask.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/FutureTask.java Tue Jan 31 19:08:36 2012 -0800
@@ -34,51 +34,111 @@
*/
package java.util.concurrent;
-import java.util.concurrent.locks.*;
+import java.util.concurrent.locks.LockSupport;
/**
* A cancellable asynchronous computation. This class provides a base
* implementation of {@link Future}, with methods to start and cancel
* a computation, query to see if the computation is complete, and
* retrieve the result of the computation. The result can only be
- * retrieved when the computation has completed; the <tt>get</tt>
- * method will block if the computation has not yet completed. Once
+ * retrieved when the computation has completed; the {@code get}
+ * methods will block if the computation has not yet completed. Once
* the computation has completed, the computation cannot be restarted
- * or cancelled.
+ * or cancelled (unless the computation is invoked using
+ * {@link #runAndReset}).
*
- * <p>A <tt>FutureTask</tt> can be used to wrap a {@link Callable} or
- * {@link java.lang.Runnable} object. Because <tt>FutureTask</tt>
- * implements <tt>Runnable</tt>, a <tt>FutureTask</tt> can be
- * submitted to an {@link Executor} for execution.
+ * <p>A {@code FutureTask} can be used to wrap a {@link Callable} or
+ * {@link Runnable} object. Because {@code FutureTask} implements
+ * {@code Runnable}, a {@code FutureTask} can be submitted to an
+ * {@link Executor} for execution.
*
* <p>In addition to serving as a standalone class, this class provides
- * <tt>protected</tt> functionality that may be useful when creating
+ * {@code protected} functionality that may be useful when creating
* customized task classes.
*
* @since 1.5
* @author Doug Lea
- * @param <V> The result type returned by this FutureTask's <tt>get</tt> method
+ * @param <V> The result type returned by this FutureTask's {@code get} methods
*/
public class FutureTask<V> implements RunnableFuture<V> {
- /** Synchronization control for FutureTask */
- private final Sync sync;
+ /*
+ * Revision notes: This differs from previous versions of this
+ * class that relied on AbstractQueuedSynchronizer, mainly to
+ * avoid surprising users about retaining interrupt status during
+ * cancellation races. Sync control in the current design relies
+ * on a "state" field updated via CAS to track completion, along
+ * with a simple Treiber stack to hold waiting threads.
+ *
+ * Style note: As usual, we bypass overhead of using
+ * AtomicXFieldUpdaters and instead directly use Unsafe intrinsics.
+ */
/**
- * Creates a <tt>FutureTask</tt> that will, upon running, execute the
- * given <tt>Callable</tt>.
+ * The run state of this task, initially NEW. The run state
+ * transitions to a terminal state only in methods set,
+ * setException, and cancel. During completion, state may take on
+ * transient values of COMPLETING (while outcome is being set) or
+ * INTERRUPTING (only while interrupting the runner to satisfy a
+ * cancel(true)). Transitions from these intermediate to final
+ * states use cheaper ordered/lazy writes because values are unique
+ * and cannot be further modified.
+ *
+ * Possible state transitions:
+ * NEW -> COMPLETING -> NORMAL
+ * NEW -> COMPLETING -> EXCEPTIONAL
+ * NEW -> CANCELLED
+ * NEW -> INTERRUPTING -> INTERRUPTED
+ */
+ private volatile int state;
+ private static final int NEW = 0;
+ private static final int COMPLETING = 1;
+ private static final int NORMAL = 2;
+ private static final int EXCEPTIONAL = 3;
+ private static final int CANCELLED = 4;
+ private static final int INTERRUPTING = 5;
+ private static final int INTERRUPTED = 6;
+
+ /** The underlying callable; nulled out after running */
+ private Callable<V> callable;
+ /** The result to return or exception to throw from get() */
+ private Object outcome; // non-volatile, protected by state reads/writes
+ /** The thread running the callable; CASed during run() */
+ private volatile Thread runner;
+ /** Treiber stack of waiting threads */
+ private volatile WaitNode waiters;
+
+ /**
+ * Returns result or throws exception for completed task.
+ *
+ * @param s completed state value
+ */
+ @SuppressWarnings("unchecked")
+ private V report(int s) throws ExecutionException {
+ Object x = outcome;
+ if (s == NORMAL)
+ return (V)x;
+ if (s >= CANCELLED)
+ throw new CancellationException();
+ throw new ExecutionException((Throwable)x);
+ }
+
+ /**
+ * Creates a {@code FutureTask} that will, upon running, execute the
+ * given {@code Callable}.
*
* @param callable the callable task
- * @throws NullPointerException if callable is null
+ * @throws NullPointerException if the callable is null
*/
public FutureTask(Callable<V> callable) {
if (callable == null)
throw new NullPointerException();
- sync = new Sync(callable);
+ this.callable = callable;
+ this.state = NEW; // ensure visibility of callable
}
/**
- * Creates a <tt>FutureTask</tt> that will, upon running, execute the
- * given <tt>Runnable</tt>, and arrange that <tt>get</tt> will return the
+ * Creates a {@code FutureTask} that will, upon running, execute the
+ * given {@code Runnable}, and arrange that {@code get} will return the
* given result on successful completion.
*
* @param runnable the runnable task
@@ -86,29 +146,46 @@
* you don't need a particular result, consider using
* constructions of the form:
* {@code Future<?> f = new FutureTask<Void>(runnable, null)}
- * @throws NullPointerException if runnable is null
+ * @throws NullPointerException if the runnable is null
*/
public FutureTask(Runnable runnable, V result) {
- sync = new Sync(Executors.callable(runnable, result));
+ this.callable = Executors.callable(runnable, result);
+ this.state = NEW; // ensure visibility of callable
}
public boolean isCancelled() {
- return sync.innerIsCancelled();
+ return state >= CANCELLED;
}
public boolean isDone() {
- return sync.innerIsDone();
+ return state != NEW;
}
public boolean cancel(boolean mayInterruptIfRunning) {
- return sync.innerCancel(mayInterruptIfRunning);
+ if (state != NEW)
+ return false;
+ if (mayInterruptIfRunning) {
+ if (!UNSAFE.compareAndSwapInt(this, stateOffset, NEW, INTERRUPTING))
+ return false;
+ Thread t = runner;
+ if (t != null)
+ t.interrupt();
+ UNSAFE.putOrderedInt(this, stateOffset, INTERRUPTED); // final state
+ }
+ else if (!UNSAFE.compareAndSwapInt(this, stateOffset, NEW, CANCELLED))
+ return false;
+ finishCompletion();
+ return true;
}
/**
* @throws CancellationException {@inheritDoc}
*/
public V get() throws InterruptedException, ExecutionException {
- return sync.innerGet();
+ int s = state;
+ if (s <= COMPLETING)
+ s = awaitDone(false, 0L);
+ return report(s);
}
/**
@@ -116,12 +193,18 @@
*/
public V get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
- return sync.innerGet(unit.toNanos(timeout));
+ if (unit == null)
+ throw new NullPointerException();
+ int s = state;
+ if (s <= COMPLETING &&
+ (s = awaitDone(true, unit.toNanos(timeout))) <= COMPLETING)
+ throw new TimeoutException();
+ return report(s);
}
/**
* Protected method invoked when this task transitions to state
- * <tt>isDone</tt> (whether normally or via cancellation). The
+ * {@code isDone} (whether normally or via cancellation). The
* default implementation does nothing. Subclasses may override
* this method to invoke completion callbacks or perform
* bookkeeping. Note that you can query status inside the
@@ -131,230 +214,269 @@
protected void done() { }
/**
- * Sets the result of this Future to the given value unless
+ * Sets the result of this future to the given value unless
* this future has already been set or has been cancelled.
- * This method is invoked internally by the <tt>run</tt> method
+ *
+ * <p>This method is invoked internally by the {@link #run} method
* upon successful completion of the computation.
+ *
* @param v the value
*/
protected void set(V v) {
- sync.innerSet(v);
+ if (UNSAFE.compareAndSwapInt(this, stateOffset, NEW, COMPLETING)) {
+ outcome = v;
+ UNSAFE.putOrderedInt(this, stateOffset, NORMAL); // final state
+ finishCompletion();
+ }
}
/**
- * Causes this future to report an <tt>ExecutionException</tt>
- * with the given throwable as its cause, unless this Future has
+ * Causes this future to report an {@link ExecutionException}
+ * with the given throwable as its cause, unless this future has
* already been set or has been cancelled.
- * This method is invoked internally by the <tt>run</tt> method
+ *
+ * <p>This method is invoked internally by the {@link #run} method
* upon failure of the computation.
+ *
* @param t the cause of failure
*/
protected void setException(Throwable t) {
- sync.innerSetException(t);
+ if (UNSAFE.compareAndSwapInt(this, stateOffset, NEW, COMPLETING)) {
+ outcome = t;
+ UNSAFE.putOrderedInt(this, stateOffset, EXCEPTIONAL); // final state
+ finishCompletion();
+ }
}
- // The following (duplicated) doc comment can be removed once
- //
- // 6270645: Javadoc comments should be inherited from most derived
- // superinterface or superclass
- // is fixed.
- /**
- * Sets this Future to the result of its computation
- * unless it has been cancelled.
- */
public void run() {
- sync.innerRun();
+ if (state != NEW ||
+ !UNSAFE.compareAndSwapObject(this, runnerOffset,
+ null, Thread.currentThread()))
+ return;
+ try {
+ Callable<V> c = callable;
+ if (c != null && state == NEW) {
+ V result;
+ boolean ran;
+ try {
+ result = c.call();
+ ran = true;
+ } catch (Throwable ex) {
+ result = null;
+ ran = false;
+ setException(ex);
+ }
+ if (ran)
+ set(result);
+ }
+ } finally {
+ // runner must be non-null until state is settled to
+ // prevent concurrent calls to run()
+ runner = null;
+ // state must be re-read after nulling runner to prevent
+ // leaked interrupts
+ int s = state;
+ if (s >= INTERRUPTING)
+ handlePossibleCancellationInterrupt(s);
+ }
}
/**
* Executes the computation without setting its result, and then
- * resets this Future to initial state, failing to do so if the
+ * resets this future to initial state, failing to do so if the
* computation encounters an exception or is cancelled. This is
* designed for use with tasks that intrinsically execute more
* than once.
+ *
* @return true if successfully run and reset
*/
protected boolean runAndReset() {
- return sync.innerRunAndReset();
+ if (state != NEW ||
+ !UNSAFE.compareAndSwapObject(this, runnerOffset,
+ null, Thread.currentThread()))
+ return false;
+ boolean ran = false;
+ int s = state;
+ try {
+ Callable<V> c = callable;
+ if (c != null && s == NEW) {
+ try {
+ c.call(); // don't set result
+ ran = true;
+ } catch (Throwable ex) {
+ setException(ex);
+ }
+ }
+ } finally {
+ // runner must be non-null until state is settled to
+ // prevent concurrent calls to run()
+ runner = null;
+ // state must be re-read after nulling runner to prevent
+ // leaked interrupts
+ s = state;
+ if (s >= INTERRUPTING)
+ handlePossibleCancellationInterrupt(s);
+ }
+ return ran && s == NEW;
+ }
+
+ /**
+ * Ensures that any interrupt from a possible cancel(true) is only
+ * delivered to a task while in run or runAndReset.
+ */
+ private void handlePossibleCancellationInterrupt(int s) {
+ // It is possible for our interrupter to stall before getting a
+ // chance to interrupt us. Let's spin-wait patiently.
+ if (s == INTERRUPTING)
+ while (state == INTERRUPTING)
+ Thread.yield(); // wait out pending interrupt
+
+ // assert state == INTERRUPTED;
+
+ // We want to clear any interrupt we may have received from
+ // cancel(true). However, it is permissible to use interrupts
+ // as an independent mechanism for a task to communicate with
+ // its caller, and there is no way to clear only the
+ // cancellation interrupt.
+ //
+ // Thread.interrupted();
+ }
+
+ /**
+ * Simple linked list nodes to record waiting threads in a Treiber
+ * stack. See other classes such as Phaser and SynchronousQueue
+ * for more detailed explanation.
+ */
+ static final class WaitNode {
+ volatile Thread thread;
+ volatile WaitNode next;
+ WaitNode() { thread = Thread.currentThread(); }
}
/**
- * Synchronization control for FutureTask. Note that this must be
- * a non-static inner class in order to invoke the protected
- * <tt>done</tt> method. For clarity, all inner class support
- * methods are same as outer, prefixed with "inner".
- *
- * Uses AQS sync state to represent run status
+ * Removes and signals all waiting threads, invokes done(), and
+ * nulls out callable.
*/
- private final class Sync extends AbstractQueuedSynchronizer {
- private static final long serialVersionUID = -7828117401763700385L;
-
- /** State value representing that task is ready to run */
- private static final int READY = 0;
- /** State value representing that task is running */
- private static final int RUNNING = 1;
- /** State value representing that task ran */
- private static final int RAN = 2;
- /** State value representing that task was cancelled */
- private static final int CANCELLED = 4;
-
- /** The underlying callable */
- private final Callable<V> callable;
- /** The result to return from get() */
- private V result;
- /** The exception to throw from get() */
- private Throwable exception;
-
- /**
- * The thread running task. When nulled after set/cancel, this
- * indicates that the results are accessible. Must be
- * volatile, to ensure visibility upon completion.
- */
- private volatile Thread runner;
-
- Sync(Callable<V> callable) {
- this.callable = callable;
- }
-
- private boolean ranOrCancelled(int state) {
- return (state & (RAN | CANCELLED)) != 0;
- }
-
- /**
- * Implements AQS base acquire to succeed if ran or cancelled
- */
- protected int tryAcquireShared(int ignore) {
- return innerIsDone() ? 1 : -1;
- }
-
- /**
- * Implements AQS base release to always signal after setting
- * final done status by nulling runner thread.
- */
- protected boolean tryReleaseShared(int ignore) {
- runner = null;
- return true;
- }
-
- boolean innerIsCancelled() {
- return getState() == CANCELLED;
- }
-
- boolean innerIsDone() {
- return ranOrCancelled(getState()) && runner == null;
- }
-
- V innerGet() throws InterruptedException, ExecutionException {
- acquireSharedInterruptibly(0);
- if (getState() == CANCELLED)
- throw new CancellationException();
- if (exception != null)
- throw new ExecutionException(exception);
- return result;
- }
-
- V innerGet(long nanosTimeout) throws InterruptedException, ExecutionException, TimeoutException {
- if (!tryAcquireSharedNanos(0, nanosTimeout))
- throw new TimeoutException();
- if (getState() == CANCELLED)
- throw new CancellationException();
- if (exception != null)
- throw new ExecutionException(exception);
- return result;
- }
-
- void innerSet(V v) {
- for (;;) {
- int s = getState();
- if (s == RAN)
- return;
- if (s == CANCELLED) {
- // aggressively release to set runner to null,
- // in case we are racing with a cancel request
- // that will try to interrupt runner
- releaseShared(0);
- return;
+ private void finishCompletion() {
+ // assert state > COMPLETING;
+ for (WaitNode q; (q = waiters) != null;) {
+ if (UNSAFE.compareAndSwapObject(this, waitersOffset, q, null)) {
+ for (;;) {
+ Thread t = q.thread;
+ if (t != null) {
+ q.thread = null;
+ LockSupport.unpark(t);
+ }
+ WaitNode next = q.next;
+ if (next == null)
+ break;
+ q.next = null; // unlink to help gc
+ q = next;
}
- if (compareAndSetState(s, RAN)) {
- result = v;
- releaseShared(0);
- done();
- return;
- }
+ break;
}
}
- void innerSetException(Throwable t) {
- for (;;) {
- int s = getState();
- if (s == RAN)
- return;
- if (s == CANCELLED) {
- // aggressively release to set runner to null,
- // in case we are racing with a cancel request
- // that will try to interrupt runner
- releaseShared(0);
- return;
- }
- if (compareAndSetState(s, RAN)) {
- exception = t;
- releaseShared(0);
- done();
- return;
- }
+ done();
+
+ callable = null; // to reduce footprint
+ }
+
+ /**
+ * Awaits completion or aborts on interrupt or timeout.
+ *
+ * @param timed true if use timed waits
+ * @param nanos time to wait, if timed
+ * @return state upon completion
+ */
+ private int awaitDone(boolean timed, long nanos)
+ throws InterruptedException {
+ final long deadline = timed ? System.nanoTime() + nanos : 0L;
+ WaitNode q = null;
+ boolean queued = false;
+ for (;;) {
+ if (Thread.interrupted()) {
+ removeWaiter(q);
+ throw new InterruptedException();
}
- }
- boolean innerCancel(boolean mayInterruptIfRunning) {
- for (;;) {
- int s = getState();
- if (ranOrCancelled(s))
- return false;
- if (compareAndSetState(s, CANCELLED))
- break;
- }
- if (mayInterruptIfRunning) {
- Thread r = runner;
- if (r != null)
- r.interrupt();
+ int s = state;
+ if (s > COMPLETING) {
+ if (q != null)
+ q.thread = null;
+ return s;
}
- releaseShared(0);
- done();
- return true;
- }
-
- void innerRun() {
- if (!compareAndSetState(READY, RUNNING))
- return;
-
- runner = Thread.currentThread();
- if (getState() == RUNNING) { // recheck after setting thread
- V result;
- try {
- result = callable.call();
- } catch (Throwable ex) {
- setException(ex);
- return;
+ else if (s == COMPLETING) // cannot time out yet
+ Thread.yield();
+ else if (q == null)
+ q = new WaitNode();
+ else if (!queued)
+ queued = UNSAFE.compareAndSwapObject(this, waitersOffset,
+ q.next = waiters, q);
+ else if (timed) {
+ nanos = deadline - System.nanoTime();
+ if (nanos <= 0L) {
+ removeWaiter(q);
+ return state;
}
- set(result);
- } else {
- releaseShared(0); // cancel
+ LockSupport.parkNanos(this, nanos);
}
+ else
+ LockSupport.park(this);
}
+ }
- boolean innerRunAndReset() {
- if (!compareAndSetState(READY, RUNNING))
- return false;
- try {
- runner = Thread.currentThread();
- if (getState() == RUNNING)
- callable.call(); // don't set result
- runner = null;
- return compareAndSetState(RUNNING, READY);
- } catch (Throwable ex) {
- setException(ex);
- return false;
+ /**
+ * Tries to unlink a timed-out or interrupted wait node to avoid
+ * accumulating garbage. Internal nodes are simply unspliced
+ * without CAS since it is harmless if they are traversed anyway
+ * by releasers. To avoid effects of unsplicing from already
+ * removed nodes, the list is retraversed in case of an apparent
+ * race. This is slow when there are a lot of nodes, but we don't
+ * expect lists to be long enough to outweigh higher-overhead
+ * schemes.
+ */
+ private void removeWaiter(WaitNode node) {
+ if (node != null) {
+ node.thread = null;
+ retry:
+ for (;;) { // restart on removeWaiter race
+ for (WaitNode pred = null, q = waiters, s; q != null; q = s) {
+ s = q.next;
+ if (q.thread != null)
+ pred = q;
+ else if (pred != null) {
+ pred.next = s;
+ if (pred.thread == null) // check for race
+ continue retry;
+ }
+ else if (!UNSAFE.compareAndSwapObject(this, waitersOffset,
+ q, s))
+ continue retry;
+ }
+ break;
}
}
}
+
+ // Unsafe mechanics
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long stateOffset;
+ private static final long runnerOffset;
+ private static final long waitersOffset;
+ static {
+ try {
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class<?> k = FutureTask.class;
+ stateOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("state"));
+ runnerOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("runner"));
+ waitersOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("waiters"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
}
--- a/jdk/src/share/classes/javax/crypto/Cipher.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/javax/crypto/Cipher.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2012, 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
@@ -26,6 +26,8 @@
package javax.crypto;
import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import java.util.regex.*;
@@ -389,16 +391,15 @@
return matches(regexp, value) ? S_YES : S_NO;
}
- // Map<String,Pattern> for previously compiled patterns
- // XXX use ConcurrentHashMap once available
- private final static Map<String, Pattern> patternCache =
- Collections.synchronizedMap(new HashMap<String, Pattern>());
+ // ConcurrentMap<String,Pattern> for previously compiled patterns
+ private final static ConcurrentMap<String, Pattern> patternCache =
+ new ConcurrentHashMap<String, Pattern>();
private static boolean matches(String regexp, String str) {
Pattern pattern = patternCache.get(regexp);
if (pattern == null) {
pattern = Pattern.compile(regexp);
- patternCache.put(regexp, pattern);
+ patternCache.putIfAbsent(regexp, pattern);
}
return pattern.matcher(str.toUpperCase(Locale.ENGLISH)).matches();
}
--- a/jdk/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, 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
@@ -25,6 +25,7 @@
package javax.sql.rowset.serial;
import java.sql.*;
+import java.util.Arrays;
import java.util.Map;
/**
@@ -119,7 +120,7 @@
"object with null parameters");
}
// assign our local reference to the attribute stream
- attrib = attributes;
+ attrib = Arrays.copyOf(attributes, attributes.length);
// init the index point before the head of the stream
idx = -1;
// set the map
--- a/jdk/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, 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
@@ -25,11 +25,10 @@
package javax.sql.rowset.serial;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.sql.*;
-import javax.sql.*;
-import java.io.*;
-import java.lang.String;
-import java.math.*;
import java.util.Map;
import java.util.Vector;
@@ -444,16 +443,15 @@
* will need to track if a field is SQL null for itself
*/
if (x == null) {
- attribs.add(x);
- return;
+ attribs.add(null);
+ } else {
+ /*
+ * We have to write out a SerialStruct that contains
+ * the name of this class otherwise we don't know
+ * what to re-instantiate during readSQL()
+ */
+ attribs.add(new SerialStruct(x, map));
}
-
- /*
- * We have to write out a SerialStruct that contains
- * the name of this class otherwise we don't know
- * what to re-instantiate during readSQL()
- */
- attribs.add(new SerialStruct(x, map));
}
/**
@@ -470,10 +468,10 @@
@SuppressWarnings("unchecked")
public void writeRef(Ref x) throws SQLException {
if (x == null) {
- attribs.add(x);
- return;
+ attribs.add(null);
+ } else {
+ attribs.add(new SerialRef(x));
}
- attribs.add(new SerialRef(x));
}
/**
@@ -490,10 +488,10 @@
@SuppressWarnings("unchecked")
public void writeBlob(Blob x) throws SQLException {
if (x == null) {
- attribs.add(x);
- return;
+ attribs.add(null);
+ } else {
+ attribs.add(new SerialBlob(x));
}
- attribs.add(new SerialBlob(x));
}
/**
@@ -510,10 +508,10 @@
@SuppressWarnings("unchecked")
public void writeClob(Clob x) throws SQLException {
if (x == null) {
- attribs.add(x);
- return;
+ attribs.add(null);
+ } else {
+ attribs.add(new SerialClob(x));
}
- attribs.add(new SerialClob(x));
}
/**
@@ -554,10 +552,10 @@
@SuppressWarnings("unchecked")
public void writeArray(Array x) throws SQLException {
if (x == null) {
- attribs.add(x);
- return;
+ attribs.add(null);
+ } else {
+ attribs.add(new SerialArray(x, map));
}
- attribs.add(new SerialArray(x, map));
}
/**
@@ -574,11 +572,10 @@
@SuppressWarnings("unchecked")
public void writeURL(java.net.URL url) throws SQLException {
if (url == null) {
- attribs.add(url);
- return;
+ attribs.add(null);
+ } else {
+ attribs.add(new SerialDatalink(url));
}
- attribs.add(new SerialDatalink(url));
-
}
--- a/jdk/src/share/classes/javax/sql/rowset/serial/SerialStruct.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/javax/sql/rowset/serial/SerialStruct.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, 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
@@ -29,6 +29,7 @@
import javax.sql.*;
import java.io.*;
import java.math.*;
+import java.util.Arrays;
import java.util.Map;
import java.util.Vector;
@@ -174,7 +175,8 @@
* @throws SerialException if an error occurs
*/
public Object[] getAttributes() throws SerialException {
- return attribs;
+ Object[] val = this.attribs;
+ return (val == null) ? null : Arrays.copyOf(val, val.length);
}
/**
@@ -197,7 +199,8 @@
public Object[] getAttributes(Map<String,Class<?>> map)
throws SerialException
{
- return attribs;
+ Object[] val = this.attribs;
+ return (val == null) ? null : Arrays.copyOf(val, val.length);
}
--- a/jdk/src/share/classes/sun/security/ssl/EngineArgs.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/sun/security/ssl/EngineArgs.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2012, 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
@@ -25,7 +25,6 @@
package sun.security.ssl;
-import javax.net.ssl.*;
import java.nio.*;
/*
@@ -157,6 +156,7 @@
int amount = Math.min(appData[i].remaining(), spaceLeft);
appData[i].limit(appData[i].position() + amount);
netData.put(appData[i]);
+ appRemaining -= amount;
spaceLeft -= amount;
}
}
@@ -209,10 +209,16 @@
/*
* In the case of Exception, we want to reset the positions
* to appear as though no data has been consumed or produced.
+ *
+ * Currently, this method is only called as we are preparing to
+ * fail out, and thus we don't need to actually recalculate
+ * appRemaining. If that assumption changes, that variable should
+ * be updated here.
*/
void resetPos() {
netData.position(netPos);
for (int i = offset; i < offset + len; i++) {
+ // See comment above about recalculating appRemaining.
appData[i].position(appPoss[i]);
}
}
--- a/jdk/src/share/classes/sun/security/ssl/SSLEngineImpl.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/share/classes/sun/security/ssl/SSLEngineImpl.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, 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
@@ -1165,7 +1165,7 @@
ea.resetPos();
fatal(Alerts.alert_internal_error,
- "problem unwrapping net record", e);
+ "problem wrapping app data", e);
return null; // make compiler happy
} finally {
/*
--- a/jdk/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java Tue Jan 31 19:08:36 2012 -0800
@@ -37,8 +37,12 @@
* Linux implementation of HotSpotVirtualMachine
*/
public class LinuxVirtualMachine extends HotSpotVirtualMachine {
- // temp directory for socket file
- private static final String tmpdir = System.getProperty("java.io.tmpdir");
+ // "/tmp" is used as a global well-known location for the files
+ // .java_pid<pid>. and .attach_pid<pid>. It is important that this
+ // location is the same for all processes, otherwise the tools
+ // will not be able to find all Hotspot processes.
+ // Any changes to this needs to be synchronized with HotSpot.
+ private static final String tmpdir = "/tmp";
// Indicates if this machine uses the old LinuxThreads
static boolean isLinuxThreads;
@@ -261,20 +265,12 @@
}
// Return the socket file for the given process.
- // Checks working directory of process for .java_pid<pid>. If not
- // found it looks in temp directory.
private String findSocketFile(int pid) {
- // First check for a .java_pid<pid> file in the working directory
- // of the target process
- String fn = ".java_pid" + pid;
- String path = "/proc/" + pid + "/cwd/" + fn;
- File f = new File(path);
+ File f = new File(tmpdir, ".java_pid" + pid);
if (!f.exists()) {
- // Not found, so try temp directory
- f = new File(tmpdir, fn);
- path = f.exists() ? f.getPath() : null;
+ return null;
}
- return path;
+ return f.getPath();
}
// On Solaris/Linux a simple handshake is used to start the attach mechanism
--- a/jdk/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java Tue Jan 31 19:08:36 2012 -0800
@@ -38,11 +38,12 @@
* Solaris implementation of HotSpotVirtualMachine.
*/
public class SolarisVirtualMachine extends HotSpotVirtualMachine {
- // Use /tmp instead of /var/tmp on Solaris as /tmp is the default used by
- // HotSpot when the property is not set on the command line.
- private static final String tmpdir1 = System.getProperty("java.io.tmpdir");
- private static final String tmpdir =
- (tmpdir1.equals("/var/tmp") || tmpdir1.equals("/var/tmp/")) ? "/tmp" : tmpdir1;
+ // "/tmp" is used as a global well-known location for the files
+ // .java_pid<pid>. and .attach_pid<pid>. It is important that this
+ // location is the same for all processes, otherwise the tools
+ // will not be able to find all Hotspot processes.
+ // Any changes to this needs to be synchronized with HotSpot.
+ private static final String tmpdir = "/tmp";
// door descriptor;
private int fd = -1;
@@ -191,19 +192,10 @@
}
}
- // The door is attached to .java_pid<pid> in the target VM's working
- // directory or temporary directory.
+ // The door is attached to .java_pid<pid> in the temporary directory.
private int openDoor(int pid) throws IOException {
- // First check for a .java_pid<pid> file in the working directory
- // of the target process
- String fn = ".java_pid" + pid;
- String path = "/proc/" + pid + "/cwd/" + fn;
- try {
- fd = open(path);
- } catch (FileNotFoundException fnf) {
- path = tmpdir + "/" + fn;
- fd = open(path);
- }
+ String path = tmpdir + "/.java_pid" + pid;;
+ fd = open(path);
// Check that the file owner/permission to avoid attaching to
// bogus process
--- a/jdk/src/solaris/native/java/lang/UNIXProcess_md.c Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/src/solaris/native/java/lang/UNIXProcess_md.c Tue Jan 31 19:08:36 2012 -0800
@@ -40,7 +40,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <ctype.h>
-#include <wait.h>
+#include <sys/wait.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
--- a/jdk/test/Makefile Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/Makefile Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
#
-# Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1995, 2012, 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
@@ -556,7 +556,7 @@
JDK_ALL_TARGETS += jdk_security3
jdk_security3: $(call TestDirs, com/sun/security lib/security javax/security \
sun/security com/sun/org/apache/xml/internal/security \
- com/oracle/secrity/ucrypto)
+ com/oracle/security/ucrypto)
$(call SharedLibraryPermissions,sun/security)
$(call RunAgentvmBatch)
--- a/jdk/test/ProblemList.txt Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/ProblemList.txt Tue Jan 31 19:08:36 2012 -0800
@@ -476,6 +476,9 @@
java/rmi/server/RMISocketFactory/useSocketFactory/registry/UseCustomSocketFactory.java generic-all
java/rmi/server/UnicastRemoteObject/unexportObject/UnexportLeak.java generic-all
+# 7132247
+java/rmi/registry/readTest/readTest.sh windows-all
+
############################################################################
# jdk_security
@@ -575,13 +578,13 @@
# Filed 6979016
sun/tools/jconsole/ResourceCheckTest.sh generic-all
+# 7132203
+sun/jvmstat/monitor/MonitoredVm/CR6672135.java generic-all
+
############################################################################
# jdk_util
-# Filed 7027061
-java/util/Locale/Bug6989440.java windows-all
-
# Filed 6933803
java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java generic-all
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/Integer/Unsigned.java Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,396 @@
+/*
+ * Copyright (c) 2009, 2012, 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4504839 4215269 6322074
+ * @summary Basic tests for unsigned operations.
+ * @author Joseph D. Darcy
+ */
+public class Unsigned {
+ public static void main(String... args) {
+ int errors = 0;
+
+ errors += testRoundtrip();
+ errors += testByteToUnsignedInt();
+ errors += testShortToUnsignedInt();
+ errors += testUnsignedCompare();
+ errors += testToUnsignedLong();
+ errors += testToStringUnsigned();
+ errors += testParseUnsignedInt();
+ errors += testDivideAndRemainder();
+
+ if (errors > 0) {
+ throw new RuntimeException(errors + " errors found in unsigned operations.");
+ }
+ }
+
+ private static int testRoundtrip() {
+ int errors = 0;
+
+ int[] data = {-1, 0, 1};
+
+ for(int datum : data) {
+ if (Integer.parseUnsignedInt(Integer.toBinaryString(datum), 2) != datum) {
+ errors++;
+ System.err.println("Bad binary roundtrip conversion of " + datum);
+ }
+
+ if (Integer.parseUnsignedInt(Integer.toOctalString(datum), 8) != datum) {
+ errors++;
+ System.err.println("Bad octal roundtrip conversion of " + datum);
+ }
+
+ if (Integer.parseUnsignedInt(Integer.toHexString(datum), 16) != datum) {
+ errors++;
+ System.err.println("Bad hex roundtrip conversion of " + datum);
+ }
+ }
+ return errors;
+ }
+
+ private static int testByteToUnsignedInt() {
+ int errors = 0;
+
+ for(int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
+ byte datum = (byte) i;
+ int ui = Byte.toUnsignedInt(datum);
+
+ if ( (ui & (~0xff)) != 0 ||
+ ((byte)ui != datum )) {
+ errors++;
+ System.err.printf("Bad conversion of byte %d to unsigned int %d%n",
+ datum, ui);
+ }
+ }
+ return errors;
+ }
+
+ private static int testShortToUnsignedInt() {
+ int errors = 0;
+
+ for(int i = Short.MIN_VALUE; i <= Short.MAX_VALUE; i++) {
+ short datum = (short) i;
+ int ui = Short.toUnsignedInt(datum);
+
+ if ( (ui & (~0xffff)) != 0 ||
+ ((short)ui != datum )) {
+ errors++;
+ System.err.printf("Bad conversion of short %d to unsigned int %d%n",
+ datum, ui);
+ }
+ }
+ return errors;
+ }
+
+ private static int testUnsignedCompare() {
+ int errors = 0;
+
+ int[] data = {
+ 0,
+ 1,
+ 2,
+ 3,
+ 0x8000_0000,
+ 0x8000_0001,
+ 0x8000_0002,
+ 0x8000_0003,
+ 0xFFFF_FFFE,
+ 0xFFFF_FFFF,
+ };
+
+ for(int i : data) {
+ for(int j : data) {
+ int libraryResult = Integer.compareUnsigned(i, j);
+ int libraryResultRev = Integer.compareUnsigned(j, i);
+ int localResult = compUnsigned(i, j);
+
+ if (i == j) {
+ if (libraryResult != 0) {
+ errors++;
+ System.err.printf("Value 0x%x did not compare as " +
+ "an unsigned value equal to itself; got %d%n",
+ i, libraryResult);
+ }
+ }
+
+ if (Integer.signum(libraryResult) != Integer.signum(localResult)) {
+ errors++;
+ System.err.printf("Unsigned compare of 0x%x to 0x%x%n:" +
+ "\texpected sign of %d, got %d%n",
+ i, j, localResult, libraryResult);
+ }
+
+ if (Integer.signum(libraryResult) !=
+ -Integer.signum(libraryResultRev)) {
+ errors++;
+ System.err.printf("signum(compareUnsigned(x, y)) != -signum(compareUnsigned(y,x))" +
+ " for \t0x%x and 0x%x, computed %d and %d%n",
+ i, j, libraryResult, libraryResultRev);
+ }
+ }
+ }
+
+ return errors;
+ }
+
+ /**
+ * Straightforward compare unsigned algorithm.
+ */
+ private static int compUnsigned(int x, int y) {
+ int sign_x = x & Integer.MIN_VALUE;
+ int sign_y = y & Integer.MIN_VALUE;
+
+ int mant_x = x & (~Integer.MIN_VALUE);
+ int mant_y = y & (~Integer.MIN_VALUE);
+
+ if (sign_x == sign_y)
+ return Integer.compare(mant_x, mant_y);
+ else {
+ if (sign_x == 0)
+ return -1; // sign x is 0, sign y is 1 => (x < y)
+ else
+ return 1; // sign x is 1, sign y is 0 => (x > y)
+ }
+ }
+
+ private static int testToUnsignedLong() {
+ int errors = 0;
+
+ int[] data = {
+ 0,
+ 1,
+ 2,
+ 3,
+ 0x1234_5678,
+ 0x8000_0000,
+ 0x8000_0001,
+ 0x8000_0002,
+ 0x8000_0003,
+ 0x8765_4321,
+ 0xFFFF_FFFE,
+ 0xFFFF_FFFF,
+ };
+
+ for(int datum : data) {
+ long result = Integer.toUnsignedLong(datum);
+
+ // High-order bits should be zero
+ if ((result & 0xffff_ffff_0000_0000L) != 0L) {
+ errors++;
+ System.err.printf("High bits set converting 0x%x to 0x%x%n",
+ datum, result);
+ }
+
+ // Lower-order bits should be equal to datum.
+ int lowOrder = (int)(result & 0x0000_0000_ffff_ffffL);
+ if (lowOrder != datum ) {
+ errors++;
+ System.err.printf("Low bits not preserved converting 0x%x to 0x%x%n",
+ datum, result);
+ }
+ }
+ return errors;
+ }
+
+ private static int testToStringUnsigned() {
+ int errors = 0;
+
+ int[] data = {
+ 0,
+ 1,
+ 2,
+ 3,
+ 99999,
+ 100000,
+ 999999,
+ 100000,
+ 999999999,
+ 1000000000,
+ 0x1234_5678,
+ 0x8000_0000,
+ 0x8000_0001,
+ 0x8000_0002,
+ 0x8000_0003,
+ 0x8765_4321,
+ 0xFFFF_FFFE,
+ 0xFFFF_FFFF,
+ };
+
+ for(int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) {
+ for(int datum : data) {
+ String result1 = Integer.toUnsignedString(datum, radix);
+ String result2 = Long.toString(Integer.toUnsignedLong(datum), radix);
+
+ if (!result1.equals(result2)) {
+ errors++;
+ System.err.printf("Unexpected string difference converting 0x%x:" +
+ "\t%s %s%n",
+ datum, result1, result2);
+ }
+
+ if (radix == 10) {
+ String result3 = Integer.toUnsignedString(datum);
+ if (!result2.equals(result3)) {
+ errors++;
+ System.err.printf("Unexpected string difference converting 0x%x:" +
+ "\t%s %s%n",
+ datum, result3, result2);
+ }
+ }
+
+ int parseResult = Integer.parseUnsignedInt(result1, radix);
+
+ if (parseResult != datum) {
+ errors++;
+ System.err.printf("Bad roundtrip conversion of %d in base %d" +
+ "\tconverting back ''%s'' resulted in %d%n",
+ datum, radix, result1, parseResult);
+ }
+ }
+ }
+
+ return errors;
+ }
+
+ private static final long MAX_UNSIGNED_INT = Integer.toUnsignedLong(0xffff_ffff);
+
+ private static int testParseUnsignedInt() {
+ int errors = 0;
+
+ // Values include those between signed Integer.MAX_VALUE and
+ // unsignted int MAX_VALUE.
+ long[] inRange = {
+ 0L,
+ 1L,
+ 10L,
+ 2147483646L, // MAX_VALUE - 1
+ 2147483647L, // MAX_VALUE
+ 2147483648L, // MAX_VALUE + 1
+
+ MAX_UNSIGNED_INT - 1L,
+ MAX_UNSIGNED_INT,
+ };
+
+ for(long value : inRange) {
+ for(int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) {
+ String longString = Long.toString(value, radix);
+ int intResult = Integer.parseUnsignedInt(longString, radix);
+
+ if (Integer.toUnsignedLong(intResult) != value) {
+ errors++;
+ System.err.printf("Bad roundtrip conversion of %d in base %d" +
+ "\tconverting back ''%s'' resulted in %d%n",
+ value, radix, longString, intResult);
+ }
+ }
+ }
+
+ String[] outOfRange = {
+ null,
+ "",
+ "-1",
+ Long.toString(MAX_UNSIGNED_INT + 1L),
+ Long.toString(Long.MAX_VALUE)
+ };
+
+ for(String s : outOfRange) {
+ try {
+ int result = Integer.parseUnsignedInt(s);
+ errors++; // Should not reach here
+ System.err.printf("Unexpected got %d from an unsigned conversion of %s",
+ result, s);
+ } catch(NumberFormatException nfe) {
+ ; // Correct result
+ }
+ }
+
+ return errors;
+ }
+
+ private static int testDivideAndRemainder() {
+ int errors = 0;
+
+ long[] inRange = {
+ 0L,
+ 1L,
+ 2L,
+ 2147483646L, // MAX_VALUE - 1
+ 2147483647L, // MAX_VALUE
+ 2147483648L, // MAX_VALUE + 1
+
+ MAX_UNSIGNED_INT - 1L,
+ MAX_UNSIGNED_INT,
+ };
+
+ for(long dividend : inRange) {
+ for(long divisor : inRange) {
+ int quotient;
+ long longQuotient;
+
+ int remainder;
+ long longRemainder;
+
+ if (divisor == 0) {
+ try {
+ quotient = Integer.divideUnsigned((int) dividend, (int) divisor);
+ errors++;
+ } catch(ArithmeticException ea) {
+ ; // Expected
+ }
+
+ try {
+ remainder = Integer.remainderUnsigned((int) dividend, (int) divisor);
+ errors++;
+ } catch(ArithmeticException ea) {
+ ; // Expected
+ }
+ } else {
+ quotient = Integer.divideUnsigned((int) dividend, (int) divisor);
+ longQuotient = dividend / divisor;
+
+ if (quotient != (int)longQuotient) {
+ errors++;
+ System.err.printf("Unexpected unsigned divide result %s on %s/%s%n",
+ Integer.toUnsignedString(quotient),
+ Integer.toUnsignedString((int) dividend),
+ Integer.toUnsignedString((int) divisor));
+ }
+
+ remainder = Integer.remainderUnsigned((int) dividend, (int) divisor);
+ longRemainder = dividend % divisor;
+
+ if (remainder != (int)longRemainder) {
+ errors++;
+ System.err.printf("Unexpected unsigned remainder result %s on %s%%%s%n",
+ Integer.toUnsignedString(remainder),
+ Integer.toUnsignedString((int) dividend),
+ Integer.toUnsignedString((int) divisor));
+ }
+ }
+ }
+ }
+
+ return errors;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/Long/Unsigned.java Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,388 @@
+/*
+ * Copyright (c) 2009, 2012, 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4504839 4215269 6322074
+ * @summary Basic tests for unsigned operations
+ * @author Joseph D. Darcy
+ */
+
+import java.math.*;
+
+public class Unsigned {
+ public static void main(String... args) {
+ int errors = 0;
+
+ errors += testRoundtrip();
+ errors += testByteToUnsignedLong();
+ errors += testShortToUnsignedLong();
+ errors += testUnsignedCompare();
+ errors += testToStringUnsigned();
+ errors += testParseUnsignedLong();
+ errors += testDivideAndRemainder();
+
+ if (errors > 0) {
+ throw new RuntimeException(errors + " errors found in unsigned operations.");
+ }
+ }
+
+ private static final BigInteger TWO = BigInteger.valueOf(2L);
+
+ private static int testRoundtrip() {
+ int errors = 0;
+
+ long[] data = {-1L, 0L, 1L};
+
+ for(long datum : data) {
+ if (Long.parseUnsignedLong(Long.toBinaryString(datum), 2) != datum) {
+ errors++;
+ System.err.println("Bad binary roundtrip conversion of " + datum);
+ }
+
+ if (Long.parseUnsignedLong(Long.toOctalString(datum), 8) != datum) {
+ errors++;
+ System.err.println("Bad octal roundtrip conversion of " + datum);
+ }
+
+ if (Long.parseUnsignedLong(Long.toHexString(datum), 16) != datum) {
+ errors++;
+ System.err.println("Bad hex roundtrip conversion of " + datum);
+ }
+ }
+ return errors;
+ }
+
+ private static int testByteToUnsignedLong() {
+ int errors = 0;
+
+ for(int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
+ byte datum = (byte) i;
+ long ui = Byte.toUnsignedLong(datum);
+
+ if ( (ui & (~0xffL)) != 0L ||
+ ((byte)ui != datum )) {
+ errors++;
+ System.err.printf("Bad conversion of byte %d to unsigned long %d%n",
+ datum, ui);
+ }
+ }
+ return errors;
+ }
+
+ private static int testShortToUnsignedLong() {
+ int errors = 0;
+
+ for(int i = Short.MIN_VALUE; i <= Short.MAX_VALUE; i++) {
+ short datum = (short) i;
+ long ui = Short.toUnsignedLong(datum);
+
+ if ( (ui & (~0xffffL)) != 0L ||
+ ((short)ui != datum )) {
+ errors++;
+ System.err.printf("Bad conversion of short %d to unsigned long %d%n",
+ datum, ui);
+ }
+ }
+ return errors;
+ }
+ private static int testUnsignedCompare() {
+ int errors = 0;
+
+ long[] data = {
+ 0L,
+ 1L,
+ 2L,
+ 3L,
+ 0x00000000_80000000L,
+ 0x00000000_FFFFFFFFL,
+ 0x00000001_00000000L,
+ 0x80000000_00000000L,
+ 0x80000000_00000001L,
+ 0x80000000_00000002L,
+ 0x80000000_00000003L,
+ 0x80000000_80000000L,
+ 0xFFFFFFFF_FFFFFFFEL,
+ 0xFFFFFFFF_FFFFFFFFL,
+ };
+
+ for(long i : data) {
+ for(long j : data) {
+ long libraryResult = Long.compareUnsigned(i, j);
+ long libraryResultRev = Long.compareUnsigned(j, i);
+ long localResult = compUnsigned(i, j);
+
+ if (i == j) {
+ if (libraryResult != 0) {
+ errors++;
+ System.err.printf("Value 0x%x did not compare as " +
+ "an unsigned equal to itself; got %d%n",
+ i, libraryResult);
+ }
+ }
+
+ if (Long.signum(libraryResult) != Long.signum(localResult)) {
+ errors++;
+ System.err.printf("Unsigned compare of 0x%x to 0x%x%n:" +
+ "\texpected sign of %d, got %d%n",
+ i, j, localResult, libraryResult);
+ }
+
+ if (Long.signum(libraryResult) !=
+ -Long.signum(libraryResultRev)) {
+ errors++;
+ System.err.printf("signum(compareUnsigned(x, y)) != -signum(compareUnsigned(y,x))" +
+ " for \t0x%x and 0x%x, computed %d and %d%n",
+ i, j, libraryResult, libraryResultRev);
+ }
+ }
+ }
+
+ return errors;
+ }
+
+ private static int compUnsigned(long x, long y) {
+ BigInteger big_x = toUnsignedBigInt(x);
+ BigInteger big_y = toUnsignedBigInt(y);
+
+ return big_x.compareTo(big_y);
+ }
+
+ private static BigInteger toUnsignedBigInt(long x) {
+ if (x >= 0)
+ return BigInteger.valueOf(x);
+ else {
+ int upper = (int)(((long)x) >> 32);
+ int lower = (int) x;
+
+ BigInteger bi = // (upper << 32) + lower
+ (BigInteger.valueOf(Integer.toUnsignedLong(upper))).shiftLeft(32).
+ add(BigInteger.valueOf(Integer.toUnsignedLong(lower)));
+
+ // System.out.printf("%n\t%d%n\t%s%n", x, bi.toString());
+ return bi;
+ }
+ }
+
+ private static int testToStringUnsigned() {
+ int errors = 0;
+
+ long[] data = {
+ 0L,
+ 1L,
+ 2L,
+ 3L,
+ 99999L,
+ 100000L,
+ 999999L,
+ 100000L,
+ 999999999L,
+ 1000000000L,
+ 0x1234_5678L,
+ 0x8000_0000L,
+ 0x8000_0001L,
+ 0x8000_0002L,
+ 0x8000_0003L,
+ 0x8765_4321L,
+ 0xFFFF_FFFEL,
+ 0xFFFF_FFFFL,
+
+ // Long-range values
+ 999_999_999_999L,
+ 1_000_000_000_000L,
+
+ 999_999_999_999_999_999L,
+ 1_000_000_000_000_000_000L,
+
+ 0xFFFF_FFFF_FFFF_FFFEL,
+ 0xFFFF_FFFF_FFFF_FFFFL,
+ };
+
+ for(int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) {
+ for(long datum : data) {
+ String result1 = Long.toUnsignedString(datum, radix);
+ String result2 = toUnsignedBigInt(datum).toString(radix);
+
+ if (!result1.equals(result2)) {
+ errors++;
+ System.err.printf("Unexpected string difference converting 0x%x:" +
+ "\t%s %s%n",
+ datum, result1, result2);
+ }
+
+ if (radix == 10) {
+ String result3 = Long.toUnsignedString(datum);
+ if (!result2.equals(result3)) {
+ errors++;
+ System.err.printf("Unexpected string difference converting 0x%x:" +
+ "\t%s %s%n",
+ datum, result3, result2);
+ }
+ }
+
+ long parseResult = Long.parseUnsignedLong(result1, radix);
+
+ if (parseResult != datum) {
+ errors++;
+ System.err.printf("Bad roundtrip conversion of %d in base %d" +
+ "\tconverting back ''%s'' resulted in %d%n",
+ datum, radix, result1, parseResult);
+ }
+ }
+ }
+
+ return errors;
+ }
+
+ private static int testParseUnsignedLong() {
+ int errors = 0;
+ long maxUnsignedInt = Integer.toUnsignedLong(0xffff_ffff);
+
+ // Values include those between signed Long.MAX_VALUE and
+ // unsignted Long MAX_VALUE.
+ BigInteger[] inRange = {
+ BigInteger.valueOf(0L),
+ BigInteger.valueOf(1L),
+ BigInteger.valueOf(10L),
+ BigInteger.valueOf(2147483646L), // Integer.MAX_VALUE - 1
+ BigInteger.valueOf(2147483647L), // Integer.MAX_VALUE
+ BigInteger.valueOf(2147483648L), // Integer.MAX_VALUE + 1
+
+ BigInteger.valueOf(maxUnsignedInt - 1L),
+ BigInteger.valueOf(maxUnsignedInt),
+
+ BigInteger.valueOf(Long.MAX_VALUE - 1L),
+ BigInteger.valueOf(Long.MAX_VALUE),
+ BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE),
+
+ TWO.pow(64).subtract(BigInteger.ONE)
+ };
+
+ for(BigInteger value : inRange) {
+ for(int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) {
+ String bigString = value.toString(radix);
+ long longResult = Long.parseUnsignedLong(bigString, radix);
+
+ if (!toUnsignedBigInt(longResult).equals(value)) {
+ errors++;
+ System.err.printf("Bad roundtrip conversion of %d in base %d" +
+ "\tconverting back ''%s'' resulted in %d%n",
+ value, radix, bigString, longResult);
+ }
+ }
+ }
+
+ String[] outOfRange = {
+ null,
+ "",
+ "-1",
+ TWO.pow(64).toString(),
+ };
+
+ for(String s : outOfRange) {
+ try {
+ long result = Long.parseUnsignedLong(s);
+ errors++; // Should not reach here
+ System.err.printf("Unexpected got %d from an unsigned conversion of %s",
+ result, s);
+ } catch(NumberFormatException nfe) {
+ ; // Correct result
+ }
+ }
+
+ return errors;
+ }
+
+ private static int testDivideAndRemainder() {
+ int errors = 0;
+ long MAX_UNSIGNED_INT = Integer.toUnsignedLong(0xffff_ffff);
+
+ BigInteger[] inRange = {
+ BigInteger.valueOf(0L),
+ BigInteger.valueOf(1L),
+ BigInteger.valueOf(10L),
+ BigInteger.valueOf(2147483646L), // Integer.MAX_VALUE - 1
+ BigInteger.valueOf(2147483647L), // Integer.MAX_VALUE
+ BigInteger.valueOf(2147483648L), // Integer.MAX_VALUE + 1
+
+ BigInteger.valueOf(MAX_UNSIGNED_INT - 1L),
+ BigInteger.valueOf(MAX_UNSIGNED_INT),
+
+ BigInteger.valueOf(Long.MAX_VALUE - 1L),
+ BigInteger.valueOf(Long.MAX_VALUE),
+ BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE),
+
+ TWO.pow(64).subtract(BigInteger.ONE)
+ };
+
+ for(BigInteger dividend : inRange) {
+ for(BigInteger divisor : inRange) {
+ long quotient;
+ BigInteger longQuotient;
+
+ long remainder;
+ BigInteger longRemainder;
+
+ if (divisor.equals(BigInteger.ZERO)) {
+ try {
+ quotient = Long.divideUnsigned(dividend.longValue(), divisor.longValue());
+ errors++;
+ } catch(ArithmeticException ea) {
+ ; // Expected
+ }
+
+ try {
+ remainder = Long.remainderUnsigned(dividend.longValue(), divisor.longValue());
+ errors++;
+ } catch(ArithmeticException ea) {
+ ; // Expected
+ }
+ } else {
+ quotient = Long.divideUnsigned(dividend.longValue(), divisor.longValue());
+ longQuotient = dividend.divide(divisor);
+
+ if (quotient != longQuotient.longValue()) {
+ errors++;
+ System.err.printf("Unexpected unsigned divide result %s on %s/%s%n",
+ Long.toUnsignedString(quotient),
+ Long.toUnsignedString(dividend.longValue()),
+ Long.toUnsignedString(divisor.longValue()));
+ }
+
+ remainder = Long.remainderUnsigned(dividend.longValue(), divisor.longValue());
+ longRemainder = dividend.remainder(divisor);
+
+ if (remainder != longRemainder.longValue()) {
+ errors++;
+ System.err.printf("Unexpected unsigned remainder result %s on %s%%%s%n",
+ Long.toUnsignedString(remainder),
+ Long.toUnsignedString(dividend.longValue()),
+ Long.toUnsignedString(divisor.longValue()));
+ }
+ }
+ }
+ }
+
+ return errors;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/text/Format/DateFormat/Bug7130335.java Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2012, 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 7130335
+ * @summary Make sure that round-trip conversion (format/parse) works
+ * with old timestamps in Europe/Moscow.
+ */
+import java.text.*;
+import java.util.*;
+
+public class Bug7130335 {
+ private static final TimeZone MOSCOW = TimeZone.getTimeZone("Europe/Moscow");
+
+ public static void main(String[] args) throws Exception {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z", Locale.US);
+ sdf.setTimeZone(MOSCOW);
+ Calendar cal = new GregorianCalendar(MOSCOW);
+ cal.clear();
+ // Try both +03:00 and +02:00
+ cal.set(1922, Calendar.SEPTEMBER, 30);
+ test(sdf, cal);
+ cal.add(Calendar.DAY_OF_YEAR, 1);
+ test(sdf, cal);
+ cal.set(1991, Calendar.MARCH, 31);
+ // in daylight saving time
+ test(sdf, cal);
+ cal.add(Calendar.DAY_OF_YEAR, 1);
+ test(sdf, cal);
+ // Try the current timestamp
+ cal.setTimeInMillis(System.currentTimeMillis());
+ test(sdf, cal);
+ }
+
+ private static void test(SimpleDateFormat sdf, Calendar cal) throws Exception {
+ Date d = cal.getTime();
+ String f = sdf.format(d);
+ System.out.println(f);
+ Date pd = sdf.parse(f);
+ String p = sdf.format(pd);
+ if (!d.equals(pd) || !f.equals(p)) {
+ throw new RuntimeException("format: " + f + ", parse: " + p);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/util/Calendar/Bug7017458.java Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2012, 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 7017458
+ * @summary Test of multithreaded serialization/deserialization of Calendar.
+ */
+
+import java.io.*;
+import java.util.Calendar;
+
+public class Bug7017458 {
+
+ static volatile boolean err = false;
+
+ public static void main(String[] args) {
+ try {
+ new Bug7017458().perform();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ err = true;
+ }
+
+ if (err) {
+ throw new RuntimeException("Multithreaded serialization/deserialization test failed.");
+ } else {
+ System.out.println("Multithreaded serialization/deserialization test passed.");
+ }
+ }
+
+ public void perform() throws Exception {
+ int nbThreads = 8;
+ Calendar cal = Calendar.getInstance();
+ SerializationThread[] threads = new SerializationThread[nbThreads];
+ for (int i = 0; i < nbThreads; i++) {
+ threads[i] = new SerializationThread(cal);
+ }
+ for (int i = 0; i < nbThreads; i++) {
+ threads[i].start();
+ }
+ for (int i = 0; i < nbThreads; i++) {
+ threads[i].join();
+ }
+
+ DeserializationThread[] threads2 = new DeserializationThread[nbThreads];
+ for (int i = 0; i < nbThreads; i++) {
+ threads2[i] = new DeserializationThread(threads[i].data);
+ }
+ for (int i = 0; i < nbThreads; i++) {
+ threads2[i].start();
+ }
+ for (int i = 0; i < nbThreads; i++) {
+ threads2[i].join();
+ }
+ }
+
+ public class SerializationThread extends Thread {
+ private Calendar cal;
+ public byte[] data;
+
+ public SerializationThread(Calendar cal) {
+ this.cal = cal;
+ }
+
+ public void run() {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(cal);
+ oos.flush();
+ oos.close();
+ data = baos.toByteArray();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ err = true;
+ }
+ }
+ }
+
+ public class DeserializationThread extends Thread {
+ public Calendar cal;
+ public byte[] data;
+
+ public DeserializationThread(byte[] data) {
+ this.data = data;
+ }
+
+ public void run() {
+ try {
+ ByteArrayInputStream bais = new ByteArrayInputStream(data);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ cal = (Calendar) ois.readObject();
+ ois.close();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ err = true;
+ }
+ }
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/util/EnumMap/UniqueNullValue.java Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2012, 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.
+ */
+
+/*
+ * Portions Copyright (c) 2012, IBM Corporation
+ */
+
+/*
+ * @test
+ * @bug 7123229
+ * @summary (coll) EnumMap.containsValue(null) returns true
+ * @author ngmr
+ */
+
+import java.util.EnumMap;
+import java.util.Map;
+
+public class UniqueNullValue {
+ static enum TestEnum { e00, e01 }
+
+ public static void main(String[] args) {
+ Map<TestEnum, Integer> map = new EnumMap<>(TestEnum.class);
+
+ map.put(TestEnum.e00, 0);
+ if (false == map.containsValue(0)) {
+ throw new RuntimeException("EnumMap unexpectedly missing 0 value");
+ }
+ if (map.containsValue(null)) {
+ throw new RuntimeException("EnumMap unexpectedly holds null value");
+ }
+
+ map.put(TestEnum.e00, null);
+ if (map.containsValue(0)) {
+ throw new RuntimeException("EnumMap unexpectedly holds 0 value");
+ }
+ if (false == map.containsValue(null)) {
+ throw new RuntimeException("EnumMap unexpectedly missing null value");
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/util/concurrent/FutureTask/DoneTimedGetLoops.java Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2012 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.
+ */
+
+/*
+ * Written by Martin Buchholz with assistance from members of JCP JSR-166
+ * Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/*
+ * @test
+ * @run main DoneTimedGetLoops 300
+ * @summary isDone returning true guarantees that subsequent timed get
+ * will never throw TimeoutException.
+ */
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+@SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
+public class DoneTimedGetLoops {
+ final long testDurationMillisDefault = 10L * 1000L;
+ final long testDurationMillis;
+
+ static class PublicFutureTask extends FutureTask<Boolean> {
+ final static Runnable noop = new Runnable() { public void run() {} };
+ PublicFutureTask() { super(noop, null); }
+ public void set(Boolean v) { super.set(v); }
+ public void setException(Throwable t) { super.setException(t); }
+ }
+
+ DoneTimedGetLoops(String[] args) {
+ testDurationMillis = (args.length > 0) ?
+ Long.valueOf(args[0]) : testDurationMillisDefault;
+ }
+
+ void test(String[] args) throws Throwable {
+ final long testDurationNanos = testDurationMillis * 1000L * 1000L;
+ final long quittingTimeNanos = System.nanoTime() + testDurationNanos;
+ final long timeoutMillis = 10L * 1000L;
+
+ final AtomicReference<PublicFutureTask> normalRef
+ = new AtomicReference<PublicFutureTask>();
+ final AtomicReference<PublicFutureTask> abnormalRef
+ = new AtomicReference<PublicFutureTask>();
+
+ final Throwable throwable = new Throwable();
+
+ abstract class CheckedThread extends Thread {
+ CheckedThread(String name) {
+ super(name);
+ setDaemon(true);
+ start();
+ }
+ /** Polls for quitting time. */
+ protected boolean quittingTime() {
+ return System.nanoTime() - quittingTimeNanos > 0;
+ }
+ /** Polls occasionally for quitting time. */
+ protected boolean quittingTime(long i) {
+ return (i % 1024) == 0 && quittingTime();
+ }
+ abstract protected void realRun() throws Exception;
+ public void run() {
+ try { realRun(); } catch (Throwable t) { unexpected(t); }
+ }
+ }
+
+ Thread setter = new CheckedThread("setter") {
+ protected void realRun() {
+ while (! quittingTime()) {
+ PublicFutureTask future = new PublicFutureTask();
+ normalRef.set(future);
+ future.set(Boolean.TRUE);
+ }}};
+
+ Thread setterException = new CheckedThread("setterException") {
+ protected void realRun() {
+ while (! quittingTime()) {
+ PublicFutureTask future = new PublicFutureTask();
+ abnormalRef.set(future);
+ future.setException(throwable);
+ }}};
+
+ Thread doneTimedGetNormal = new CheckedThread("doneTimedGetNormal") {
+ protected void realRun() throws Exception {
+ while (! quittingTime()) {
+ PublicFutureTask future = normalRef.get();
+ if (future != null) {
+ while (!future.isDone())
+ ;
+ check(future.get(0L, TimeUnit.HOURS) == Boolean.TRUE);
+ }}}};
+
+ Thread doneTimedGetAbnormal = new CheckedThread("doneTimedGetAbnormal") {
+ protected void realRun() throws Exception {
+ while (! quittingTime()) {
+ PublicFutureTask future = abnormalRef.get();
+ if (future != null) {
+ while (!future.isDone())
+ ;
+ try { future.get(0L, TimeUnit.HOURS); fail(); }
+ catch (ExecutionException t) {
+ check(t.getCause() == throwable);
+ }
+ }}}};
+
+ for (Thread thread : new Thread[] {
+ setter,
+ setterException,
+ doneTimedGetNormal,
+ doneTimedGetAbnormal }) {
+ thread.join(timeoutMillis + testDurationMillis);
+ if (thread.isAlive()) {
+ System.err.printf("Hung thread: %s%n", thread.getName());
+ failed++;
+ for (StackTraceElement e : thread.getStackTrace())
+ System.err.println(e);
+ // Kludge alert
+ thread.stop();
+ thread.join(timeoutMillis);
+ }
+ }
+ }
+
+ //--------------------- Infrastructure ---------------------------
+ volatile int passed = 0, failed = 0;
+ void pass() {passed++;}
+ void fail() {failed++; Thread.dumpStack();}
+ void fail(String msg) {System.err.println(msg); fail();}
+ void unexpected(Throwable t) {failed++; t.printStackTrace();}
+ void check(boolean cond) {if (cond) pass(); else fail();}
+ void equal(Object x, Object y) {
+ if (x == null ? y == null : x.equals(y)) pass();
+ else fail(x + " not equal to " + y);}
+ public static void main(String[] args) throws Throwable {
+ new DoneTimedGetLoops(args).instanceMain(args);}
+ public void instanceMain(String[] args) throws Throwable {
+ try {test(args);} catch (Throwable t) {unexpected(t);}
+ System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
+ if (failed > 0) throw new AssertionError("Some tests failed");}
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/util/concurrent/FutureTask/ExplicitSet.java Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2012, 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 7132378
+ * @summary Race in FutureTask if used with explicit set ( not Runnable )
+ * @author Chris Hegarty
+ */
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.FutureTask;
+
+public class ExplicitSet {
+
+ static void realMain(String[] args) throws Throwable {
+ for (int i = 1; i <= 10000; i++) {
+ //System.out.print(".");
+ test();
+ }
+ }
+
+ static void test() throws Throwable {
+ final SettableTask task = new SettableTask();
+
+ Thread thread = new Thread() { public void run() {
+ try {
+ check(task.get() != null);
+ } catch (Exception e) { unexpected(e); }
+ }};
+ thread.start();
+
+ task.set(Boolean.TRUE);
+ thread.join(5000);
+ }
+
+ static class SettableTask extends FutureTask<Boolean> {
+ SettableTask() {
+ super(new Callable<Boolean>() {
+ public Boolean call() {
+ fail ("The task should never be run!");
+ return null;
+ };
+ });
+ }
+
+ @Override
+ public void set(Boolean b) {
+ super.set(b);
+ }
+ }
+
+ //--------------------- Infrastructure ---------------------------
+ static volatile int passed = 0, failed = 0;
+ static void pass() {passed++;}
+ static void fail() {failed++; Thread.dumpStack();}
+ static void fail(String msg) {System.out.println(msg); fail();}
+ static void unexpected(Throwable t) {failed++; t.printStackTrace();}
+ static void check(boolean cond) {if (cond) pass(); else fail();}
+ static void equal(Object x, Object y) {
+ if (x == null ? y == null : x.equals(y)) pass();
+ else fail(x + " not equal to " + y);}
+ public static void main(String[] args) throws Throwable {
+ try {realMain(args);} catch (Throwable t) {unexpected(t);}
+ System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
+ if (failed > 0) throw new AssertionError("Some tests failed");}
+}
--- a/jdk/test/javax/xml/crypto/dsig/KeySelectors.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/javax/xml/crypto/dsig/KeySelectors.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2012, 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
@@ -22,7 +22,9 @@
*/
import java.io.*;
-import java.security.*;
+import java.security.Key;
+import java.security.KeyException;
+import java.security.PublicKey;
import java.security.cert.*;
import java.util.*;
import javax.crypto.SecretKey;
@@ -76,7 +78,7 @@
}
public byte[] getEncoded() {
- return (byte[]) bytes.clone();
+ return bytes.clone();
}
};
}
@@ -196,9 +198,9 @@
* matching public key.
*/
static class CollectionKeySelector extends KeySelector {
- private CertificateFactory certFac;
+ private CertificateFactory cf;
private File certDir;
- private Vector certs;
+ private Vector<X509Certificate> certs;
private static final int MATCH_SUBJECT = 0;
private static final int MATCH_ISSUER = 1;
private static final int MATCH_SERIAL = 2;
@@ -208,24 +210,24 @@
CollectionKeySelector(File dir) {
certDir = dir;
try {
- certFac = CertificateFactory.getInstance("X509");
+ cf = CertificateFactory.getInstance("X509");
} catch (CertificateException ex) {
// not going to happen
}
- certs = new Vector();
+ certs = new Vector<X509Certificate>();
File[] files = new File(certDir, "certs").listFiles();
for (int i = 0; i < files.length; i++) {
- try {
- certs.add(certFac.generateCertificate
- (new FileInputStream(files[i])));
+ try (FileInputStream fis = new FileInputStream(files[i])) {
+ certs.add((X509Certificate)cf.generateCertificate(fis));
} catch (Exception ex) { }
}
}
- Vector match(int matchType, Object value, Vector pool) {
- Vector matchResult = new Vector();
+ Vector<X509Certificate> match(int matchType, Object value,
+ Vector<X509Certificate> pool) {
+ Vector<X509Certificate> matchResult = new Vector<>();
for (int j=0; j < pool.size(); j++) {
- X509Certificate c = (X509Certificate) pool.get(j);
+ X509Certificate c = pool.get(j);
switch (matchType) {
case MATCH_SUBJECT:
try {
@@ -286,19 +288,18 @@
if (xmlStructure instanceof KeyName) {
String name = ((KeyName)xmlStructure).getName();
PublicKey pk = null;
- try {
+ File certFile = new File(new File(certDir, "certs"),
+ name.toLowerCase() + ".crt");
+ try (FileInputStream fis = new FileInputStream(certFile)) {
// Lookup the public key using the key name 'Xxx',
// i.e. the public key is in "certs/xxx.crt".
- File certFile = new File(new File(certDir, "certs"),
- name.toLowerCase()+".crt");
X509Certificate cert = (X509Certificate)
- certFac.generateCertificate
- (new FileInputStream(certFile));
+ cf.generateCertificate(fis);
pk = cert.getPublicKey();
} catch (FileNotFoundException e) {
// assume KeyName contains subject DN and search
// collection of certs for match
- Vector result =
+ Vector<X509Certificate> result =
match(MATCH_SUBJECT, name, certs);
int numOfMatches = (result==null? 0:result.size());
if (numOfMatches != 1) {
@@ -306,7 +307,7 @@
((numOfMatches==0?"No":"More than one") +
" match found");
}
- pk =((X509Certificate)result.get(0)).getPublicKey();
+ pk = result.get(0).getPublicKey();
}
return new SimpleKSResult(pk);
} else if (xmlStructure instanceof RetrievalMethod) {
@@ -316,10 +317,12 @@
String type = rm.getType();
if (type.equals(X509Data.RAW_X509_CERTIFICATE_TYPE)) {
String uri = rm.getURI();
- X509Certificate cert = (X509Certificate)
- certFac.generateCertificate
- (new FileInputStream(new File(certDir, uri)));
- return new SimpleKSResult(cert.getPublicKey());
+ try (FileInputStream fis =
+ new FileInputStream(new File(certDir, uri))) {
+ X509Certificate cert = (X509Certificate)
+ cf.generateCertificate(fis);
+ return new SimpleKSResult(cert.getPublicKey());
+ }
} else {
throw new KeySelectorException
("Unsupported RetrievalMethod type");
@@ -327,7 +330,7 @@
} else if (xmlStructure instanceof X509Data) {
List content = ((X509Data)xmlStructure).getContent();
int size = content.size();
- Vector result = null;
+ Vector<X509Certificate> result = null;
// Lookup the public key using the information
// specified in X509Data element, i.e. searching
// over the collection of certificate files under
@@ -357,8 +360,7 @@
((numOfMatches==0?"No":"More than one") +
" match found");
}
- return new SimpleKSResult(((X509Certificate)
- result.get(0)).getPublicKey());
+ return new SimpleKSResult(result.get(0).getPublicKey());
}
} catch (Exception ex) {
throw new KeySelectorException(ex);
--- a/jdk/test/javax/xml/crypto/dsig/ValidationTests.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/javax/xml/crypto/dsig/ValidationTests.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2012, 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
@@ -23,7 +23,7 @@
/**
* @test
- * @bug 4635230 6365103 6366054 6824440
+ * @bug 4635230 6365103 6366054 6824440 7131084
* @summary Basic unit tests for validating XML Signatures with JSR 105
* @compile -XDignore.symbol.file KeySelectors.java SignatureValidator.java
* X509KeySelector.java ValidationTests.java
@@ -43,10 +43,6 @@
import javax.xml.crypto.dsig.XMLSignatureException;
import javax.xml.crypto.dsig.XMLSignatureFactory;
-/**
- * This is a testcase to validate all "merlin-xmldsig-twenty-three"
- * testcases from Baltimore
- */
public class ValidationTests {
private static SignatureValidator validator;
@@ -61,25 +57,14 @@
private final static String STYLESHEET_B64 =
"http://www.w3.org/Signature/2002/04/xml-stylesheet.b64";
- private final static String[] FILES = {
- "signature-enveloped-dsa.xml",
- "signature-enveloping-b64-dsa.xml",
- "signature-enveloping-dsa.xml",
- "signature-enveloping-rsa.xml",
- "signature-enveloping-hmac-sha1.xml",
- "signature-external-dsa.xml",
- "signature-external-b64-dsa.xml",
- "signature-retrievalmethod-rawx509crt.xml",
- "signature-keyname.xml",
- "signature-x509-crt-crl.xml",
- "signature-x509-crt.xml",
- "signature-x509-is.xml",
- "signature-x509-ski.xml",
- "signature-x509-sn.xml",
-// "signature.xml",
- "exc-signature.xml",
- "sign-spec.xml"
- };
+ static class Test {
+ String file;
+ KeySelector ks;
+ Test(String file, KeySelector ks) {
+ this.file = file;
+ this.ks = ks;
+ }
+ }
static KeySelector skks;
static {
@@ -98,26 +83,34 @@
private final static KeySelector RXKS =
new KeySelectors.RawX509KeySelector();
private final static KeySelector XKS = null;
- private final static KeySelector[] KEY_SELECTORS = {
- KVKS,
- KVKS,
- KVKS,
- KVKS,
- SKKS,
- KVKS,
- KVKS,
- CKS,
- CKS,
- RXKS,
- RXKS,
- CKS,
- CKS,
- CKS,
-// XKS,
- KVKS,
- RXKS
+ private static URIDereferencer httpUd = null;
+
+ private final static Test[] VALID_TESTS = {
+ new Test("signature-enveloped-dsa.xml", KVKS),
+ new Test("signature-enveloping-b64-dsa.xml", KVKS),
+ new Test("signature-enveloping-dsa.xml", KVKS),
+ new Test("signature-enveloping-rsa.xml", KVKS),
+ new Test("signature-enveloping-hmac-sha1.xml", SKKS),
+ new Test("signature-external-dsa.xml", KVKS),
+ new Test("signature-external-b64-dsa.xml", KVKS),
+ new Test("signature-retrievalmethod-rawx509crt.xml", CKS),
+ new Test("signature-keyname.xml", CKS),
+ new Test("signature-x509-crt-crl.xml", RXKS),
+ new Test("signature-x509-crt.xml", RXKS),
+ new Test("signature-x509-is.xml", CKS),
+ new Test("signature-x509-ski.xml", CKS),
+ new Test("signature-x509-sn.xml", CKS),
+ new Test("signature.xml", XKS),
+ new Test("exc-signature.xml", KVKS),
+ new Test("sign-spec.xml", RXKS),
+ new Test("xmldsig-xfilter2.xml", KVKS)
};
- private static URIDereferencer httpUd = null;
+
+ private final static Test[] INVALID_TESTS = {
+ new Test("signature-enveloping-hmac-sha1-40.xml", SKKS),
+ new Test("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", SKKS),
+ new Test("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", SKKS)
+ };
public static void main(String args[]) throws Exception {
httpUd = new HttpURIDereferencer();
@@ -125,9 +118,9 @@
validator = new SignatureValidator(new File(DATA_DIR));
boolean atLeastOneFailed = false;
- for (int i=0; i < FILES.length; i++) {
- System.out.println("Validating " + FILES[i]);
- if (test_signature(FILES[i], KEY_SELECTORS[i])) {
+ for (Test test : VALID_TESTS) {
+ System.out.println("Validating " + test.file);
+ if (test_signature(test)) {
System.out.println("PASSED");
} else {
System.out.println("FAILED");
@@ -136,41 +129,23 @@
}
// test with reference caching enabled
System.out.println("Validating sign-spec.xml with caching enabled");
- if (test_signature("sign-spec.xml", RXKS, true)) {
+ if (test_signature(new Test("sign-spec.xml", RXKS), true)) {
System.out.println("PASSED");
} else {
System.out.println("FAILED");
atLeastOneFailed = true;
}
- System.out.println("Validating signature-enveloping-hmac-sha1-40.xml");
- try {
- test_signature("signature-enveloping-hmac-sha1-40.xml", SKKS, false);
- System.out.println("FAILED");
- atLeastOneFailed = true;
- } catch (XMLSignatureException xse) {
- System.out.println(xse.getMessage());
- System.out.println("PASSED");
- }
-
- System.out.println("Validating signature-enveloping-hmac-sha1-trunclen-0-attack.xml");
- try {
- test_signature("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", SKKS, false);
- System.out.println("FAILED");
- atLeastOneFailed = true;
- } catch (XMLSignatureException xse) {
- System.out.println(xse.getMessage());
- System.out.println("PASSED");
- }
-
- System.out.println("Validating signature-enveloping-hmac-sha1-trunclen-8-attack.xml");
- try {
- test_signature("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", SKKS, false);
- System.out.println("FAILED");
- atLeastOneFailed = true;
- } catch (XMLSignatureException xse) {
- System.out.println(xse.getMessage());
- System.out.println("PASSED");
+ for (Test test : INVALID_TESTS) {
+ System.out.println("Validating " + test.file);
+ try {
+ test_signature(test);
+ System.out.println("FAILED");
+ atLeastOneFailed = true;
+ } catch (XMLSignatureException xse) {
+ System.out.println(xse.getMessage());
+ System.out.println("PASSED");
+ }
}
if (atLeastOneFailed) {
@@ -179,20 +154,21 @@
}
}
- public static boolean test_signature(String file, KeySelector ks)
- throws Exception {
- return test_signature(file, ks, false);
+ public static boolean test_signature(Test test) throws Exception {
+ return test_signature(test, false);
}
- public static boolean test_signature(String file, KeySelector ks,
- boolean cache) throws Exception {
- if (ks == null) {
+ public static boolean test_signature(Test test, boolean cache)
+ throws Exception
+ {
+ if (test.ks == null) {
KeyStore keystore = KeyStore.getInstance("JKS");
- keystore.load
- (new FileInputStream(KEYSTORE), "changeit".toCharArray());
- ks = new X509KeySelector(keystore, false);
+ try (FileInputStream fis = new FileInputStream(KEYSTORE)) {
+ keystore.load(fis, "changeit".toCharArray());
+ test.ks = new X509KeySelector(keystore, false);
+ }
}
- return validator.validate(file, ks, httpUd, cache);
+ return validator.validate(test.file, test.ks, httpUd, cache);
}
/**
--- a/jdk/test/javax/xml/crypto/dsig/X509KeySelector.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/javax/xml/crypto/dsig/X509KeySelector.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2012, 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
@@ -205,9 +205,9 @@
*/
private KeySelectorResult keyStoreSelect(CertSelector cs)
throws KeyStoreException {
- Enumeration aliases = ks.aliases();
+ Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
- String alias = (String) aliases.nextElement();
+ String alias = aliases.nextElement();
Certificate cert = ks.getCertificate(alias);
if (cert != null && cs.match(cert)) {
return new SimpleKeySelectorResult(cert.getPublicKey());
@@ -301,7 +301,7 @@
} catch (IOException ioe) {
throw new KeySelectorException(ioe);
}
- Collection certs = new ArrayList();
+ Collection<X509Certificate> certs = new ArrayList<>();
Iterator xi = xd.getContent().iterator();
while (xi.hasNext()) {
@@ -345,7 +345,7 @@
System.arraycopy(ski, 0, encodedSki, 2, ski.length);
subjectcs.setSubjectKeyIdentifier(encodedSki);
} else if (o instanceof X509Certificate) {
- certs.add((X509Certificate) o);
+ certs.add((X509Certificate)o);
// check X509CRL
// not supported: should use CertPath API
} else {
@@ -359,9 +359,7 @@
}
if (!certs.isEmpty() && !trusted) {
// try to find public key in certs in X509Data
- Iterator i = certs.iterator();
- while (i.hasNext()) {
- X509Certificate cert = (X509Certificate) i.next();
+ for (X509Certificate cert : certs) {
if (subjectcs.match(cert)) {
return new SimpleKeySelectorResult(cert.getPublicKey());
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/xml/crypto/dsig/data/xmldsig-xfilter2.xml Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?><Document><ToBeSigned><!-- comment --><Data/><NotToBeSigned><ReallyToBeSigned><!-- comment --><Data/></ReallyToBeSigned></NotToBeSigned></ToBeSigned><ToBeSigned><Data/><NotToBeSigned><Data/></NotToBeSigned></ToBeSigned><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"/><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2002/06/xmldsig-filter2"><XPath xmlns="http://www.w3.org/2002/06/xmldsig-filter2" Filter="intersect"> //FooBar </XPath><XPath xmlns="http://www.w3.org/2002/06/xmldsig-filter2" Filter="subtract"> //NotToBeSigned </XPath><XPath xmlns="http://www.w3.org/2002/06/xmldsig-filter2" Filter="union"> //ReallyToBeSigned </XPath></Transform></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>6S7pEM13ZCDvVUbP9XB8iRWFbAI=</DigestValue></Reference><Reference URI="#signature-value"><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><Transform Algorithm="http://www.w3.org/2002/06/xmldsig-filter2"><XPath xmlns="http://www.w3.org/2002/06/xmldsig-filter2" Filter="union"> / </XPath></Transform></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>2jmj7l5rSw0yVb/vlWAYkK/YBwk=</DigestValue></Reference></SignedInfo><SignatureValue Id="signature-value">cJBwfPGWSI9CiuFinTvWJLbF8bGVK5SRB/N/NjCM5IMxakBjra+KSg==</SignatureValue><KeyInfo><KeyValue><DSAKeyValue><P>/X9TgR11EilS30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuA
+HTRv8mZgt2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOu
+K2HXKu/yIgMZndFIAcc=</P><Q>l2BQjxUjC8yykrmCouuEC/BYHPU=</Q><G>9+GghdabPd7LvKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3
+zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImog9/hWuWfBpKL
+Zl6Ae1UlZAFMO/7PSSo=</G><Y>5LRac3QkDCDOPaeNF5dJQ2r0hgIWZomZV7Z9pHrRqMoepJD5xnJpJY7aA4eUSS+AHS1qOm5I6VTZ
+68hsOdPZCDFF/DiR38BzTxi4ZD0PhtmOjBh32lSNG1nhEq6e9RsyzhUw5FVYHAPnCx2bX4/8Rz8i
+EMuG0IcCiAbbzsCfGBw=</Y></DSAKeyValue></KeyValue></KeyInfo></Signature></Document>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.java Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,401 @@
+/*
+ * Copyright (c) 2003, 2011, 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 7126889
+ * @summary Incorrect SSLEngine debug output
+ *
+ * Debug output was reporting n+1 bytes of data was written when it was
+ * really was n.
+ *
+ * SunJSSE does not support dynamic system properties, no way to re-use
+ * system properties in samevm/agentvm mode.
+ */
+
+/**
+ * A SSLEngine usage example which simplifies the presentation
+ * by removing the I/O and multi-threading concerns.
+ *
+ * The test creates two SSLEngines, simulating a client and server.
+ * The "transport" layer consists two byte buffers: think of them
+ * as directly connected pipes.
+ *
+ * Note, this is a *very* simple example: real code will be much more
+ * involved. For example, different threading and I/O models could be
+ * used, transport mechanisms could close unexpectedly, and so on.
+ *
+ * When this application runs, notice that several messages
+ * (wrap/unwrap) pass before any application data is consumed or
+ * produced. (For more information, please see the SSL/TLS
+ * specifications.) There may several steps for a successful handshake,
+ * so it's typical to see the following series of operations:
+ *
+ * client server message
+ * ====== ====== =======
+ * wrap() ... ClientHello
+ * ... unwrap() ClientHello
+ * ... wrap() ServerHello/Certificate
+ * unwrap() ... ServerHello/Certificate
+ * wrap() ... ClientKeyExchange
+ * wrap() ... ChangeCipherSpec
+ * wrap() ... Finished
+ * ... unwrap() ClientKeyExchange
+ * ... unwrap() ChangeCipherSpec
+ * ... unwrap() Finished
+ * ... wrap() ChangeCipherSpec
+ * ... wrap() Finished
+ * unwrap() ... ChangeCipherSpec
+ * unwrap() ... Finished
+ */
+
+import javax.net.ssl.*;
+import javax.net.ssl.SSLEngineResult.*;
+import java.io.*;
+import java.security.*;
+import java.nio.*;
+
+public class DebugReportsOneExtraByte {
+
+ /*
+ * Enables logging of the SSLEngine operations.
+ */
+ private static boolean logging = true;
+
+ /*
+ * Enables the JSSE system debugging system property:
+ *
+ * -Djavax.net.debug=all
+ *
+ * This gives a lot of low-level information about operations underway,
+ * including specific handshake messages, and might be best examined
+ * after gaining some familiarity with this application.
+ */
+ private static boolean debug = false;
+
+ private SSLContext sslc;
+
+ private SSLEngine clientEngine; // client Engine
+ private ByteBuffer clientOut; // write side of clientEngine
+ private ByteBuffer clientIn; // read side of clientEngine
+
+ private SSLEngine serverEngine; // server Engine
+ private ByteBuffer serverOut; // write side of serverEngine
+ private ByteBuffer serverIn; // read side of serverEngine
+
+ /*
+ * For data transport, this example uses local ByteBuffers. This
+ * isn't really useful, but the purpose of this example is to show
+ * SSLEngine concepts, not how to do network transport.
+ */
+ private ByteBuffer cTOs; // "reliable" transport client->server
+ private ByteBuffer sTOc; // "reliable" transport server->client
+
+ /*
+ * The following is to set up the keystores.
+ */
+ private static String pathToStores = "../../../../../../../etc";
+ private static String keyStoreFile = "keystore";
+ private static String trustStoreFile = "truststore";
+ private static String passwd = "passphrase";
+
+ private static String keyFilename =
+ System.getProperty("test.src", ".") + "/" + pathToStores +
+ "/" + keyStoreFile;
+ private static String trustFilename =
+ System.getProperty("test.src", ".") + "/" + pathToStores +
+ "/" + trustStoreFile;
+
+ /*
+ * Main entry point for this test.
+ */
+ public static void main(String args[]) throws Exception {
+ if (debug) {
+ System.setProperty("javax.net.debug", "all");
+ }
+
+ DebugReportsOneExtraByte test = new DebugReportsOneExtraByte();
+ test.runTest();
+
+ System.out.println("Test Passed.");
+ }
+
+ /*
+ * Create an initialized SSLContext to use for these tests.
+ */
+ public DebugReportsOneExtraByte() throws Exception {
+
+ KeyStore ks = KeyStore.getInstance("JKS");
+ KeyStore ts = KeyStore.getInstance("JKS");
+
+ char[] passphrase = "passphrase".toCharArray();
+
+ ks.load(new FileInputStream(keyFilename), passphrase);
+ ts.load(new FileInputStream(trustFilename), passphrase);
+
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
+ kmf.init(ks, passphrase);
+
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
+ tmf.init(ts);
+
+ SSLContext sslCtx = SSLContext.getInstance("TLS");
+
+ sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
+
+ sslc = sslCtx;
+ }
+
+ /*
+ * Run the test.
+ *
+ * Sit in a tight loop, both engines calling wrap/unwrap regardless
+ * of whether data is available or not. We do this until both engines
+ * report back they are closed.
+ *
+ * The main loop handles all of the I/O phases of the SSLEngine's
+ * lifetime:
+ *
+ * initial handshaking
+ * application data transfer
+ * engine closing
+ *
+ * One could easily separate these phases into separate
+ * sections of code.
+ */
+ private void runTest() throws Exception {
+ boolean dataDone = false;
+
+ createSSLEngines();
+ createBuffers();
+
+ SSLEngineResult clientResult; // results from client's last operation
+ SSLEngineResult serverResult; // results from server's last operation
+
+ /*
+ * Examining the SSLEngineResults could be much more involved,
+ * and may alter the overall flow of the application.
+ *
+ * For example, if we received a BUFFER_OVERFLOW when trying
+ * to write to the output pipe, we could reallocate a larger
+ * pipe, but instead we wait for the peer to drain it.
+ */
+
+ /*
+ * Write one byte in first application packet, the rest
+ * will come later.
+ */
+ serverOut.limit(1);
+
+ while (!isEngineClosed(clientEngine) ||
+ !isEngineClosed(serverEngine)) {
+
+ log("================");
+
+ clientResult = clientEngine.wrap(clientOut, cTOs);
+ log("client wrap: ", clientResult);
+ runDelegatedTasks(clientResult, clientEngine);
+
+ serverResult = serverEngine.wrap(serverOut, sTOc);
+ log("server wrap: ", serverResult);
+ runDelegatedTasks(serverResult, serverEngine);
+
+ // Next wrap will split.
+ if (serverOut.position() == 1) {
+ serverOut.limit(serverOut.capacity());
+ }
+
+ cTOs.flip();
+ sTOc.flip();
+
+ log("----");
+
+ clientResult = clientEngine.unwrap(sTOc, clientIn);
+ log("client unwrap: ", clientResult);
+ runDelegatedTasks(clientResult, clientEngine);
+
+ serverResult = serverEngine.unwrap(cTOs, serverIn);
+ log("server unwrap: ", serverResult);
+ runDelegatedTasks(serverResult, serverEngine);
+
+ cTOs.compact();
+ sTOc.compact();
+
+ /*
+ * After we've transfered all application data between the client
+ * and server, we close the clientEngine's outbound stream.
+ * This generates a close_notify handshake message, which the
+ * server engine receives and responds by closing itself.
+ */
+ if (!dataDone && (clientOut.limit() == serverIn.position()) &&
+ (serverOut.limit() == clientIn.position())) {
+
+ /*
+ * A sanity check to ensure we got what was sent.
+ */
+ checkTransfer(serverOut, clientIn);
+ checkTransfer(clientOut, serverIn);
+
+ log("\tClosing clientEngine's *OUTBOUND*...");
+ clientEngine.closeOutbound();
+ dataDone = true;
+ }
+ }
+ }
+
+ /*
+ * Using the SSLContext created during object creation,
+ * create/configure the SSLEngines we'll use for this test.
+ */
+ private void createSSLEngines() throws Exception {
+ /*
+ * Configure the serverEngine to act as a server in the SSL/TLS
+ * handshake. Also, require SSL client authentication.
+ */
+ serverEngine = sslc.createSSLEngine();
+ serverEngine.setUseClientMode(false);
+ serverEngine.setNeedClientAuth(true);
+
+ // Force a block-oriented ciphersuite.
+ serverEngine.setEnabledCipherSuites(
+ new String [] {"TLS_RSA_WITH_AES_128_CBC_SHA"});
+
+ /*
+ * Similar to above, but using client mode instead.
+ */
+ clientEngine = sslc.createSSLEngine("client", 80);
+ clientEngine.setUseClientMode(true);
+ }
+
+ /*
+ * Create and size the buffers appropriately.
+ */
+ private void createBuffers() {
+
+ /*
+ * We'll assume the buffer sizes are the same
+ * between client and server.
+ */
+ SSLSession session = clientEngine.getSession();
+ int appBufferMax = session.getApplicationBufferSize();
+ int netBufferMax = session.getPacketBufferSize();
+
+ /*
+ * We'll make the input buffers a bit bigger than the max needed
+ * size, so that unwrap()s following a successful data transfer
+ * won't generate BUFFER_OVERFLOWS.
+ *
+ * We'll use a mix of direct and indirect ByteBuffers for
+ * tutorial purposes only. In reality, only use direct
+ * ByteBuffers when they give a clear performance enhancement.
+ */
+ clientIn = ByteBuffer.allocate(appBufferMax + 50);
+ serverIn = ByteBuffer.allocate(appBufferMax + 50);
+
+ cTOs = ByteBuffer.allocateDirect(netBufferMax);
+ sTOc = ByteBuffer.allocateDirect(netBufferMax);
+
+ // No need to write anything on the client side, it will
+ // just confuse the output.
+ clientOut = ByteBuffer.wrap("".getBytes());
+ // 10 bytes long
+ serverOut = ByteBuffer.wrap("Hi Client!".getBytes());
+ }
+
+ /*
+ * If the result indicates that we have outstanding tasks to do,
+ * go ahead and run them in this thread.
+ */
+ private static void runDelegatedTasks(SSLEngineResult result,
+ SSLEngine engine) throws Exception {
+
+ if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
+ Runnable runnable;
+ while ((runnable = engine.getDelegatedTask()) != null) {
+ log("\trunning delegated task...");
+ runnable.run();
+ }
+ HandshakeStatus hsStatus = engine.getHandshakeStatus();
+ if (hsStatus == HandshakeStatus.NEED_TASK) {
+ throw new Exception(
+ "handshake shouldn't need additional tasks");
+ }
+ log("\tnew HandshakeStatus: " + hsStatus);
+ }
+ }
+
+ private static boolean isEngineClosed(SSLEngine engine) {
+ return (engine.isOutboundDone() && engine.isInboundDone());
+ }
+
+ /*
+ * Simple check to make sure everything came across as expected.
+ */
+ private static void checkTransfer(ByteBuffer a, ByteBuffer b)
+ throws Exception {
+ a.flip();
+ b.flip();
+
+ if (!a.equals(b)) {
+ throw new Exception("Data didn't transfer cleanly");
+ } else {
+ log("\tData transferred cleanly");
+ }
+
+ a.position(a.limit());
+ b.position(b.limit());
+ a.limit(a.capacity());
+ b.limit(b.capacity());
+ }
+
+ /*
+ * Logging code
+ */
+ private static boolean resultOnce = true;
+
+ private static void log(String str, SSLEngineResult result) {
+ if (!logging) {
+ return;
+ }
+ if (resultOnce) {
+ resultOnce = false;
+ System.out.println("The format of the SSLEngineResult is: \n" +
+ "\t\"getStatus() / getHandshakeStatus()\" +\n" +
+ "\t\"bytesConsumed() / bytesProduced()\"\n");
+ }
+ HandshakeStatus hsStatus = result.getHandshakeStatus();
+ log(str +
+ result.getStatus() + "/" + hsStatus + ", " +
+ result.bytesConsumed() + "/" + result.bytesProduced() +
+ " bytes");
+ if (hsStatus == HandshakeStatus.FINISHED) {
+ log("\t...ready for application data");
+ }
+ }
+
+ private static void log(String str) {
+ if (logging) {
+ System.out.println(str);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.sh Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,80 @@
+#! /bin/sh
+
+#
+# Copyright (c) 2011, 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 7126889
+# @summary Incorrect SSLEngine debug output
+#
+# ${TESTJAVA} is pointing to the JDK under test.
+#
+# set platform-dependent variables
+
+OS=`uname -s`
+case "$OS" in
+ SunOS )
+ PS=":"
+ FS="/"
+ ;;
+ Linux )
+ PS=":"
+ FS="/"
+ ;;
+ CYGWIN* )
+ PS=";"
+ FS="/"
+ ;;
+ Windows* )
+ PS=";"
+ FS="\\"
+ ;;
+ * )
+ echo "Unrecognized system!"
+ exit 1;
+ ;;
+esac
+
+${TESTJAVA}${FS}bin${FS}javac -d . ${TESTSRC}${FS}DebugReportsOneExtraByte.java
+
+STRING='main, WRITE: TLSv1 Application Data, length = 8'
+
+echo "Examining debug output for the string:"
+echo "${STRING}"
+echo "========="
+
+${TESTJAVA}${FS}bin${FS}java -Djavax.net.debug=all \
+ -Dtest.src=${TESTSRC} \
+ DebugReportsOneExtraByte 2>&1 | \
+ grep "${STRING}"
+RETVAL=$?
+
+echo "========="
+
+if [ ${RETVAL} -ne 0 ]; then
+ echo "Did NOT see the expected debug output."
+ exit 1
+else
+ echo "Received the expected debug output."
+ exit 0
+fi
--- a/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/CookieHttpsClientTest.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/CookieHttpsClientTest.java Tue Jan 31 19:08:36 2012 -0800
@@ -26,6 +26,11 @@
* @bug 7129083
* @summary Cookiemanager does not store cookies if url is read
* before setting cookiemanager
+ *
+ * SunJSSE does not support dynamic system properties, no way to re-use
+ * system properties in samevm/agentvm mode.
+ *
+ * @run main/othervm CookieHttpsClientTest
*/
import java.net.CookieHandler;
--- a/jdk/test/tools/launcher/Arrrghs.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/tools/launcher/Arrrghs.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2012, 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
@@ -26,7 +26,7 @@
* @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938
* 6894719 6968053 7067922
* @summary Argument parsing validation.
- * @compile -XDignore.symbol.file Arrrghs.java TestHelper.java
+ * @compile -XDignore.symbol.file Arrrghs.java
* @run main Arrrghs
*/
@@ -38,7 +38,7 @@
import java.io.InputStreamReader;
import java.util.Map;
-public class Arrrghs {
+public class Arrrghs extends TestHelper {
private Arrrghs(){}
/**
* This class provides various tests for arguments processing.
@@ -62,7 +62,7 @@
* SIGH, On Windows all strings are quoted, we need to unwrap it
*/
private static String removeExtraQuotes(String in) {
- if (TestHelper.isWindows) {
+ if (isWindows) {
// Trim the string and remove the enclosed quotes if any.
in = in.trim();
if (in.startsWith("\"") && in.endsWith("\"")) {
@@ -82,7 +82,7 @@
String in = rd.readLine();
while (in != null) {
- if (TestHelper.debug) System.out.println(in);
+ if (debug) System.out.println(in);
if (in.startsWith(Cookie)) {
String detectedArgument = removeExtraQuotes(in.substring(Cookie.length()));
if (expectedArguments.equals(detectedArgument)) {
@@ -94,7 +94,7 @@
detectedArgument + "'");
}
// Return the value asap if not in debug mode.
- if (!TestHelper.debug) {
+ if (!debug) {
rd.close();
istream.close();
return retval;
@@ -125,7 +125,7 @@
* Quoting could cause dissimilar testArguments and expected arguments.
*/
static int doTest(String testArguments, String expectedPattern) {
- ProcessBuilder pb = new ProcessBuilder(TestHelper.javaCmd,
+ ProcessBuilder pb = new ProcessBuilder(javaCmd,
VersionStr, testArguments);
Map<String, String> env = pb.environment();
@@ -146,8 +146,7 @@
* These tests require that a JVM (any JVM) be installed in the system registry.
* If none is installed, skip this test.
*/
- TestHelper.TestResult tr =
- TestHelper.doExec(TestHelper.javaCmd, VersionStr, "-version");
+ TestResult tr = doExec(javaCmd, VersionStr, "-version");
if (!tr.isOK()) {
System.err.println("Warning:Argument Passing Tests were skipped, " +
"no java found in system registry.");
@@ -155,38 +154,38 @@
}
// Basic test
- TestHelper.testExitValue += doTest("-a -b -c -d");
+ testExitValue += doTest("-a -b -c -d");
// Basic test with many spaces
- TestHelper.testExitValue += doTest("-a -b -c -d");
+ testExitValue += doTest("-a -b -c -d");
// Quoted whitespace does matter ?
- TestHelper.testExitValue += doTest("-a \"\"-b -c\"\" -d");
+ testExitValue += doTest("-a \"\"-b -c\"\" -d");
// Escaped quotes outside of quotes as literals
- TestHelper.testExitValue += doTest("-a \\\"-b -c\\\" -d");
+ testExitValue += doTest("-a \\\"-b -c\\\" -d");
// Check for escaped quotes inside of quotes as literal
- TestHelper.testExitValue += doTest("-a \"-b \\\"stuff\\\"\" -c -d");
+ testExitValue += doTest("-a \"-b \\\"stuff\\\"\" -c -d");
// A quote preceeded by an odd number of slashes is a literal quote
- TestHelper.testExitValue += doTest("-a -b\\\\\\\" -c -d");
+ testExitValue += doTest("-a -b\\\\\\\" -c -d");
// A quote preceeded by an even number of slashes is a literal quote
// see 6214916.
- TestHelper.testExitValue += doTest("-a -b\\\\\\\\\" -c -d");
+ testExitValue += doTest("-a -b\\\\\\\\\" -c -d");
// Make sure that whitespace doesn't interfere with the removal of the
// appropriate tokens. (space-tab-space preceeds -jre-restict-search).
- TestHelper.testExitValue += doTest("-a -b \t -jre-restrict-search -c -d","-a -b -c -d");
+ testExitValue += doTest("-a -b \t -jre-restrict-search -c -d","-a -b -c -d");
// Make sure that the mJRE tokens being stripped, aren't stripped if
// they happen to appear as arguments to the main class.
- TestHelper.testExitValue += doTest("foo -version:1.1+");
+ testExitValue += doTest("foo -version:1.1+");
System.out.println("Completed arguments quoting tests with " +
- TestHelper.testExitValue + " errors");
+ testExitValue + " errors");
}
/*
@@ -194,156 +193,167 @@
*/
static void runBasicErrorMessageTests() {
// Tests for 5030233
- TestHelper.TestResult tr = TestHelper.doExec(TestHelper.javaCmd, "-cp");
+ TestResult tr = doExec(javaCmd, "-cp");
tr.checkNegative();
tr.isNotZeroOutput();
System.out.println(tr);
- tr = TestHelper.doExec(TestHelper.javaCmd, "-classpath");
+ tr = doExec(javaCmd, "-classpath");
tr.checkNegative();
tr.isNotZeroOutput();
System.out.println(tr);
- tr = TestHelper.doExec(TestHelper.javaCmd, "-jar");
+ tr = doExec(javaCmd, "-jar");
tr.checkNegative();
tr.isNotZeroOutput();
System.out.println(tr);
- tr = TestHelper.doExec(TestHelper.javacCmd, "-cp");
+ tr = doExec(javacCmd, "-cp");
tr.checkNegative();
tr.isNotZeroOutput();
System.out.println(tr);
// Test for 6356475 "REGRESSION:"java -X" from cmdline fails"
- tr = TestHelper.doExec(TestHelper.javaCmd, "-X");
+ tr = doExec(javaCmd, "-X");
tr.checkPositive();
tr.isNotZeroOutput();
System.out.println(tr);
- tr = TestHelper.doExec(TestHelper.javaCmd, "-help");
+ tr = doExec(javaCmd, "-help");
tr.checkPositive();
tr.isNotZeroOutput();
System.out.println(tr);
// 6753938, test for non-negative exit value for an incorrectly formed
// command line, '% java'
- tr = TestHelper.doExec(TestHelper.javaCmd);
+ tr = doExec(javaCmd);
tr.checkNegative();
tr.isNotZeroOutput();
System.out.println(tr);
// 6753938, test for non-negative exit value for an incorrectly formed
// command line, '% java -Xcomp'
- tr = TestHelper.doExec(TestHelper.javaCmd, "-Xcomp");
+ tr = doExec(javaCmd, "-Xcomp");
tr.checkNegative();
tr.isNotZeroOutput();
System.out.println(tr);
}
/*
- * A set of tests which tests various dispositions of the main method.
+ * Tests various dispositions of the main method, these tests are limited
+ * to English locales as they check for error messages that are localized.
*/
static void runMainMethodTests() throws FileNotFoundException {
- TestHelper.TestResult tr = null;
+ if (!isEnglishLocale()) {
+ return;
+ }
+
+ TestResult tr = null;
// a missing class
- TestHelper.createJar("MIA", new File("some.jar"), new File("Foo"),
+ createJar("MIA", new File("some.jar"), new File("Foo"),
(String[])null);
- tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
+ tr = doExec(javaCmd, "-jar", "some.jar");
tr.contains("Error: Could not find or load main class MIA");
System.out.println(tr);
// use classpath to check
- tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "MIA");
+ tr = doExec(javaCmd, "-cp", "some.jar", "MIA");
tr.contains("Error: Could not find or load main class MIA");
System.out.println(tr);
// incorrect method access
- TestHelper.createJar(new File("some.jar"), new File("Foo"),
+ createJar(new File("some.jar"), new File("Foo"),
"private static void main(String[] args){}");
- tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
+ tr = doExec(javaCmd, "-jar", "some.jar");
tr.contains("Error: Main method not found in class Foo");
System.out.println(tr);
// use classpath to check
- tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo");
+ tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
tr.contains("Error: Main method not found in class Foo");
System.out.println(tr);
// incorrect return type
- TestHelper.createJar(new File("some.jar"), new File("Foo"),
+ createJar(new File("some.jar"), new File("Foo"),
"public static int main(String[] args){return 1;}");
- tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
+ tr = doExec(javaCmd, "-jar", "some.jar");
tr.contains("Error: Main method must return a value of type void in class Foo");
System.out.println(tr);
// use classpath to check
- tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo");
+ tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
tr.contains("Error: Main method must return a value of type void in class Foo");
System.out.println(tr);
// incorrect parameter type
- TestHelper.createJar(new File("some.jar"), new File("Foo"),
+ createJar(new File("some.jar"), new File("Foo"),
"public static void main(Object[] args){}");
- tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
+ tr = doExec(javaCmd, "-jar", "some.jar");
tr.contains("Error: Main method not found in class Foo");
System.out.println(tr);
// use classpath to check
- tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo");
+ tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
tr.contains("Error: Main method not found in class Foo");
System.out.println(tr);
// incorrect method type - non-static
- TestHelper.createJar(new File("some.jar"), new File("Foo"),
+ createJar(new File("some.jar"), new File("Foo"),
"public void main(String[] args){}");
- tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
+ tr = doExec(javaCmd, "-jar", "some.jar");
tr.contains("Error: Main method is not static in class Foo");
System.out.println(tr);
// use classpath to check
- tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo");
+ tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
tr.contains("Error: Main method is not static in class Foo");
System.out.println(tr);
// amongst a potpourri of kindred main methods, is the right one chosen ?
- TestHelper.createJar(new File("some.jar"), new File("Foo"),
+ createJar(new File("some.jar"), new File("Foo"),
"void main(Object[] args){}",
"int main(Float[] args){return 1;}",
"private void main() {}",
"private static void main(int x) {}",
"public int main(int argc, String[] argv) {return 1;}",
"public static void main(String[] args) {System.out.println(\"THE_CHOSEN_ONE\");}");
- tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
+ tr = doExec(javaCmd, "-jar", "some.jar");
tr.contains("THE_CHOSEN_ONE");
System.out.println(tr);
// use classpath to check
- tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo");
+ tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
tr.contains("THE_CHOSEN_ONE");
System.out.println(tr);
// test for extraneous whitespace in the Main-Class attribute
- TestHelper.createJar(" Foo ", new File("some.jar"), new File("Foo"),
+ createJar(" Foo ", new File("some.jar"), new File("Foo"),
"public static void main(String... args){}");
- tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
+ tr = doExec(javaCmd, "-jar", "some.jar");
tr.checkPositive();
System.out.println(tr);
}
- // tests 6968053, ie. we turn on the -Xdiag (for now) flag and check if
- // the suppressed stack traces are exposed.
+ /*
+ * tests 6968053, ie. we turn on the -Xdiag (for now) flag and check if
+ * the suppressed stack traces are exposed, ignore these tests for localized
+ * locales, limiting to English only.
+ */
static void runDiagOptionTests() throws FileNotFoundException {
- TestHelper.TestResult tr = null;
+ if (!isEnglishLocale()) { // only english version
+ return;
+ }
+ TestResult tr = null;
// a missing class
- TestHelper.createJar("MIA", new File("some.jar"), new File("Foo"),
+ createJar("MIA", new File("some.jar"), new File("Foo"),
(String[])null);
- tr = TestHelper.doExec(TestHelper.javaCmd, "-Xdiag", "-jar", "some.jar");
+ tr = doExec(javaCmd, "-Xdiag", "-jar", "some.jar");
tr.contains("Error: Could not find or load main class MIA");
tr.contains("java.lang.ClassNotFoundException: MIA");
System.out.println(tr);
// use classpath to check
- tr = TestHelper.doExec(TestHelper.javaCmd, "-Xdiag", "-cp", "some.jar", "MIA");
+ tr = doExec(javaCmd, "-Xdiag", "-cp", "some.jar", "MIA");
tr.contains("Error: Could not find or load main class MIA");
tr.contains("java.lang.ClassNotFoundException: MIA");
System.out.println(tr);
// a missing class on the classpath
- tr = TestHelper.doExec(TestHelper.javaCmd, "-Xdiag", "NonExistentClass");
+ tr = doExec(javaCmd, "-Xdiag", "NonExistentClass");
tr.contains("Error: Could not find or load main class NonExistentClass");
tr.contains("java.lang.ClassNotFoundException: NonExistentClass");
System.out.println(tr);
@@ -351,23 +361,29 @@
static void test6894719() {
// test both arguments to ensure they exist
- TestHelper.TestResult tr = null;
- tr = TestHelper.doExec(TestHelper.javaCmd,
+ TestResult tr = null;
+ tr = doExec(javaCmd,
"-no-jre-restrict-search", "-version");
tr.checkPositive();
System.out.println(tr);
- tr = TestHelper.doExec(TestHelper.javaCmd,
+ tr = doExec(javaCmd,
"-jre-restrict-search", "-version");
tr.checkPositive();
System.out.println(tr);
}
+ /*
+ * a missing manifest entry 7067922, we ignore this test for locales
+ * which are localized, thus the testing is limited to English locales.
+ */
static void test7067922() {
- // a missing manifest entry 7067922
- TestHelper.TestResult tr = null;
- TestHelper.createJar("cvf", "missingmainentry.jar", ".");
- tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "missingmainentry.jar");
+ if (!isEnglishLocale()) {
+ return;
+ }
+ TestResult tr = null;
+ createJar("cvf", "missingmainentry.jar", ".");
+ tr = doExec(javaCmd, "-jar", "missingmainentry.jar");
tr.contains("no main manifest attribute");
System.out.println(tr);
}
@@ -377,7 +393,7 @@
* @throws java.io.FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException {
- if (TestHelper.debug) {
+ if (debug) {
System.out.println("Starting Arrrghs tests");
}
quoteParsingTests();
@@ -386,8 +402,8 @@
test6894719();
test7067922();
runDiagOptionTests();
- if (TestHelper.testExitValue > 0) {
- System.out.println("Total of " + TestHelper.testExitValue + " failed");
+ if (testExitValue > 0) {
+ System.out.println("Total of " + testExitValue + " failed");
System.exit(1);
} else {
System.out.println("All tests pass");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/tools/launcher/ChangeDataModel.java Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2012, 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 4894330 4810347 6277269
+ * @compile -XDignore.symbol.file ChangeDataModel.java
+ * @run main ChangeDataModel
+ * @summary Verify -d32 and -d64 options are accepted(rejected) on all platforms
+ * @author Joseph D. Darcy, ksrini
+ */
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ChangeDataModel extends TestHelper {
+ private static final File TestJar = new File("test" + JAR_FILE_EXT);
+ private static final String OPT_PREFIX = "ARCH_OPT:";
+
+ public static void main(String... args) throws Exception {
+ String[] code = {
+ " public static void main(String argv[]) {",
+ " System.out.println(\"" + OPT_PREFIX + "-d\" + System.getProperty(\"sun.arch.data.model\", \"none\"));",
+ " }",
+ };
+ createJar(TestJar, code);
+
+ // verify if data model flag for default data model is accepted
+ if (is32Bit) {
+ checkAcceptance(javaCmd, "-d32");
+ } else if (is64Bit) {
+ checkAcceptance(javaCmd, "-d64");
+ } else {
+ throw new Error("unsupported data model");
+ }
+
+ // test dual mode systems
+ if (isDualMode) {
+ // albeit dual mode we may not have the 64 bit components present
+ if (dualModePresent()) {
+ // 32-bit -> 64-bit
+ checkExecCount(javaCmd, "-d64");
+ // 64-bit -> 32-bit
+ checkExecCount(java64Cmd, "-d32");
+
+ checkAcceptance(javaCmd, "-d64");
+ checkAcceptance(java64Cmd, "-d32");
+ } else {
+ System.out.println("Warning: no 64-bit components found;" +
+ " only one data model tested.");
+ }
+ } else {
+ // Negative tests: ensure that non-dual mode systems reject the
+ // complementary (other) data model
+ if (is32Bit) {
+ checkRejection(javaCmd, "-d64");
+ } else if (is64Bit) {
+ checkRejection(javaCmd, "-d32");
+ } else {
+ throw new Error("unsupported data model");
+ }
+ }
+ }
+
+ static void checkExecCount(String cmd, String dmodel) {
+ Map<String, String> envMap = new HashMap<>();
+ envMap.put(JLDEBUG_KEY, "true");
+ TestResult tr = doExec(envMap, javaCmd, "-d64",
+ "-jar", TestJar.getAbsolutePath());
+ int count = 0;
+ for (String x : tr.testOutput) {
+ if (x.contains(EXPECTED_MARKER)) {
+ count++;
+ if (count > 1) {
+ System.out.println(tr);
+ throw new RuntimeException("Maximum exec count of 1 execeeded");
+ }
+ }
+ }
+ }
+
+ static void checkAcceptance(String cmd, String dmodel) {
+ TestResult tr = doExec(cmd, dmodel, "-jar", TestJar.getAbsolutePath());
+ if (!tr.contains(OPT_PREFIX + dmodel)) {
+ System.out.println(tr);
+ String message = "Data model flag " + dmodel +
+ " not accepted or had improper effect.";
+ throw new RuntimeException(message);
+ }
+ }
+
+ static void checkRejection(String cmd, String dmodel) {
+ TestResult tr = doExec(cmd, dmodel, "-jar", TestJar.getAbsolutePath());
+ if (tr.contains(OPT_PREFIX + dmodel)) {
+ System.out.println(tr);
+ String message = "Data model flag " + dmodel + " was accepted.";
+ throw new RuntimeException(message);
+ }
+ }
+}
--- a/jdk/test/tools/launcher/ChangeDataModel.sh Tue Jan 31 19:06:48 2012 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,260 +0,0 @@
-#
-# Copyright (c) 2003, 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 4894330 4810347 6277269
-# @run shell ChangeDataModel.sh
-# @summary Verify -d32 and -d64 options are accepted(rejected) on all platforms
-# @author Joseph D. Darcy
-
-OS=`uname -s`;
-
-# To remove CR from output, needed for java apps in CYGWIN, harmless otherwise
-SED_CR="sed -e s@\\r@@g"
-
-case "$OS" in
- Windows* | CYGWIN* )
- PATHSEP=";"
- ;;
-
- * )
- PATHSEP=":"
- ;;
-esac
-
-# Verify directory context variables are set
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
- exit 1
-fi
-
-if [ "${TESTSRC}" = "" ]
-then
- echo "TESTSRC not set. Test cannot execute. Failed."
- exit 1
-fi
-
-if [ "${TESTCLASSES}" = "" ]
-then
- echo "TESTCLASSES not set. Test cannot execute. Failed."
- exit 1
-fi
-
-# Construct paths to default Java executables
-JAVA="$TESTJAVA/bin/java -classpath $TESTCLASSES${PATHSEP}."
-JAVAC="$TESTJAVA/bin/javac"
-
-
-# Create our little Java test on the fly
-( printf "public class GetDataModel {"
- printf " public static void main(String argv[]) {"
- printf " System.out.println(System.getProperty(\"sun.arch.data.model\", \"none\"));"
- printf " }"
- printf "}"
-) > GetDataModel.java
-
-$JAVAC GetDataModel.java
-
-
-# All preconditions are met; run the tests.
-
-
-# Verify data model flag for default data model is accepted
-
-DM=`$JAVA GetDataModel | ${SED_CR}`
-case "$DM" in
- 32 )
- DM2=`${JAVA} -d32 GetDataModel | ${SED_CR}`
- if [ "${DM2}" != "32" ]
- then
- echo "Data model flag -d32 not accepted or had improper effect."
- exit 1
- fi
- ;;
-
- 64 )
- DM2=`${JAVA} -d64 GetDataModel | ${SED_CR}`
- if [ "${DM2}" != "64" ]
- then
- echo "Data model flag -d64 not accepted or had improper effect."
- exit 1
- fi
- ;;
-
- * )
- echo "Unrecognized data model: $DM"
- exit 1
- ;;
-esac
-
-# Determine if platform might be dual-mode capable.
-
-case "$OS" in
- SunOS )
- # ARCH should be sparc or i386
- ARCH=`uname -p`
- case "${ARCH}" in
- sparc )
- DUALMODE=true
- PATH64=sparcv9
- ;;
-
- i386 )
- DUALMODE=true
- PATH64=amd64
- ;;
-
- * )
- DUALMODE=false
- ;;
- esac
- ;;
-
-
- Linux )
- # ARCH should be ia64, x86_64, or i*86
- ARCH=`uname -m`
- case "${ARCH}" in
- ia64 )
- DUALMODE=false
- ;;
-
- x86_64 )
- DUALMODE=true
- PATH64=amd64
- ;;
-
- * )
- DUALMODE=false;
- ;;
- esac
- ;;
-
- Windows* | CYGWIN* )
- ARCH=`uname -m`
- case "${ARCH}" in
- * )
- DUALMODE=false;
- ;;
- esac
- ;;
-
- * )
- echo "Warning: unknown environment."
- DUALMODE=false
- ;;
-esac
-
-if [ "${DUALMODE}" = "true" ]
-then
- # Construct path to 64-bit Java executable, might not exist
- JAVA64FILE="${TESTJAVA}/bin/${PATH64}/java"
- JAVA64="${JAVA64FILE} -classpath ${TESTCLASSES}${PATHSEP}."
-
- if [ -f ${JAVA64FILE} ]; then
- # Verify that, at least on Solaris, only one exec is
- # used to change data models
- if [ "${OS}" = "SunOS" ]
- then
- rm -f truss.out
- truss -texec ${JAVA} -d64 GetDataModel > /dev/null 2> truss.out
- execCount=`grep -c execve truss.out`
- if [ "${execCount}" -gt 2 ]
- then
- echo "Maximum exec count of 2 exceeded: got $execCount."
- exit 1
- fi
-
- rm -f truss.out
- truss -texec ${JAVA64} -d32 GetDataModel > /dev/null 2> truss.out
- execCount=`grep -c execve truss.out`
- if [ "${execCount}" -gt 2 ]
- then
- echo "Maximum exec count of 2 exceeded: got $execCount."
- exit 1
- fi
- fi
-
- DM2=`${JAVA} -d64 GetDataModel`
- if [ "${DM2}" != "64" ]
- then
- echo "Data model flag -d64 not accepted or had improper effect."
- exit 1
- fi
-
- DM2=`${JAVA64} GetDataModel`
- if [ "${DM2}" != "64" ]
- then
- echo "Improper data model returned."
- exit 1
- fi
-
- DM2=`${JAVA64} -d64 GetDataModel`
- if [ "${DM2}" != "64" ]
- then
- echo "Data model flag -d64 not accepted or had improper effect."
- exit 1
- fi
-
- DM2=`${JAVA64} -d32 GetDataModel`
- if [ "${DM2}" != "32" ]
- then
- echo "Data model flag -d32 not accepted or had improper effect."
- exit 1
- fi
-
- else
- echo "Warning: no 64-bit components found; only one data model tested."
- fi
-else
-# Negative tests for non-dual mode platforms to ensure the other data model is
-# rejected
- DM=`$JAVA GetDataModel | ${SED_CR}`
- case "$DM" in
- 32 )
- DM2=`${JAVA} -d64 GetDataModel | ${SED_CR}`
- if [ "x${DM2}" != "x" ]
- then
- echo "Data model flag -d64 was accepted."
- exit 1
- fi
- ;;
-
- 64 )
- DM2=`${JAVA} -d32 GetDataModel | ${SED_CR}`
- if [ "x${DM2}" != "x" ]
- then
- echo "Data model flag -d32 was accepted."
- exit 1
- fi
- ;;
-
- * )
- echo "Unrecognized data model: $DM"
- exit 1
- ;;
- esac
-fi
-
-exit 0;
--- a/jdk/test/tools/launcher/CreatePlatformFile.java Tue Jan 31 19:06:48 2012 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-/*
- * 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.
- */
-
-/*
- *
- *
- * This class is used by test i18nTest.sh
- *
- * Class to create various i18n Hello World Java source files using
- * the platform's default encoding of a non-ASCII name; create plain
- * ASCII Hello World if the platform's default is charset is US-ASCII.
- */
-
-import java.io.PrintWriter;
-import java.io.FileOutputStream;
-
-public class CreatePlatformFile {
- public static void main(String argv[]) {
- String fileSep = System.getProperty("file.separator");
- String defaultEncoding = System.getProperty("file.encoding");
-
- if(defaultEncoding == null) {
- System.err.println("Default encoding not found; Error.");
- return;
- }
-
- if (defaultEncoding.equals("Cp1252") ) {
- // "HelloWorld" with an accented e
- String fileName = "i18nH\u00e9lloWorld.java";
- try {
- PrintWriter pw = new PrintWriter(new FileOutputStream("."+fileSep+fileName));
- pw.println("public class i18nH\u00e9lloWorld {");
- pw.println(" public static void main(String [] argv) {");
- pw.println(" System.out.println(\"Hello Cp1252 World\");");
- pw.println(" }");
- pw.println("}");
- pw.flush();
- pw.close();
- }
- catch (java.io.FileNotFoundException e) {
- System.err.println("Problem opening file; test fails");
- }
-
- } else {
- // ASCII "HelloWorld"
- String fileName = "i18nHelloWorld.java";
- try {
- PrintWriter pw = new PrintWriter(new FileOutputStream("."+fileSep+fileName));
- pw.println("public class i18nHelloWorld {");
- pw.println(" public static void main(String [] argv) {");
- pw.println(" System.out.println(\"Warning: US-ASCII assumed; filenames with\");");
- pw.println(" System.out.println(\"non-ASCII characters will not be tested\");");
- pw.println(" }");
- pw.println("}");
- pw.flush();
- pw.close();
- }
- catch (java.io.FileNotFoundException e) {
- System.err.println("Problem opening file; test fails");
- }
- }
- }
-}
--- a/jdk/test/tools/launcher/DefaultLocaleTestRun.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/tools/launcher/DefaultLocaleTestRun.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2012, 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
@@ -31,23 +31,24 @@
Following 2 testing scenarios are recommended
(1)systemLocale=Japanese, userLocale=English
(2)systemLocale=English, userLocale=Japanese
- * @compile -XDignore.symbol.file DefaultLocaleTest.java TestHelper.java
+ * @compile -XDignore.symbol.file DefaultLocaleTest.java
* @run main DefaultLocaleTestRun
*/
-import java.io.File;
-public class DefaultLocaleTestRun {
+public class DefaultLocaleTestRun extends TestHelper {
public static void main(String... args) {
- if (!TestHelper.isWindows) {
+ if (!isWindows) {
System.out.println("Test passes vacuously on non-windows");
return;
}
- TestHelper.TestResult tr = null;
- tr = TestHelper.doExec(TestHelper.javaCmd, "DefaultLocaleTest", "-w",
- "x.out");
+ TestResult tr = null;
+ tr = doExec(javaCmd,
+ "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
+ "DefaultLocaleTest", "-w", "x.out");
System.out.println(tr.testOutput);
- tr = TestHelper.doExec(TestHelper.javawCmd, "DefaultLocaleTest", "-r",
- "x.out");
+ tr = doExec(javawCmd,
+ "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
+ "DefaultLocaleTest", "-r", "x.out");
System.out.println(tr.testOutput);
if (!tr.isOK()) {
throw new RuntimeException("Test failed");
--- a/jdk/test/tools/launcher/ExecutionEnvironment.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/tools/launcher/ExecutionEnvironment.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2012, 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
@@ -25,7 +25,7 @@
* @test
* @bug 4780570 4731671 6354700 6367077 6670965 4882974
* @summary Checks for LD_LIBRARY_PATH and execution on *nixes
- * @compile -XDignore.symbol.file ExecutionEnvironment.java TestHelper.java
+ * @compile -XDignore.symbol.file ExecutionEnvironment.java
* @run main ExecutionEnvironment
*/
@@ -60,7 +60,7 @@
import java.util.Map;
-public class ExecutionEnvironment {
+public class ExecutionEnvironment extends TestHelper {
static final String LD_LIBRARY_PATH = "LD_LIBRARY_PATH";
static final String LD_LIBRARY_PATH_32 = LD_LIBRARY_PATH + "_32";
static final String LD_LIBRARY_PATH_64 = LD_LIBRARY_PATH + "_64";
@@ -70,9 +70,6 @@
static final String LD_LIBRARY_PATH_32_VALUE = "/Lawrence/Of/Arabia";
static final String LD_LIBRARY_PATH_64_VALUE = "/A/Passage/To/India";
- static final String JLDEBUG_KEY = "_JAVA_LAUNCHER_DEBUG";
- static final String EXPECTED_MARKER = "TRACER_MARKER:About to EXEC";
-
static final String[] LD_PATH_STRINGS = {
LD_LIBRARY_PATH + "=" + LD_LIBRARY_PATH_VALUE,
LD_LIBRARY_PATH_32 + "=" + LD_LIBRARY_PATH_32_VALUE,
@@ -84,11 +81,11 @@
static int errors = 0;
static int passes = 0;
- static final String LIBJVM = TestHelper.isWindows ? "jvm.dll" : "libjvm.so";
+ static final String LIBJVM = isWindows ? "jvm.dll" : "libjvm.so";
static void createTestJar() {
try {
- List<String> codeList = new ArrayList<String>();
+ List<String> codeList = new ArrayList<>();
codeList.add("static void printValue(String name, boolean property) {\n");
codeList.add(" String value = (property) ? System.getProperty(name) : System.getenv(name);\n");
codeList.add(" System.out.println(name + \"=\" + value);\n");
@@ -105,7 +102,7 @@
codeList.add(" printValue(\"" + LD_LIBRARY_PATH_64 + "\", false);\n");
codeList.add("}\n");
String[] clist = new String[codeList.size()];
- TestHelper.createJar(testJarFile, codeList.toArray(clist));
+ createJar(testJarFile, codeList.toArray(clist));
} catch (FileNotFoundException fnfe) {
throw new RuntimeException(fnfe);
}
@@ -117,16 +114,15 @@
* environment should be pristine.
*/
private static void ensureEcoFriendly() {
- TestHelper.TestResult tr = null;
+ TestResult tr = null;
- Map<String, String> env = new HashMap<String, String>();
+ Map<String, String> env = new HashMap<>();
for (String x : LD_PATH_STRINGS) {
String pairs[] = x.split("=");
env.put(pairs[0], pairs[1]);
}
- tr = TestHelper.doExec(env, TestHelper.javaCmd, "-jar",
- testJarFile.getAbsolutePath());
+ tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());
if (!tr.isNotZeroOutput()) {
System.out.println(tr);
@@ -149,10 +145,9 @@
* data model
*/
static void ensureNoExec() {
- Map<String, String> env = new HashMap<String, String>();
+ Map<String, String> env = new HashMap<>();
env.put(JLDEBUG_KEY, "true");
- TestHelper.TestResult tr =
- TestHelper.doExec(env, TestHelper.javaCmd, "-version");
+ TestResult tr = doExec(env, javaCmd, "-version");
if (tr.testOutput.contains(EXPECTED_MARKER)) {
System.out.println("FAIL: EnsureNoExecs: found expected warning <" +
EXPECTED_MARKER +
@@ -176,25 +171,23 @@
*/
static void verifyJavaLibraryPath() {
- TestHelper.TestResult tr = null;
+ TestResult tr = null;
- Map<String, String> env = new HashMap<String, String>();
+ Map<String, String> env = new HashMap<>();
- if (TestHelper.isLinux) {
+ if (isLinux) {
for (String x : LD_PATH_STRINGS) {
String pairs[] = x.split("=");
env.put(pairs[0], pairs[1]);
}
- tr = TestHelper.doExec(env, TestHelper.javaCmd, "-jar",
- testJarFile.getAbsolutePath());
+ tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());
verifyJavaLibraryPathGeneric(tr);
} else {
// no override
env.clear();
env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE);
- tr = TestHelper.doExec(env, TestHelper.javaCmd, "-jar",
- testJarFile.getAbsolutePath());
+ tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());
verifyJavaLibraryPathGeneric(tr);
env.clear();
@@ -206,53 +199,52 @@
// verify the override occurs, since we know the invocation always
// uses by default is 32-bit, therefore we also set the test
// expectation to be the same.
- tr = TestHelper.doExec(env, TestHelper.javaCmd, "-jar",
- testJarFile.getAbsolutePath());
+ tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());
verifyJavaLibraryPathOverride(tr, true);
// try changing the model from 32 to 64 bit
- if (TestHelper.dualModePresent() && TestHelper.is32Bit) {
+ if (dualModePresent() && is32Bit) {
// verify the override occurs
env.clear();
for (String x : LD_PATH_STRINGS) {
String pairs[] = x.split("=");
env.put(pairs[0], pairs[1]);
}
- tr = TestHelper.doExec(env, TestHelper.javaCmd, "-d64", "-jar",
+ tr = doExec(env, javaCmd, "-d64", "-jar",
testJarFile.getAbsolutePath());
verifyJavaLibraryPathOverride(tr, false);
// no override
env.clear();
env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE);
- tr = TestHelper.doExec(env, TestHelper.javaCmd, "-jar",
+ tr = doExec(env, javaCmd, "-jar",
testJarFile.getAbsolutePath());
verifyJavaLibraryPathGeneric(tr);
}
// try changing the model from 64 to 32 bit
- if (TestHelper.java64Cmd != null && TestHelper.is64Bit) {
+ if (java64Cmd != null && is64Bit) {
// verify the override occurs
env.clear();
for (String x : LD_PATH_STRINGS) {
String pairs[] = x.split("=");
env.put(pairs[0], pairs[1]);
}
- tr = TestHelper.doExec(env, TestHelper.java64Cmd, "-d32", "-jar",
+ tr = doExec(env, java64Cmd, "-d32", "-jar",
testJarFile.getAbsolutePath());
verifyJavaLibraryPathOverride(tr, true);
// no override
env.clear();
env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE);
- tr = TestHelper.doExec(env, TestHelper.java64Cmd, "-d32", "-jar",
+ tr = doExec(env, java64Cmd, "-d32", "-jar",
testJarFile.getAbsolutePath());
verifyJavaLibraryPathGeneric(tr);
}
}
}
- private static void verifyJavaLibraryPathGeneric(TestHelper.TestResult tr) {
+ private static void verifyJavaLibraryPathGeneric(TestResult tr) {
if (!tr.matches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) {
System.out.print("FAIL: verifyJavaLibraryPath: ");
System.out.println(" java.library.path does not contain " +
@@ -264,7 +256,7 @@
}
}
- private static void verifyJavaLibraryPathOverride(TestHelper.TestResult tr,
+ private static void verifyJavaLibraryPathOverride(TestResult tr,
boolean is32Bit) {
// make sure the 32/64 bit value exists
if (!tr.matches("java.library.path=.*" +
@@ -295,10 +287,10 @@
*/
static void verifyVmSelection() {
- TestHelper.TestResult tr = null;
+ TestResult tr = null;
- if (TestHelper.is32Bit) {
- tr = TestHelper.doExec(TestHelper.javaCmd, "-client", "-version");
+ if (is32Bit) {
+ tr = doExec(javaCmd, "-client", "-version");
if (!tr.matches(".*Client VM.*")) {
System.out.println("FAIL: the expected vm -client did not launch");
System.out.println(tr);
@@ -307,7 +299,7 @@
passes++;
}
}
- tr = TestHelper.doExec(TestHelper.javaCmd, "-server", "-version");
+ tr = doExec(javaCmd, "-server", "-version");
if (!tr.matches(".*Server VM.*")) {
System.out.println("FAIL: the expected vm -server did not launch");
System.out.println(tr);
@@ -321,14 +313,14 @@
* checks to see there is no extra libjvm.so than needed
*/
static void verifyNoSymLink() {
- if (TestHelper.is64Bit) {
+ if (is64Bit) {
return;
}
File symLink = null;
- String libPathPrefix = TestHelper.isSDK ? "jre/lib" : "/lib";
- symLink = new File(TestHelper.JAVAHOME, libPathPrefix +
- TestHelper.getJreArch() + "/" + LIBJVM);
+ String libPathPrefix = isSDK ? "jre/lib" : "/lib";
+ symLink = new File(JAVAHOME, libPathPrefix +
+ getJreArch() + "/" + LIBJVM);
if (symLink.exists()) {
System.out.println("FAIL: The symlink exists " +
symLink.getAbsolutePath());
@@ -339,7 +331,7 @@
}
public static void main(String... args) throws Exception {
- if (TestHelper.isWindows) {
+ if (isWindows) {
System.out.println("Warning: noop on windows");
return;
}
--- a/jdk/test/tools/launcher/I18NJarTest.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/tools/launcher/I18NJarTest.java Tue Jan 31 19:08:36 2012 -0800
@@ -26,7 +26,7 @@
* @bug 7125442
* @summary ensures a jar path as well as a class located in a path containing
* unicode characters are launched.
- * @compile -XDignore.symbol.file I18NJarTest.java TestHelper.java
+ * @compile -XDignore.symbol.file I18NJarTest.java
* @run main/othervm I18NJarTest
*/
import java.io.File;
@@ -48,7 +48,7 @@
* in its own VM (othervm mode), such that the ensuing tests can run unperturbed,
* regardless of the outcome.
*/
-public class I18NJarTest {
+public class I18NJarTest extends TestHelper {
private static final File cwd = new File(".");
private static final File dir = new File("\uFF66\uFF67\uFF68\uFF69");
private static final String encoding = System.getProperty("sun.jnu.encoding", "");
@@ -78,7 +78,7 @@
}
dir.mkdir();
File dirfile = new File(dir, "foo.jar");
- TestHelper.createJar(dirfile,
+ createJar(dirfile,
"public static void main(String... args) {",
"System.out.println(\"Hello World\");",
"System.exit(0);",
@@ -86,22 +86,20 @@
// remove the class files, to ensure that the class is indeed picked up
// from the jar file and not from ambient classpath.
- File[] classFiles = cwd.listFiles(TestHelper.createFilter(TestHelper.CLASS_FILE_EXT));
+ File[] classFiles = cwd.listFiles(createFilter(CLASS_FILE_EXT));
for (File f : classFiles) {
f.delete();
}
// test with a jar file
- TestHelper.TestResult tr = TestHelper.doExec(TestHelper.javaCmd,
- "-jar", dirfile.getAbsolutePath());
+ TestResult tr = doExec(javaCmd, "-jar", dirfile.getAbsolutePath());
System.out.println(tr);
if (!tr.isOK()) {
throw new RuntimeException("TEST FAILED");
}
// test the same class but by specifying it as a classpath
- tr = TestHelper.doExec(TestHelper.javaCmd, "-cp",
- dirfile.getAbsolutePath(), "Foo");
+ tr = doExec(javaCmd, "-cp", dirfile.getAbsolutePath(), "Foo");
System.out.println(tr);
if (!tr.isOK()) {
throw new RuntimeException("TEST FAILED");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/tools/launcher/I18NTest.java Tue Jan 31 19:08:36 2012 -0800
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2012, 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 4761384
+ * @compile -XDignore.symbol.file I18NTest.java
+ * @run main I18NTest
+ * @summary Test to see if class files with non-ASCII characters can be run
+ * @author Joseph D. Darcy, Kumar Srinivasan
+ */
+
+
+import java.util.ArrayList;
+import java.io.File;
+import java.util.List;
+
+public class I18NTest extends TestHelper {
+ static String fileName = null;
+ public static void main(String... args) throws Exception {
+ String defaultEncoding = System.getProperty("file.encoding");
+ if (defaultEncoding == null) {
+ System.err.println("Default encoding not found; Error.");
+ return;
+ }
+ if (!defaultEncoding.equals("Cp1252")) {
+ System.err.println("Warning: required encoding not found, test skipped.");
+ return;
+ }
+ // for some reason the shell test version insisted on cleaning out the
+ // directory, likely being pedantic.
+ File cwd = new File(".");
+ for (File f : cwd.listFiles(createFilter(CLASS_FILE_EXT))) {
+ f.delete();
+ }
+ for (File f : cwd.listFiles(createFilter(JAVA_FILE_EXT))) {
+ f.delete();
+ }
+ createPlatformFile();
+
+ // compile the generate code using the javac compiler vs. the api, to
+ // as a bonus point to see if the argument is passed correctly
+ TestResult tr = null;
+ tr = doExec(javacCmd, fileName + JAVA_FILE_EXT);
+ if (!tr.isOK()) {
+ System.out.println(tr);
+ throw new Error("compilation failed...");
+ }
+ tr = doExec(javaCmd, "-cp", ".", fileName);
+ if (!tr.isOK()) {
+ System.out.println(tr);
+ throw new RuntimeException("run failed with encoding " + defaultEncoding);
+ }
+ }
+
+ public static void createPlatformFile() throws Exception {
+ List<String> buffer = new ArrayList<>();
+ // "HelloWorld" with an accented e
+ fileName = "i18nH\u00e9lloWorld";
+ buffer.clear();
+ buffer.add("public class i18nH\u00e9lloWorld {");
+ buffer.add(" public static void main(String [] argv) {");
+ buffer.add(" System.out.println(\"Hello Cp1252 World\");");
+ buffer.add(" }");
+ buffer.add("}");
+ File outFile = new File(fileName + JAVA_FILE_EXT);
+ createFile(outFile, buffer);
+ }
+}
--- a/jdk/test/tools/launcher/MiscTests.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/tools/launcher/MiscTests.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2012, 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
@@ -25,7 +25,7 @@
* @test
* @bug 6856415
* @summary Miscellaneous tests, Exceptions
- * @compile -XDignore.symbol.file MiscTests.java TestHelper.java
+ * @compile -XDignore.symbol.file MiscTests.java
* @run main MiscTests
*/
@@ -33,12 +33,12 @@
import java.io.File;
import java.io.FileNotFoundException;
-public class MiscTests {
+public class MiscTests extends TestHelper {
// 6856415: Checks to ensure that proper exceptions are thrown by java
static void test6856415() {
// No pkcs library on win-x64, so we bail out.
- if (TestHelper.is64Bit && TestHelper.isWindows) {
+ if (is64Bit && isWindows) {
return;
}
StringBuilder sb = new StringBuilder();
@@ -49,11 +49,11 @@
File testJar = new File("Foo.jar");
testJar.delete();
try {
- TestHelper.createJar(testJar, sb.toString());
+ createJar(testJar, sb.toString());
} catch (FileNotFoundException fnfe) {
throw new RuntimeException(fnfe);
}
- TestHelper.TestResult tr = TestHelper.doExec(TestHelper.javaCmd,
+ TestResult tr = doExec(javaCmd,
"-Djava.security.manager", "-jar", testJar.getName(), "foo.bak");
for (String s : tr.testOutput) {
System.out.println(s);
@@ -67,8 +67,8 @@
public static void main(String... args) {
test6856415();
- if (TestHelper.testExitValue != 0) {
- throw new Error(TestHelper.testExitValue + " tests failed");
+ if (testExitValue != 0) {
+ throw new Error(testExitValue + " tests failed");
}
}
}
--- a/jdk/test/tools/launcher/Settings.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/tools/launcher/Settings.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2012, 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
@@ -27,11 +27,11 @@
* @test
* @bug 6994753 7123582
* @summary tests -XshowSettings options
- * @compile -XDignore.symbol.file Settings.java TestHelper.java
+ * @compile -XDignore.symbol.file Settings.java
* @run main Settings
* @author ksrini
*/
-public class Settings {
+public class Settings extends TestHelper {
private static File testJar = null;
static void init() throws IOException {
@@ -45,17 +45,17 @@
tsrc.append(" System.out.println(x);\n");
tsrc.append(" }\n");
tsrc.append("}\n");
- TestHelper.createJar(testJar, tsrc.toString());
+ createJar(testJar, tsrc.toString());
}
- static void checkContains(TestHelper.TestResult tr, String str) {
+ static void checkContains(TestResult tr, String str) {
if (!tr.contains(str)) {
System.out.println(tr);
throw new RuntimeException(str + " not found");
}
}
- static void checkNoContains(TestHelper.TestResult tr, String str) {
+ static void checkNoContains(TestResult tr, String str) {
if (tr.contains(str)) {
System.out.println(tr.status);
throw new RuntimeException(str + " found");
@@ -66,22 +66,22 @@
private static final String PROP_SETTINGS = "Property settings:";
private static final String LOCALE_SETTINGS = "Locale settings:";
- static void containsAllOptions(TestHelper.TestResult tr) {
+ static void containsAllOptions(TestResult tr) {
checkContains(tr, VM_SETTINGS);
checkContains(tr, PROP_SETTINGS);
checkContains(tr, LOCALE_SETTINGS);
}
static void runTestOptionDefault() throws IOException {
- TestHelper.TestResult tr = null;
- tr = TestHelper.doExec(TestHelper.javaCmd, "-Xms64m", "-Xmx512m",
+ TestResult tr = null;
+ tr = doExec(javaCmd, "-Xms64m", "-Xmx512m",
"-Xss128k", "-XshowSettings", "-jar", testJar.getAbsolutePath());
containsAllOptions(tr);
if (!tr.isOK()) {
System.out.println(tr.status);
throw new RuntimeException("test fails");
}
- tr = TestHelper.doExec(TestHelper.javaCmd, "-Xms65536k", "-Xmx712m",
+ tr = doExec(javaCmd, "-Xms65536k", "-Xmx712m",
"-Xss122880", "-XshowSettings", "-jar", testJar.getAbsolutePath());
containsAllOptions(tr);
if (!tr.isOK()) {
@@ -92,38 +92,38 @@
static void runTestOptionAll() throws IOException {
init();
- TestHelper.TestResult tr = null;
- tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:all");
+ TestResult tr = null;
+ tr = doExec(javaCmd, "-XshowSettings:all");
containsAllOptions(tr);
}
static void runTestOptionVM() throws IOException {
- TestHelper.TestResult tr = null;
- tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:vm");
+ TestResult tr = null;
+ tr = doExec(javaCmd, "-XshowSettings:vm");
checkContains(tr, VM_SETTINGS);
checkNoContains(tr, PROP_SETTINGS);
checkNoContains(tr, LOCALE_SETTINGS);
}
static void runTestOptionProperty() throws IOException {
- TestHelper.TestResult tr = null;
- tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:properties");
+ TestResult tr = null;
+ tr = doExec(javaCmd, "-XshowSettings:properties");
checkNoContains(tr, VM_SETTINGS);
checkContains(tr, PROP_SETTINGS);
checkNoContains(tr, LOCALE_SETTINGS);
}
static void runTestOptionLocale() throws IOException {
- TestHelper.TestResult tr = null;
- tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:locale");
+ TestResult tr = null;
+ tr = doExec(javaCmd, "-XshowSettings:locale");
checkNoContains(tr, VM_SETTINGS);
checkNoContains(tr, PROP_SETTINGS);
checkContains(tr, LOCALE_SETTINGS);
}
static void runTestBadOptions() throws IOException {
- TestHelper.TestResult tr = null;
- tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettingsBadOption");
+ TestResult tr = null;
+ tr = doExec(javaCmd, "-XshowSettingsBadOption");
checkNoContains(tr, VM_SETTINGS);
checkNoContains(tr, PROP_SETTINGS);
checkNoContains(tr, LOCALE_SETTINGS);
@@ -131,8 +131,8 @@
}
static void runTest7123582() throws IOException {
- TestHelper.TestResult tr = null;
- tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings", "-version");
+ TestResult tr = null;
+ tr = doExec(javaCmd, "-XshowSettings", "-version");
if (!tr.isOK()) {
System.out.println(tr.status);
throw new RuntimeException("test fails");
--- a/jdk/test/tools/launcher/SomeException.java Tue Jan 31 19:06:48 2012 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/*
- * 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.
- */
-
-/*
- *
- *
- * Used by unresolvedExceptions.sh
- */
-
-public class SomeException extends RuntimeException {
-
-}
--- a/jdk/test/tools/launcher/Test7029048.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/tools/launcher/Test7029048.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2012, 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
@@ -25,7 +25,7 @@
* @test
* @bug 7029048
* @summary Checks for LD_LIBRARY_PATH on *nixes
- * @compile -XDignore.symbol.file ExecutionEnvironment.java TestHelper.java Test7029048.java
+ * @compile -XDignore.symbol.file ExecutionEnvironment.java Test7029048.java
* @run main Test7029048
*/
@@ -42,7 +42,7 @@
import java.util.List;
import java.util.Map;
-public class Test7029048 {
+public class Test7029048 extends TestHelper {
static int passes = 0;
static int errors = 0;
@@ -62,7 +62,7 @@
private static final File dstLibDir = new File("lib");
private static final File dstLibArchDir =
- new File(dstLibDir, TestHelper.getJreArch());
+ new File(dstLibDir, getJreArch());
private static final File dstServerDir = new File(dstLibArchDir, "server");
private static final File dstServerLibjvm = new File(dstServerDir, LIBJVM);
@@ -78,8 +78,8 @@
private static final Map<String, String> env = new HashMap<>();
static {
- if (TestHelper.isDualMode) {
- dstOtherArchDir = new File(dstLibDir, TestHelper.getComplementaryJreArch());
+ if (isDualMode) {
+ dstOtherArchDir = new File(dstLibDir, getComplementaryJreArch());
dstOtherServerDir = new File(dstOtherArchDir, "server");
dstOtherServerLibjvm = new File(dstOtherServerDir, LIBJVM);
} else {
@@ -106,10 +106,10 @@
List<String> cmdsList = new ArrayList<>();
// only for a dual-mode system
- if (want64 && TestHelper.isDualMode) {
- cmdsList.add(TestHelper.java64Cmd);
+ if (want64 && isDualMode) {
+ cmdsList.add(java64Cmd);
} else {
- cmdsList.add(TestHelper.javaCmd); // a 32-bit java command for all
+ cmdsList.add(javaCmd); // a 32-bit java command for all
}
/*
@@ -127,18 +127,18 @@
cmdsList.add("-jar");
cmdsList.add(ExecutionEnvironment.testJarFile.getAbsolutePath());
String[] cmds = new String[cmdsList.size()];
- TestHelper.TestResult tr = TestHelper.doExec(env, cmdsList.toArray(cmds));
+ TestResult tr = doExec(env, cmdsList.toArray(cmds));
analyze(tr, nLLPComponents, caseID);
}
// no cross launch, ie. no change to the data model.
static void run(Map<String, String> env, int nLLPComponents, String caseID)
throws IOException {
- boolean want32 = TestHelper.is32Bit;
+ boolean want32 = is32Bit;
run(want32, null, env, nLLPComponents, caseID);
}
- static void analyze(TestHelper.TestResult tr, int nLLPComponents, String caseID) {
+ static void analyze(TestResult tr, int nLLPComponents, String caseID) {
String envValue = getValue(LD_LIBRARY_PATH, tr.testOutput);
/*
* the envValue can never be null, since the test code should always
@@ -189,12 +189,12 @@
switch (v) {
case LLP_SET_WITH_JVM:
// copy the files into the directory structures
- TestHelper.copyFile(srcLibjvmSo, dstServerLibjvm);
+ copyFile(srcLibjvmSo, dstServerLibjvm);
// does not matter if it is client or a server
- TestHelper.copyFile(srcLibjvmSo, dstClientLibjvm);
+ copyFile(srcLibjvmSo, dstClientLibjvm);
// does not matter if the arch do not match either
- if (TestHelper.isDualMode) {
- TestHelper.copyFile(srcLibjvmSo, dstOtherServerLibjvm);
+ if (isDualMode) {
+ copyFile(srcLibjvmSo, dstOtherServerLibjvm);
}
desc = "LD_LIBRARY_PATH should be set";
break;
@@ -211,7 +211,7 @@
Files.deleteIfExists(dstServerLibjvm.toPath());
}
- if (TestHelper.isDualMode) {
+ if (isDualMode) {
if (!dstOtherServerDir.exists()) {
Files.createDirectories(dstOtherServerDir.toPath());
} else {
@@ -223,7 +223,7 @@
break;
case LLP_SET_NON_EXISTENT_PATH:
if (dstLibDir.exists()) {
- TestHelper.recursiveDelete(dstLibDir);
+ recursiveDelete(dstLibDir);
}
desc = "LD_LIBRARY_PATH should not be set";
break;
@@ -245,18 +245,18 @@
env.put(LD_LIBRARY_PATH, dstClientDir.getAbsolutePath());
run(env, v.value + 1, "Case 2: " + desc);
- if (!TestHelper.isDualMode) {
+ if (!isDualMode) {
continue; // nothing more to do for Linux
}
// Tests applicable only to solaris.
// initialize test variables for dual mode operations
- final File dst32ServerDir = TestHelper.is32Bit
+ final File dst32ServerDir = is32Bit
? dstServerDir
: dstOtherServerDir;
- final File dst64ServerDir = TestHelper.is64Bit
+ final File dst64ServerDir = is64Bit
? dstServerDir
: dstOtherServerDir;
@@ -268,7 +268,7 @@
env.clear();
env.put(LD_LIBRARY_PATH_32, dst32ServerDir.getAbsolutePath());
env.put(LD_LIBRARY_PATH_64, dst64ServerDir.getAbsolutePath());
- run(TestHelper.is32Bit, null, env, v.value + 1, "Case 3: " + desc);
+ run(is32Bit, null, env, v.value + 1, "Case 3: " + desc);
/*
* Case 4: we are in dual mode environment, running 64-bit then
@@ -276,7 +276,7 @@
* java32 -d64, LLP_64 is relevant, LLP_32 is ignored
* java64 -d32, LLP_32 is relevant, LLP_64 is ignored
*/
- if (TestHelper.dualModePresent()) {
+ if (dualModePresent()) {
run(true, "-d64", env, v.value + 1, "Case 4A: " + desc);
run(false,"-d32", env, v.value + 1, "Case 4B: " + desc);
}
@@ -285,7 +285,7 @@
}
public static void main(String... args) throws Exception {
- if (TestHelper.isWindows) {
+ if (isWindows) {
System.out.println("Warning: noop on windows");
return;
}
@@ -297,13 +297,13 @@
if (errors > 0) {
throw new Exception("Test7029048: FAIL: with "
+ errors + " errors and passes " + passes);
- } else if (TestHelper.dualModePresent() && passes < 15) {
+ } else if (dualModePresent() && passes < 15) {
throw new Exception("Test7029048: FAIL: " +
"all tests did not run, expected " + 15 + " got " + passes);
- } else if (TestHelper.isSolaris && passes < 9) {
+ } else if (isSolaris && passes < 9) {
throw new Exception("Test7029048: FAIL: " +
"all tests did not run, expected " + 9 + " got " + passes);
- } else if (TestHelper.isLinux && passes < 6) {
+ } else if (isLinux && passes < 6) {
throw new Exception("Test7029048: FAIL: " +
"all tests did not run, expected " + 6 + " got " + passes);
} else {
--- a/jdk/test/tools/launcher/TestHelper.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/tools/launcher/TestHelper.java Tue Jan 31 19:08:36 2012 -0800
@@ -29,6 +29,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
+import java.nio.charset.Charset;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.Files;
import java.nio.file.FileVisitResult;
@@ -36,17 +37,22 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import static java.nio.file.StandardCopyOption.*;
+import static java.nio.file.StandardOpenOption.*;
/**
* This class provides some common utilities for the launcher tests.
*/
-public enum TestHelper {
- INSTANCE;
+public class TestHelper {
+ // commonly used jtreg constants
+ static final File TEST_CLASSES_DIR;
+ static final File TEST_SOURCES_DIR;
+
static final String JAVAHOME = System.getProperty("java.home");
static final boolean isSDK = JAVAHOME.endsWith("jre");
static final String javaCmd;
@@ -69,13 +75,30 @@
static final boolean isDualMode = isSolaris;
static final boolean isSparc = System.getProperty("os.arch").startsWith("sparc");
+ // make a note of the golden default locale
+ static final Locale DefaultLocale = Locale.getDefault();
+
static final String JAVA_FILE_EXT = ".java";
static final String CLASS_FILE_EXT = ".class";
static final String JAR_FILE_EXT = ".jar";
+ static final String JLDEBUG_KEY = "_JAVA_LAUNCHER_DEBUG";
+ static final String EXPECTED_MARKER = "TRACER_MARKER:About to EXEC";
static int testExitValue = 0;
static {
+ String tmp = System.getProperty("test.classes", null);
+ if (tmp == null) {
+ throw new Error("property test.classes not defined ??");
+ }
+ TEST_CLASSES_DIR = new File(tmp).getAbsoluteFile();
+
+ tmp = System.getProperty("test.src", null);
+ if (tmp == null) {
+ throw new Error("property test.src not defined ??");
+ }
+ TEST_SOURCES_DIR = new File(tmp).getAbsoluteFile();
+
if (is64Bit && is32Bit) {
throw new RuntimeException("arch model cannot be both 32 and 64 bit");
}
@@ -181,6 +204,19 @@
}
/*
+ * A convenience method to compile java files.
+ */
+ static void compile(String... compilerArgs) {
+ if (compiler.run(null, null, null, compilerArgs) != 0) {
+ String sarg = "";
+ for (String x : compilerArgs) {
+ sarg.concat(x + " ");
+ }
+ throw new Error("compilation failed: " + sarg);
+ }
+ }
+
+ /*
* A generic jar file creator to create a java file, compile it
* and jar it up, a specific Main-Class entry name in the
* manifest can be specified or a null to use the sole class file name
@@ -239,6 +275,11 @@
Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING);
}
+ static void createFile(File outFile, List<String> content) throws IOException {
+ Files.write(outFile.getAbsoluteFile().toPath(), content,
+ Charset.defaultCharset(), CREATE_NEW);
+ }
+
static void recursiveDelete(File target) throws IOException {
if (!target.exists()) {
return;
@@ -321,6 +362,10 @@
};
}
+ static boolean isEnglishLocale() {
+ return Locale.getDefault().getLanguage().equals("en");
+ }
+
/*
* A class to encapsulate the test results and stuff, with some ease
* of use methods to check the test results.
--- a/jdk/test/tools/launcher/UnicodeCleanup.java Tue Jan 31 19:06:48 2012 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2007, 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.
- */
-
-
-/*
- *
- *
- * Used by UnicodeTest.sh.
- *
- * Recursively deletes the given file/directory and its contents.
- * Equivalent to "rm -rf args...", but on NT-based Windows can
- * handle files with full Unicode names inside the given directories
- * while shells are generally limited to names using the system encoding.
- *
- * @author Norbert Lindenberg
- */
-
-
-
-import java.io.File;
-
-public class UnicodeCleanup {
-
- public static void main(String[] args) {
-
- for (int i = 0; i < args.length; i++) {
- delete(new File(args[i]));
- }
- }
-
- private static void delete(File file) {
- // paranoia is healthy in rm -rf
- String name = file.toString();
- if (name.equals(".") || name.equals("..") ||
- name.endsWith(File.separator + ".") ||
- name.endsWith(File.separator + "..")) {
- throw new RuntimeException("too risky to process: " + name);
- }
- if (file.isDirectory()) {
- File[] contents = file.listFiles();
- for (int i = 0; i < contents.length; i++) {
- delete(contents[i]);
- }
- }
- if (!file.delete()) {
- throw new RuntimeException("Unable to delete " + file);
- }
- }
-}
--- a/jdk/test/tools/launcher/UnicodeTest.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/tools/launcher/UnicodeTest.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2012, 2012 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
@@ -21,12 +21,18 @@
* questions.
*/
+/*
+ * @test
+ * @bug 5030265
+ * @compile -XDignore.symbol.file UnicodeTest.java
+ * @run main/othervm UnicodeTest
+ * @summary Verify that the J2RE can handle all legal Unicode characters
+ * in class names unless limited by the file system encoding
+ * or the encoding used for command line arguments.
+ * @author Norbert Lindenberg, ksrini
+ */
/*
- *
- *
- * Used by UnicodeTest.sh.
- *
* This class creates Java source files using Unicode characters
* that test the limits of what's possible
* - in situations where the platform encoding imposes limits
@@ -35,38 +41,126 @@
* (file system access in UTF-8 locales and on Windows 2000++,
* jar file contents)
*
- * @author Norbert Lindenberg
+ * This test needs to be run in othervm as the locale is reset.
*/
-
-
+import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.Locale;
-public class UnicodeTest {
+public class UnicodeTest extends TestHelper {
+ static final File UnicodeTestSrc = new File("UnicodeTest-src");
+ static final File UnicodeTestClasses = new File("UnicodeTest-classes");
+ static final String UnicodeTestJarName = "UnicodeTest" + JAR_FILE_EXT;
+ static final File UnicodeTestJar = new File(UnicodeTestJarName);
+ static final File SolarisUnicodeTestJar = new File(TEST_SOURCES_DIR,
+ UnicodeTestJarName);
+
+ /*
+ * the main method is a port of the shell based test to a java, this
+ * eliminates the need for MKS on windows, thus we can rely on consistent
+ * results regardless of the shell being used.
+ */
+ public static void main(String... args) throws Exception {
+ System.out.println("creating test source files");
+ UnicodeTestSrc.mkdirs();
+ UnicodeTestClasses.mkdirs();
+ String classname = generateSources();
+ File javaFile = new File(UnicodeTestSrc, classname + JAVA_FILE_EXT);
+ System.out.println("building test apps");
+ compile("-encoding", "UTF-8",
+ "-sourcepath", UnicodeTestSrc.getAbsolutePath(),
+ "-d", UnicodeTestClasses.getAbsolutePath(),
+ javaFile.getAbsolutePath());
+
+ createJar("-cvfm", UnicodeTestJar.getAbsolutePath(),
+ new File(UnicodeTestSrc, "MANIFEST.MF").getAbsolutePath(),
+ "-C", UnicodeTestClasses.getAbsolutePath(), ".");
+
+ if (!UnicodeTestJar.exists()) {
+ throw new Error("failed to create " + UnicodeTestJar.getAbsolutePath());
+ }
+
+ System.out.println("running test app using class file");
+ TestResult tr = doExec(javaCmd,
+ "-cp", UnicodeTestClasses.getAbsolutePath(), classname);
+ if (!tr.isOK()) {
+ System.out.println(tr);
+ throw new RuntimeException("test fails");
+ }
+
+ System.out.println("delete generated files with non-ASCII names");
+ recursiveDelete(UnicodeTestSrc);
+ recursiveDelete(UnicodeTestClasses);
+
+ /*
+ * test in whatever the default locale is
+ */
+ runJarTests();
- public static void main(String[] args) throws Exception {
+ /*
+ * if the Japanese locale is available, test in that locale as well
+ */
+ if (setLocale(Locale.JAPANESE)) {
+ runJarTests();
+ }
+
+ /*
+ * if we can switch to a C locale, then test whether jar files with
+ * non-ASCII characters in the manifest still work in this crippled
+ * environment
+ */
+ if (setLocale(Locale.ENGLISH)) {
+ runJarTests();
+ }
+ // thats it we are outta here
+ }
+
+ static void runJarTests() {
+ System.out.println("running test app using newly built jar file in " +
+ Locale.getDefault());
+ runTest(UnicodeTestJar);
+ System.out.println("running test app using jar file " +
+ "(built with Solaris UTF-8 locale) in " + Locale.getDefault());
+ runTest(SolarisUnicodeTestJar);
+ }
+
+ static void runTest(File testJar) {
+ TestResult tr = doExec(javaCmd, "-jar", testJar.getAbsolutePath());
+ if (!tr.isOK()) {
+ System.out.println(tr);
+ throw new RuntimeException("test fails");
+ }
+ }
+
+ static boolean setLocale(Locale desired) {
+ if (Locale.getDefault().equals(desired)) {
+ return true; // already set nothing more
+ }
+ for (Locale l : Locale.getAvailableLocales()) {
+ if (l == desired) {
+ Locale.setDefault(l);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ static String generateSources() throws Exception {
String commandLineClassNameSuffix = commandLineClassNameSuffix();
String commandLineClassName = "ClassA" + commandLineClassNameSuffix;
- String manifestClassName;
- if (hasUnicodeFileSystem()) {
- manifestClassName = "ClassB" + unicode;
- } else {
- manifestClassName = "ClassB" + commandLineClassNameSuffix;
- }
+ String manifestClassName = "ClassB" +
+ (hasUnicodeFileSystem() ? unicode : commandLineClassNameSuffix);
generateSource(commandLineClassName, manifestClassName);
generateSource(manifestClassName, commandLineClassName);
generateManifest(manifestClassName);
-
- System.out.println(commandLineClassName);
+ return commandLineClassName;
}
- private static final String fileSeparator = System.getProperty("file.separator");
- private static final String osName = System.getProperty("os.name");
private static final String defaultEncoding = Charset.defaultCharset().name();
// language names taken from java.util.Locale.getDisplayLanguage for the respective language
@@ -132,12 +226,7 @@
{ "tis-620", thai, null },
};
- int column;
- if (osName.startsWith("Windows")) {
- column = 2;
- } else {
- column = 1;
- }
+ int column = isWindows ? 2 : 1;
for (int i = 0; i < names.length; i++) {
if (names[i][0].equalsIgnoreCase(defaultEncoding)) {
return names[i][column];
@@ -147,17 +236,12 @@
}
private static boolean hasUnicodeFileSystem() {
- if (osName.startsWith("Windows")) {
- return ! osName.startsWith("Windows 9") &&
- ! osName.equals("Windows Me");
- } else {
- return defaultEncoding.equalsIgnoreCase("UTF-8");
- }
+ return (isWindows) ? true : defaultEncoding.equalsIgnoreCase("UTF-8");
}
private static void generateSource(String thisClass, String otherClass) throws Exception {
- String fileName = "UnicodeTest-src" + fileSeparator + thisClass + ".java";
- OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8");
+ File file = new File(UnicodeTestSrc, thisClass + JAVA_FILE_EXT);
+ OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
out.write("public class " + thisClass + " {\n");
out.write(" public static void main(String[] args) {\n");
out.write(" if (!" + otherClass + "." + otherClass.toLowerCase() + "().equals(\"" + otherClass + "\")) {\n");
@@ -172,8 +256,8 @@
}
private static void generateManifest(String mainClass) throws Exception {
- String fileName = "UnicodeTest-src" + fileSeparator + "MANIFEST.MF";
- FileOutputStream out = new FileOutputStream(fileName);
+ File file = new File(UnicodeTestSrc, "MANIFEST.MF");
+ FileOutputStream out = new FileOutputStream(file);
out.write("Manifest-Version: 1.0\n".getBytes("UTF-8"));
// Header lines are limited to 72 bytes.
// The manifest spec doesn't say we have to break at character boundaries,
--- a/jdk/test/tools/launcher/UnicodeTest.sh Tue Jan 31 19:06:48 2012 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
-# Copyright (c) 2007, 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 5030265
-# @summary Verify that the J2RE can handle all legal Unicode characters
-# in class names unless limited by the file system encoding
-# or the encoding used for command line arguments.
-# @author Norbert Lindenberg
-
-
-# Verify directory context variables are set
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
- exit 1
-fi
-
-if [ "${TESTSRC}" = "" ]
-then
- echo "TESTSRC not set. Test cannot execute. Failed."
- exit 1
-fi
-
-if [ "${TESTCLASSES}" = "" ]
-then
- echo "TESTCLASSES not set. Test cannot execute. Failed."
- exit 1
-fi
-
-JAVAC="${TESTJAVA}"/bin/javac
-JAVA="${TESTJAVA}"/bin/java
-JAR="${TESTJAVA}"/bin/jar
-
-mkdir UnicodeTest-src UnicodeTest-classes
-
-echo "creating test source files"
-"$JAVAC" -d . "${TESTSRC}"/UnicodeTest.java
-if [ "`uname -s | grep CYGWIN`" != "" ] ; then
- CLASS_NAME=`"$JAVA" UnicodeTest | sed -e 's@\\r@@g' `
-else
- CLASS_NAME=`"$JAVA" UnicodeTest`
-fi
-
-if [ "$CLASS_NAME" = "" ]
-then
- echo "CLASS_NAME not generated. Test failed."
- exit 1
-fi
-
-echo "building test apps"
-"$JAVAC" -encoding UTF-8 -sourcepath UnicodeTest-src \
- -d UnicodeTest-classes UnicodeTest-src/"${CLASS_NAME}".java || exit 1
-"$JAR" -cvfm UnicodeTest.jar UnicodeTest-src/MANIFEST.MF \
- -C UnicodeTest-classes . || exit 1
-
-echo "running test app using class file"
-"$JAVA" -classpath UnicodeTest-classes "$CLASS_NAME" || exit 1
-
-echo "delete generated files with non-ASCII names"
-# do it now because on Unix they may not be accessible when locale changes
-# do it in Java because shells on Windows can't handle full Unicode
-"$JAVAC" -d . "${TESTSRC}"/UnicodeCleanup.java || exit 1
-"$JAVA" UnicodeCleanup UnicodeTest-src UnicodeTest-classes || exit 1
-
-echo "running test app using newly built jar file"
-"$JAVA" -jar UnicodeTest.jar || exit 1
-
-echo "running test app using jar file built in Solaris UTF-8 locale"
-"$JAVA" -jar "${TESTSRC}"/UnicodeTest.jar || exit 1
-
-# if we can switch to a C locale, then test whether jar files with
-# non-ASCII characters in the manifest still work in this crippled
-# environment
-if test -n "`locale -a 2>/dev/null | grep '^C$'`"
-then
- LC_ALL=C
- export LC_ALL
-
- echo "running test app using newly built jar file in C locale"
- "$JAVA" -jar UnicodeTest.jar || exit 1
-
- echo "running test app using premade jar file in C locale"
- "$JAVA" -jar "${TESTSRC}"/UnicodeTest.jar || exit 1
-fi
-
-exit 0
-
--- a/jdk/test/tools/launcher/UnresolvedExceptions.java Tue Jan 31 19:06:48 2012 -0800
+++ b/jdk/test/tools/launcher/UnresolvedExceptions.java Tue Jan 31 19:08:36 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2012, 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
@@ -22,15 +22,39 @@
*/
/*
- *
- *
- * Used by unresolvedExceptions.sh
+ * @test
+ * @bug 4529320
+ * @compile -XDignore.symbol.file UnresolvedExceptions.java
+ * @run main UnresolvedExceptions
+ * @summary Verifying jvm won't segv if exception not available
+ * @author Joseph D. Darcy, ksrini
*/
-public class UnresolvedExceptions {
- public static void main(String[] argv) throws SomeException {
- // main is invoked from a shell so calling exit won't stop all
- // tests.
- System.exit(0);
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class UnresolvedExceptions extends TestHelper {
+
+ public static void main(String... args) throws Exception {
+ final String fname = "Foo";
+ List<String> buffer = new ArrayList<>();
+ buffer.add("public class " + fname + " {");
+ buffer.add(" public static void main(String[] argv) throws "
+ + "Foo.SomeException {");
+ buffer.add(" System.exit(0);");
+ buffer.add(" }");
+ buffer.add(" static class SomeException extends RuntimeException{}");
+ buffer.add("}");
+
+ File testJavaFile = new File("Foo" + JAVA_FILE_EXT);
+ createFile(testJavaFile, buffer);
+ compile(testJavaFile.getName());
+ TestResult tr = doExec(javaCmd, "-cp", ".", fname);
+ if (!tr.isOK()) {
+ System.out.println(tr);
+ throw new RuntimeException("java -cp ... failed");
}
}
+}
--- a/jdk/test/tools/launcher/deleteI18n.sh Tue Jan 31 19:06:48 2012 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-#
-# 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.
-#
-
-#
-#
-# This file is used by test i18nTest.sh; this file is called to use
-# shell globbing to delete Java source and class files whose names
-# include non-ASCII characters.
-
-
-# Verify directory context variables are set
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
- exit 1
-fi
-
-if [ "${TESTSRC}" = "" ]
-then
- echo "TESTSRC not set. Test cannot execute. Failed."
- exit 1
-fi
-
-
-if [ "${TESTCLASSES}" = "" ]
-then
- echo "TESTCLASSES not set. Test cannot execute. Failed."
- exit 1
-fi
-
-rm -f i18n*.java
-rm -f i18n*.class
-
-
--- a/jdk/test/tools/launcher/i18nTest.sh Tue Jan 31 19:06:48 2012 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-#
-# 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 4761384
-# @run shell deleteI18n.sh
-# @build CreatePlatformFile
-# @run main CreatePlatformFile
-# @run shell i18nTest.sh
-# @summary Test to see if class files with non-ASCII characters can be run
-# @author Joseph D. Darcy
-
-
-# Verify directory context variables are set
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
- exit 1
-fi
-
-if [ "${TESTSRC}" = "" ]
-then
- echo "TESTSRC not set. Test cannot execute. Failed."
- exit 1
-fi
-
-
-if [ "${TESTCLASSES}" = "" ]
-then
- echo "TESTCLASSES not set. Test cannot execute. Failed."
- exit 1
-fi
-
-JAVAC="${TESTJAVA}/bin/javac -d . "
-JAVA="${TESTJAVA}/bin/java -classpath . "
-
-NAME=`ls i18n*.java | sed s/.java//`
-echo $NAME
-$JAVAC ${NAME}.java
-
-RESULT=$?
-case "$RESULT" in
- 0 )
- ;;
-
- * )
- echo "Compile of i18n*.java failed."
- exit 1
-esac
-
-$JAVA ${NAME}
-RESULT=$?
-
-case "$RESULT" in
- 0 )
- exit 0;
- ;;
-
- * )
- echo "Class $NAME did not run successfully."
- exit 1
-esac
--- a/jdk/test/tools/launcher/unresolvedExceptions.sh Tue Jan 31 19:06:48 2012 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-#
-# 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 4529320
-# @build SomeException
-# @build UnresolvedExceptions
-# @clean SomeException
-# @run shell/timeout=60 unresolvedExceptions.sh
-# @summary Verifying jvm won't segv if exception not available
-# @author Joseph D. Darcy
-
-# Verify directory context variables are set
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
- exit 1
-fi
-
-if [ "${TESTSRC}" = "" ]
-then
- echo "TESTSRC not set. Test cannot execute. Failed."
- exit 1
-fi
-
-
-if [ "${TESTCLASSES}" = "" ]
-then
- echo "TESTCLASSES not set. Test cannot execute. Failed."
- exit 1
-fi
-
-JAVA="${TESTJAVA}/bin/java"
-
-$JAVA -classpath ${TESTCLASSES} UnresolvedExceptions
-RESULT=$?
-
-case "$RESULT" in
- 0 | 1 )
- exit 0;
- ;;
-
- * )
- exit 1
-esac