diff --git a/.hgtags b/.hgtags index d8826fdc86c219b32ec3dc486b0bf3987db337c8..a204003dd7fddbf8e818c3a28d400b6253600c02 100644 --- a/.hgtags +++ b/.hgtags @@ -145,3 +145,5 @@ b71d1acfae5240d8c1359443cd02b5ddb587231c jdk8-b17 664fa4fb0ee411ef048903c479f8b962fcdb2f4b jdk8-b21 dda27c73d8db4a9c7a23872b6f0c5106edcb2021 jdk8-b22 54202e0148ec7d4570cab5bc9b00d216a7677569 jdk8-b23 +34029a0c69bba882264a29fc822f8283fd15f104 jdk8-b24 +ec17fbe5b8fbc52da070eec43b4711d9354b2ab8 jdk8-b25 diff --git a/make/com/oracle/Makefile b/make/com/oracle/Makefile index c83cf8026b194109b82bcac37942e26f19ea7f1f..a657750b2c18e183be9799bfd4341a52aa651556 100644 --- a/make/com/oracle/Makefile +++ b/make/com/oracle/Makefile @@ -38,8 +38,14 @@ ifndef OPENJDK 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 diff --git a/make/com/oracle/jfr/Makefile b/make/com/oracle/jfr/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..5fd5e53039fa4258fe8832d662a3a3dd0c7d3bba --- /dev/null +++ b/make/com/oracle/jfr/Makefile @@ -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) + diff --git a/make/common/Defs.gmk b/make/common/Defs.gmk index 5f8d91171de415002cc30bca044cb2c8e3e67eba..7b8dfce9a5b56a01dbaeb9bfc4982efc194b85b9 100644 --- a/make/common/Defs.gmk +++ b/make/common/Defs.gmk @@ -425,7 +425,12 @@ vpath %.$(OBJECT_SUFFIX) $(OBJDIR) # 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) # diff --git a/make/common/Release-embedded.gmk b/make/common/Release-embedded.gmk index 655b324d26596245dd30fa994930ec116b3e67c1..d5d709fd3b4740f267746323d5d5aa6faf74da8c 100644 --- a/make/common/Release-embedded.gmk +++ b/make/common/Release-embedded.gmk @@ -189,7 +189,7 @@ reduced-headless-image-jre:: $(RT_JAR) $(RESOURCES_JAR) $(BUILD_META_INDEX) $(HL $(RM) -r $(JRE_REDUCED_HEADLESS_IMAGE_DIR)/lib/audio $(RM) -fr $(JRE_REDUCED_HEADLESS_IMAGE_DIR)/lib/applet $(RM) $(JRE_REDUCED_HEADLESS_IMAGE_DIR)/lib/$(LIBARCH)/awt_robot - $(RM) -r $(JRE_REDUCED_HEADLESS_IMAGE_DIR)/lib/$(LIBARCH)/xawt + $(RM) $(JRE_REDUCED_HEADLESS_IMAGE_DIR)/lib/$(LIBARCH)/libawt_xawt.so $(RM) -r $(JRE_REDUCED_HEADLESS_IMAGE_DIR)/lib/$(LIBARCH)/libsplashscreen.so @# Remove oblique fonts and reduce font support to LucidaSansRegular only $(RM) -fr $(JRE_REDUCED_HEADLESS_IMAGE_DIR)/lib/oblique-fonts diff --git a/make/common/Release.gmk b/make/common/Release.gmk index e6f69c3ab9d8cf93a317d11a880726ced705bf1e..5e3b033011096da76e030942394655ac71c4cf78 100644 --- a/make/common/Release.gmk +++ b/make/common/Release.gmk @@ -381,6 +381,11 @@ TOOLS = \ 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 @@ $(NOT_RT_JAR_LIST): FRC $(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 @@ $(TOTAL_JAR_FILELIST): $(JARREORDER_JARFILE) $(NOT_RT_JAR_LIST) $(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 @@ initial-image-jre-sol64:: initial-image-jre-setup # 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 @@ initial-image-jre:: initial-image-jre-setup \ $(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) \ diff --git a/make/jprt.properties b/make/jprt.properties index 9fb29299805063071f4f7a493311d8508525c5d1..9b4f1880369908f19d0dac80a74e9fb6a3164712 100644 --- a/make/jprt.properties +++ b/make/jprt.properties @@ -62,18 +62,32 @@ jprt.vm.default.test.targets= \ # 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_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_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_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 @@ jprt.vm.all.test.targets= \ # 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= \ diff --git a/make/sun/font/Makefile b/make/sun/font/Makefile index c9cf330f054197a8310b20a34f8f0c79a90d826b..1a280c77fa40a4200b72d46391349194e345c34d 100644 --- a/make/sun/font/Makefile +++ b/make/sun/font/Makefile @@ -175,7 +175,7 @@ else # PLATFORM ifeq ($(PLATFORM), solaris) # Note that on Solaris, fontmanager is built against the headless library. LDFLAGS += -L$(LIBDIR)/$(LIBARCH)/headless - OTHER_LDLIBS += -lawt -L$(LIBDIR)/$(LIBARCH)/xawt -lmawt -lc $(LIBM) $(LIBCXX) + OTHER_LDLIBS += -lawt -lawt_xawt -lc $(LIBM) $(LIBCXX) else # PLATFORM is linux OTHER_LDLIBS += -lawt $(LIBM) $(LIBCXX) ifeq ("$(CC_VER_MAJOR)", "3") diff --git a/make/sun/font/t2k/Makefile b/make/sun/font/t2k/Makefile index 09dbc3ad0104002cc11764be4cc7a297d33681e7..71903e0f774b5d184406eb630870b90bce5aa3a8 100644 --- a/make/sun/font/t2k/Makefile +++ b/make/sun/font/t2k/Makefile @@ -99,7 +99,7 @@ ifneq ($(PLATFORM), windows) endif else ifeq ($(PLATFORM), solaris) - OTHER_LDLIBS += -lawt -L$(LIBDIR)/$(LIBARCH)/xawt -lmawt + OTHER_LDLIBS += -lawt -lawt_xawt endif endif endif diff --git a/make/sun/headless/Makefile b/make/sun/headless/Makefile index 233d24fa1fdbcbb4b953ac677f4bac4d796a9ac3..2b3aae4fd76b1843ba7917f585a71d2391ad1d15 100644 --- a/make/sun/headless/Makefile +++ b/make/sun/headless/Makefile @@ -28,11 +28,9 @@ HEADLESS = true NO_ROBOT = true MOTIF_VERSION = none MOTIF_VERSION_STRING=none -LIB_LOCATION = $(LIBDIR)/$(LIBARCH)/headless PACKAGE = sun.awt -LIBRARY = mawt -LIBRARY_OUTPUT = headless +LIBRARY = awt_headless PRODUCT = sun include $(BUILDDIR)/common/Defs.gmk diff --git a/make/sun/jawt/Makefile b/make/sun/jawt/Makefile index afbce78e63801fcdbc51cd62cd4871b9e2c8e99b..82719b6fb5c7c9d9ded9f7c639707c2163e1d792 100644 --- a/make/sun/jawt/Makefile +++ b/make/sun/jawt/Makefile @@ -113,17 +113,17 @@ CPPFLAGS += -I$(OPENWIN_HOME)/include \ # ifeq ($(PLATFORM), solaris) ifndef BUILD_HEADLESS_ONLY - OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -L$(OPENWIN_LIB) -L$(LIBDIR)/$(LIBARCH)/xawt -lmawt -L/usr/openwin/sfw/lib$(ISA_DIR) -lXrender + OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -L$(OPENWIN_LIB) -lawt_xawt -L/usr/openwin/sfw/lib$(ISA_DIR) -lXrender else - OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -L$(OPENWIN_LIB) -L$(LIBDIR)/$(LIBARCH)/headless -lmawt -L/usr/openwin/sfw/lib$(ISA_DIR) -lXrender + OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -L$(OPENWIN_LIB) -lawt_headless -L/usr/openwin/sfw/lib$(ISA_DIR) -lXrender endif endif # PLATFORM ifeq ($(PLATFORM), linux) ifndef BUILD_HEADLESS_ONLY - OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -lawt -L$(LIBDIR)/$(LIBARCH)/xawt -lmawt + OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -lawt -lawt_xawt else - OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -lawt -L$(LIBDIR)/$(LIBARCH)/headless -lmawt + OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -lawt -lawt_headless CFLAGS += -DHEADLESS endif endif # PLATFORM diff --git a/make/sun/xawt/Makefile b/make/sun/xawt/Makefile index cf322d9023c8c7bac95d4b4af4bdc3031db6c042..460818a8f33fa22b7e1ad6da55ea5e5a48559553 100644 --- a/make/sun/xawt/Makefile +++ b/make/sun/xawt/Makefile @@ -25,9 +25,7 @@ BUILDDIR = ../.. PACKAGE = sun.awt.X11 -LIBRARY = mawt -LIBRARY_OUTPUT = xawt -LIB_LOCATION = $(LIBDIR)/$(LIBARCH)/xawt +LIBRARY = awt_xawt PRODUCT = sun include $(BUILDDIR)/common/Defs.gmk diff --git a/src/share/classes/com/sun/org/apache/xml/internal/security/transforms/implementations/TransformXPath2Filter.java b/src/share/classes/com/sun/org/apache/xml/internal/security/transforms/implementations/TransformXPath2Filter.java index d58453c4a0d4eb10eb7aed8cd37bc4c541517dac..2d805d13dd261c598b465236bc07967e246dd94b 100644 --- a/src/share/classes/com/sun/org/apache/xml/internal/security/transforms/implementations/TransformXPath2Filter.java +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/transforms/implementations/TransformXPath2Filter.java @@ -148,8 +148,8 @@ public class TransformXPath2Filter extends TransformSpi { } - 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 @@ public class TransformXPath2Filter extends TransformSpi { throw new TransformationException("empty", ex); } } - static Set convertNodeListToSet(List l){ - Set result=new HashSet(); - - 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 unionNodes, Set substractNodes, - Set 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 unionNodes, List substractNodes, + List intersectNodes) { + hasUnionFilter=!unionNodes.isEmpty(); + this.unionNodes=convertNodeListToSet(unionNodes); + hasSubstractFilter=!substractNodes.isEmpty(); + this.substractNodes=convertNodeListToSet(substractNodes); + hasIntersectFilter=!intersectNodes.isEmpty(); + this.intersectNodes=convertNodeListToSet(intersectNodes); } Set unionNodes; Set substractNodes; @@ -208,16 +196,16 @@ class XPath2NodeFilter implements NodeFilter { 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 @@ class XPath2NodeFilter implements NodeFilter { 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 @@ class XPath2NodeFilter implements NodeFilter { } } if (result!=-1){ - if (hasIntersectNodes) { + if (hasIntersectFilter) { if ((inIntersect==-1) || (level<=inIntersect)) { if (!inList(n, intersectNodes)) { inIntersect=-1; @@ -260,7 +248,7 @@ class XPath2NodeFilter implements NodeFilter { inUnion=-1; if (result==1) return 1; - if (hasUnionNodes) { + if (hasUnionFilter) { if ((inUnion==-1) && inList(n, unionNodes)) { inUnion=level; } @@ -280,6 +268,9 @@ class XPath2NodeFilter implements NodeFilter { * @return if rooted bye the rootnodes */ static boolean rooted(Node currentNode, Set nodeList ) { + if (nodeList.isEmpty()) { + return false; + } if (nodeList.contains(currentNode)) { return true; } @@ -302,4 +293,17 @@ class XPath2NodeFilter implements NodeFilter { static boolean inList(Node currentNode, Set nodeList ) { return nodeList.contains(currentNode); } + + private static Set convertNodeListToSet(List l){ + Set result=new HashSet(); + + 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; + } } diff --git a/src/share/classes/com/sun/rowset/CachedRowSetImpl.java b/src/share/classes/com/sun/rowset/CachedRowSetImpl.java index 9b4670556c847f37daa09ef6ab648daf3577437c..6987537f2e81d289bb2984941560fb3a59db6cec 100644 --- a/src/share/classes/com/sun/rowset/CachedRowSetImpl.java +++ b/src/share/classes/com/sun/rowset/CachedRowSetImpl.java @@ -6431,7 +6431,8 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern * @see #setKeyColumns */ public int[] getKeyColumns() throws SQLException { - return keyCols; + int[]keyColumns = this.keyCols; + return (keyColumns == null) ? null : Arrays.copyOf(keyColumns, keyColumns.length); } diff --git a/src/share/classes/com/sun/rowset/internal/BaseRow.java b/src/share/classes/com/sun/rowset/internal/BaseRow.java index 49fce7090b4579efb74fe6c5aca860f539fd0cc5..814e7456f0db39ebb990f278ad4acf8ebecd9075 100644 --- a/src/share/classes/com/sun/rowset/internal/BaseRow.java +++ b/src/share/classes/com/sun/rowset/internal/BaseRow.java @@ -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 @@ package com.sun.rowset.internal; import java.sql.*; import java.io.*; +import java.util.Arrays; /** * The abstract base class from which the classes Row @@ -65,7 +66,8 @@ public abstract class BaseRow implements Serializable, Cloneable { * original values */ public Object[] getOrigRow() { - return origVals; + Object[] origRow = this.origVals; + return (origRow == null) ? null: Arrays.copyOf(origRow, origRow.length); } /** diff --git a/src/share/classes/com/sun/rowset/internal/WebRowSetXmlWriter.java b/src/share/classes/com/sun/rowset/internal/WebRowSetXmlWriter.java index 41737b7c47cc7d8eba335fd8e041f1a3b3c04dc0..3b04d1c748c03fc69e1f2cab3b7faebc0acdbddf 100644 --- a/src/share/classes/com/sun/rowset/internal/WebRowSetXmlWriter.java +++ b/src/share/classes/com/sun/rowset/internal/WebRowSetXmlWriter.java @@ -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 @@ public class WebRowSetXmlWriter implements XmlWriter, Serializable { * for this field is set with the java.io.Writer object given * as the second argument to the writeXML method. */ - private java.io.Writer writer; + private transient java.io.Writer writer; /** * The java.util.Stack object that this WebRowSetXmlWriter @@ -205,16 +205,11 @@ public class WebRowSetXmlWriter implements XmlWriter, Serializable { //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> typeMap = caller.getTypeMap(); + if(typeMap != null) { + for(Map.Entry> mm : typeMap.entrySet()) { + propString("type", mm.getKey()); + propString("class", mm.getValue().getName()); } } endSection("map"); diff --git a/src/share/classes/java/awt/datatransfer/MimeType.java b/src/share/classes/java/awt/datatransfer/MimeType.java index f58cffb18ec6432e242b88d3923c2dcf6f650560..3ed00b75c03767e7c2c35c649e600f89eaa49813 100644 --- a/src/share/classes/java/awt/datatransfer/MimeType.java +++ b/src/share/classes/java/awt/datatransfer/MimeType.java @@ -30,6 +30,7 @@ import java.io.ObjectOutput; import java.io.ObjectInput; import java.io.IOException; import java.util.Enumeration; +import java.util.Locale; /** @@ -93,14 +94,14 @@ class MimeType implements Externalizable, Cloneable { MimeTypeParseException { // check to see if primary is valid if(isValidToken(primary)) { - primaryType = primary.toLowerCase(); + primaryType = primary.toLowerCase(Locale.ENGLISH); } else { throw new MimeTypeParseException("Primary type is invalid."); } // check to see if sub is valid if(isValidToken(sub)) { - subType = sub.toLowerCase(); + subType = sub.toLowerCase(Locale.ENGLISH); } else { throw new MimeTypeParseException("Sub type is invalid."); } @@ -158,17 +159,17 @@ MimeTypeParseException { throw new MimeTypeParseException("Unable to find a sub type."); } else if((slashIndex >= 0) && (semIndex < 0)) { // we have a primary and sub type but no parameter list - primaryType = rawdata.substring(0, -slashIndex).trim().toLowerCase(); - subType = rawdata.substring(slashIndex + -1).trim().toLowerCase(); + primaryType = rawdata.substring(0,slashIndex). + trim().toLowerCase(Locale.ENGLISH); + subType = rawdata.substring(slashIndex + 1). + trim().toLowerCase(Locale.ENGLISH); parameters = new MimeTypeParameterList(); } else if (slashIndex < semIndex) { // we have all three items in the proper sequence - primaryType = rawdata.substring(0, -slashIndex).trim().toLowerCase(); + primaryType = rawdata.substring(0, slashIndex). + trim().toLowerCase(Locale.ENGLISH); subType = rawdata.substring(slashIndex + 1, -semIndex).trim().toLowerCase(); + semIndex).trim().toLowerCase(Locale.ENGLISH); parameters = new MimeTypeParameterList(rawdata.substring(semIndex)); } else { diff --git a/src/share/classes/java/awt/event/MouseEvent.java b/src/share/classes/java/awt/event/MouseEvent.java index 440467f11f530e6f3bcc98d79343ad3cb717640f..988eda60a8bb8e70858287cc8651e48f42a26b7a 100644 --- a/src/share/classes/java/awt/event/MouseEvent.java +++ b/src/share/classes/java/awt/event/MouseEvent.java @@ -758,7 +758,6 @@ public class MouseEvent extends InputEvent { if (getModifiersEx() != 0) { //There is at least one more button in a pressed state. if (id == MouseEvent.MOUSE_RELEASED || id == MouseEvent.MOUSE_CLICKED){ - System.out.println("MEvent. CASE!"); shouldExcludeButtonFromExtModifiers = true; } } diff --git a/src/share/classes/java/beans/BeanInfo.java b/src/share/classes/java/beans/BeanInfo.java index e58426460305b874fe82c920532f7b113d13c75f..bb43f2fd4e89aa46eb0a30a3d4d76152d59ddbcc 100644 --- a/src/share/classes/java/beans/BeanInfo.java +++ b/src/share/classes/java/beans/BeanInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1999, 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 @@ -25,134 +25,134 @@ package java.beans; +import java.awt.Image; + /** - * A bean implementor who wishes to provide explicit information about - * their bean may provide a BeanInfo class that implements this BeanInfo - * interface and provides explicit information about the methods, - * properties, events, etc, of their bean. + * Use the {@code BeanInfo} interface + * to create a {@code BeanInfo} class + * and provide explicit information about the methods, + * properties, events, and other features of your beans. *

- * A bean implementor doesn't need to provide a complete set of - * explicit information. You can pick and choose which information - * you want to provide and the rest will be obtained by automatic - * analysis using low-level reflection of the bean classes' methods + * When developing your bean, you can implement + * the bean features required for your application task + * omitting the rest of the {@code BeanInfo} features. + * They will be obtained through the automatic analysis + * by using the low-level reflection of the bean methods * and applying standard design patterns. + * You have an opportunity to provide additional bean information + * through various descriptor classes. + *

+ * See the {@link SimpleBeanInfo} class that is + * a convenient basic class for {@code BeanInfo} classes. + * You can override the methods and properties of + * the {@code SimpleBeanInfo} class to define specific information. *

- * You get the opportunity to provide lots and lots of different - * information as part of the various XyZDescriptor classes. But - * don't panic, you only really need to provide the minimal core - * information required by the various constructors. - *

- * See also the SimpleBeanInfo class which provides a convenient - * "noop" base class for BeanInfo classes, which you can override - * for those specific places where you want to return explicit info. - *

- * To learn about all the behaviour of a bean see the Introspector class. + * See also the {@link Introspector} class to learn more about bean behavior. */ - public interface BeanInfo { /** - * Gets the beans BeanDescriptor. + * Returns the bean descriptor + * that provides overall information about the bean, + * such as its display name or its customizer. * - * @return A BeanDescriptor providing overall information about - * the bean, such as its displayName, its customizer, etc. May - * return null if the information should be obtained by automatic - * analysis. + * @return a {@link BeanDescriptor} object, + * or {@code null} if the information is to + * be obtained through the automatic analysis */ BeanDescriptor getBeanDescriptor(); /** - * Gets the beans EventSetDescriptors. + * Returns the event descriptors of the bean + * that define the types of events fired by this bean. * - * @return An array of EventSetDescriptors describing the kinds of - * events fired by this bean. May return null if the information - * should be obtained by automatic analysis. + * @return an array of {@link EventSetDescriptor} objects, + * or {@code null} if the information is to + * be obtained through the automatic analysis */ EventSetDescriptor[] getEventSetDescriptors(); /** - * A bean may have a "default" event that is the event that will - * mostly commonly be used by humans when using the bean. - * @return Index of default event in the EventSetDescriptor array - * returned by getEventSetDescriptors. - *

Returns -1 if there is no default event. + * A bean may have a default event typically applied when this bean is used. + * + * @return index of the default event in the {@code EventSetDescriptor} array + * returned by the {@code getEventSetDescriptors} method, + * or -1 if there is no default event */ int getDefaultEventIndex(); /** * Returns descriptors for all properties of the bean. - * May return {@code null} if the information - * should be obtained by automatic analysis. *

* If a property is indexed, then its entry in the result array - * will belong to the {@link IndexedPropertyDescriptor} subclass + * belongs to the {@link IndexedPropertyDescriptor} subclass * of the {@link PropertyDescriptor} class. * A client of the {@code getPropertyDescriptors} method - * can use "{@code instanceof}" to check + * can use the {@code instanceof} operator to check * whether a given {@code PropertyDescriptor} * is an {@code IndexedPropertyDescriptor}. * - * @return an array of {@code PropertyDescriptor}s - * describing all properties supported by the bean - * or {@code null} + * @return an array of {@code PropertyDescriptor} objects, + * or {@code null} if the information is to + * be obtained through the automatic analysis */ PropertyDescriptor[] getPropertyDescriptors(); /** - * A bean may have a "default" property that is the property that will - * mostly commonly be initially chosen for update by human's who are - * customizing the bean. - * @return Index of default property in the PropertyDescriptor array - * returned by getPropertyDescriptors. - *

Returns -1 if there is no default property. + * A bean may have a default property commonly updated when this bean is customized. + * + * @return index of the default property in the {@code PropertyDescriptor} array + * returned by the {@code getPropertyDescriptors} method, + * or -1 if there is no default property */ int getDefaultPropertyIndex(); /** - * Gets the beans MethodDescriptors. + * Returns the method descriptors of the bean + * that define the externally visible methods supported by this bean. * - * @return An array of MethodDescriptors describing the externally - * visible methods supported by this bean. May return null if - * the information should be obtained by automatic analysis. + * @return an array of {@link MethodDescriptor} objects, + * or {@code null} if the information is to + * be obtained through the automatic analysis */ MethodDescriptor[] getMethodDescriptors(); /** - * This method allows a BeanInfo object to return an arbitrary collection - * of other BeanInfo objects that provide additional information on the - * current bean. - *

- * If there are conflicts or overlaps between the information provided - * by different BeanInfo objects, then the current BeanInfo takes precedence - * over the getAdditionalBeanInfo objects, and later elements in the array - * take precedence over earlier ones. + * This method enables the current {@code BeanInfo} object + * to return an arbitrary collection of other {@code BeanInfo} objects + * that provide additional information about the current bean. + *

+ * If there are conflicts or overlaps between the information + * provided by different {@code BeanInfo} objects, + * the current {@code BeanInfo} object takes priority + * over the additional {@code BeanInfo} objects. + * Array elements with higher indices take priority + * over the elements with lower indices. * - * @return an array of BeanInfo objects. May return null. + * @return an array of {@code BeanInfo} objects, + * or {@code null} if there are no additional {@code BeanInfo} objects */ BeanInfo[] getAdditionalBeanInfo(); /** - * This method returns an image object that can be used to - * represent the bean in toolboxes, toolbars, etc. Icon images - * will typically be GIFs, but may in future include other formats. - *

- * Beans aren't required to provide icons and may return null from - * this method. + * Returns an image that can be used to represent the bean in toolboxes or toolbars. *

- * There are four possible flavors of icons (16x16 color, - * 32x32 color, 16x16 mono, 32x32 mono). If a bean choses to only - * support a single icon we recommend supporting 16x16 color. - *

- * We recommend that icons have a "transparent" background - * so they can be rendered onto an existing background. + * There are four possible types of icons: + * 16 x 16 color, 32 x 32 color, 16 x 16 mono, and 32 x 32 mono. + * If you implement a bean so that it supports a single icon, + * it is recommended to use 16 x 16 color. + * Another recommendation is to set a transparent background for the icons. + * + * @param iconKind the kind of icon requested + * @return an image object representing the requested icon, + * or {@code null} if no suitable icon is available * - * @param iconKind The kind of icon requested. This should be - * one of the constant values ICON_COLOR_16x16, ICON_COLOR_32x32, - * ICON_MONO_16x16, or ICON_MONO_32x32. - * @return An image object representing the requested icon. May - * return null if no suitable icon is available. + * @see #ICON_COLOR_16x16 + * @see #ICON_COLOR_32x32 + * @see #ICON_MONO_16x16 + * @see #ICON_MONO_32x32 */ - java.awt.Image getIcon(int iconKind); + Image getIcon(int iconKind); /** * Constant to indicate a 16 x 16 color icon. diff --git a/src/share/classes/java/beans/Introspector.java b/src/share/classes/java/beans/Introspector.java index 57342081059a5186bb9821543e40343ff00b9e77..476adf079aad94e620d59332a993b15408234466 100644 --- a/src/share/classes/java/beans/Introspector.java +++ b/src/share/classes/java/beans/Introspector.java @@ -473,7 +473,7 @@ public class Introspector { // Now analyze each method. for (int i = 0; i < methodList.length; i++) { Method method = methodList[i]; - if (method == null || method.isSynthetic()) { + if (method == null) { continue; } // skip static methods. diff --git a/src/share/classes/java/beans/PropertyDescriptor.java b/src/share/classes/java/beans/PropertyDescriptor.java index 6abe8a0bdc439435a1ef7fa864333df0fb07b276..5d548309b743027d393a136295a633f73ffd2948 100644 --- a/src/share/classes/java/beans/PropertyDescriptor.java +++ b/src/share/classes/java/beans/PropertyDescriptor.java @@ -559,7 +559,7 @@ public class PropertyDescriptor extends FeatureDescriptor { // Normally give priority to y's readMethod. try { - if (yr != null && yr.getDeclaringClass() == getClass0()) { + if (isAssignable(xr, yr)) { setReadMethod(yr); } else { setReadMethod(xr); @@ -713,4 +713,37 @@ public class PropertyDescriptor extends FeatureDescriptor { appendTo(sb, "readMethod", this.readMethodRef); appendTo(sb, "writeMethod", this.writeMethodRef); } + + private boolean isAssignable(Method m1, Method m2) { + if (m1 == null) { + return true; // choose second method + } + if (m2 == null) { + return false; // choose first method + } + if (!m1.getName().equals(m2.getName())) { + return true; // choose second method by default + } + Class type1 = m1.getDeclaringClass(); + Class type2 = m2.getDeclaringClass(); + if (!type1.isAssignableFrom(type2)) { + return false; // choose first method: it declared later + } + type1 = getReturnType(getClass0(), m1); + type2 = getReturnType(getClass0(), m2); + if (!type1.isAssignableFrom(type2)) { + return false; // choose first method: it overrides return type + } + Class[] args1 = getParameterTypes(getClass0(), m1); + Class[] args2 = getParameterTypes(getClass0(), m2); + if (args1.length != args2.length) { + return true; // choose second method by default + } + for (int i = 0; i < args1.length; i++) { + if (!args1[i].isAssignableFrom(args2[i])) { + return false; // choose first method: it overrides parameter + } + } + return true; // choose second method + } } diff --git a/src/share/classes/java/io/DataInput.java b/src/share/classes/java/io/DataInput.java index e4b7e83ff5aa3126835c8057d669587d68a34925..1480c9f0485b37aebc4908f07de92be738e08dd5 100644 --- a/src/share/classes/java/io/DataInput.java +++ b/src/share/classes/java/io/DataInput.java @@ -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 DataInput 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 String + * facility for reconstructing a {@code String} * from data in * modified UTF-8 * format. @@ -39,12 +39,12 @@ package java.io; * 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 EOFException - * (which is a kind of IOException) + * 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 IOException - * other than EOFException is - * thrown. In particular, an IOException + * 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 @@ package java.io; * Note that in the following tables, the most significant bit appears in the * far left-hand column. *

- * All characters in the range '\u0001' to - * '\u007F' are represented by a single byte: + * All characters in the range {@code '\u005Cu0001'} to + * {@code '\u005Cu007F'} are represented by a single byte: * *

* * *

- * The null character '\u0000' and characters in the - * range '\u0080' to '\u07FF' are + * The null character {@code '\u005Cu0000'} and characters in the + * range {@code '\u005Cu0080'} to {@code '\u005Cu07FF'} are * represented by a pair of bytes: * *

@@ -123,8 +123,8 @@ package java.io; *
* *
- * char values in the range '\u0800' to - * '\uFFFF' are represented by three bytes: + * {@code char} values in the range {@code '\u005Cu0800'} to + * {@code '\u005CuFFFF'} are represented by three bytes: * *
*
- *
  • The null byte '\u0000' is encoded in 2-byte format + *
  • The null byte {@code '\u005Cu0000'} is encoded in 2-byte format * rather than 1-byte, so that the encoded strings never have * embedded nulls. *
  • Only the 1-byte, 2-byte, and 3-byte formats are used. @@ -195,36 +195,36 @@ interface DataInput { /** * Reads some bytes from an input * stream and stores them into the buffer - * array b. The number of bytes + * array {@code b}. The number of bytes * read is equal - * to the length of b. + * to the length of {@code b}. *

    * This method blocks until one of the * following conditions occurs:

    *

      - *
    • b.length + *
    • {@code b.length} * bytes of input data are available, in which * case a normal return is made. * *
    • End of - * file is detected, in which case an EOFException + * file is detected, in which case an {@code EOFException} * is thrown. * *
    • An I/O error occurs, in - * which case an IOException other - * than EOFException is thrown. + * which case an {@code IOException} other + * than {@code EOFException} is thrown. *
    *

    - * If b is null, - * a NullPointerException is thrown. - * If b.length 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 b[0], - * the next one into b[1], 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 b 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 @@ interface DataInput { /** * - * Reads len + * Reads {@code len} * bytes from * an input stream. *

    @@ -244,32 +244,32 @@ interface DataInput { * blocks until one of the following conditions * occurs:

    *

      - *
    • len bytes + *
    • {@code len} bytes * of input data are available, in which case * a normal return is made. * *
    • End of file - * is detected, in which case an EOFException + * is detected, in which case an {@code EOFException} * is thrown. * *
    • An I/O error occurs, in - * which case an IOException other - * than EOFException is thrown. + * which case an {@code IOException} other + * than {@code EOFException} is thrown. *
    *

    - * If b is null, - * a NullPointerException is thrown. - * If off is negative, or len - * is negative, or off+len is - * greater than the length of the array b, - * then an IndexOutOfBoundsException + * 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 len is zero, + * If {@code len} is zero, * then no bytes are read. Otherwise, the first - * byte read is stored into element b[off], - * the next one into b[off+1], + * 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 len. + * 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 @@ interface DataInput { /** * Makes an attempt to skip over - * n bytes + * {@code n} bytes * of data from the input * stream, discarding the skipped bytes. However, * it may skip @@ -290,10 +290,10 @@ interface DataInput { * bytes, possibly zero. This may result from * any of a * number of conditions; reaching - * end of file before n bytes + * end of file before {@code n} bytes * have been skipped is * only one possibility. - * This method never throws an EOFException. + * This method never throws an {@code EOFException}. * The actual * number of bytes skipped is returned. * @@ -305,13 +305,13 @@ interface DataInput { /** * Reads one input byte and returns - * true if that byte is nonzero, - * false 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 writeBoolean - * method of interface DataOutput. + * the byte written by the {@code writeBoolean} + * method of interface {@code DataOutput}. * - * @return the boolean 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 @@ interface DataInput { /** * Reads and returns one input byte. * The byte is treated as a signed value in - * the range -128 through 127, + * the range {@code -128} through {@code 127}, * inclusive. * This method is suitable for - * reading the byte written by the writeByte - * method of interface DataOutput. + * 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 @@ interface DataInput { /** * Reads one input byte, zero-extends - * it to type int, and returns + * it to type {@code int}, and returns * the result, which is therefore in the range - * 0 - * through 255. + * {@code 0} + * through {@code 255}. * This method is suitable for reading - * the byte written by the writeByte - * method of interface DataOutput - * if the argument to writeByte + * 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 - * 0 through 255. + * {@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 @@ interface DataInput { /** * Reads two input bytes and returns - * a short value. Let a - * be the first byte read and b + * 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 @@ interface DataInput { * * This method * is suitable for reading the bytes written - * by the writeShort method of - * interface DataOutput. + * 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 @@ interface DataInput { /** * Reads two input bytes and returns - * an int value in the range 0 - * through 65535. Let a + * an {@code int} value in the range {@code 0} + * through {@code 65535}. Let {@code a} * be the first byte read and - * b + * {@code b} * be the second byte. The value returned is: *

    (((a & 0xff) << 8) | (b & 0xff))
          * 
    * This method is suitable for reading the bytes - * written by the writeShort method - * of interface DataOutput if - * the argument to writeShort + * 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 - * 0 through 65535. + * {@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 @@ interface DataInput { int readUnsignedShort() throws IOException; /** - * Reads two input bytes and returns a char value. - * Let a - * be the first byte read and b + * 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: *

    (char)((a << 8) | (b & 0xff))
          * 
    * This method * is suitable for reading bytes written by - * the writeChar method of interface - * DataOutput. + * the {@code writeChar} method of interface + * {@code DataOutput}. * - * @return the char 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 @@ interface DataInput { /** * Reads four input bytes and returns an - * int value. Let a-d + * {@code int} value. Let {@code a-d} * be the first through fourth bytes read. The value returned is: - *

    -     * 
    +     * 

    
          * (((a & 0xff) << 24) | ((b & 0xff) << 16) |
          *  ((c & 0xff) << 8) | (d & 0xff))
          * 
    * This method is suitable - * for reading bytes written by the writeInt - * method of interface DataOutput. + * for reading bytes written by the {@code writeInt} + * method of interface {@code DataOutput}. * - * @return the int 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 @@ interface DataInput { /** * Reads eight input bytes and returns - * a long value. Let a-h + * a {@code long} value. Let {@code a-h} * be the first through eighth bytes read. * The value returned is: - *

     
    +     * 

    
          * (((long)(a & 0xff) << 56) |
          *  ((long)(b & 0xff) << 48) |
          *  ((long)(c & 0xff) << 40) |
    @@ -455,10 +454,10 @@ interface DataInput {
          * 
    *

    * This method is suitable - * for reading bytes written by the writeLong - * method of interface DataOutput. + * for reading bytes written by the {@code writeLong} + * method of interface {@code DataOutput}. * - * @return the long 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 @@ interface DataInput { /** * Reads four input bytes and returns - * a float value. It does this - * by first constructing an int + * a {@code float} value. It does this + * by first constructing an {@code int} * value in exactly the manner - * of the readInt - * method, then converting this int - * value to a float in - * exactly the manner of the method Float.intBitsToFloat. + * 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 writeFloat - * method of interface DataOutput. + * bytes written by the {@code writeFloat} + * method of interface {@code DataOutput}. * - * @return the float 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 @@ interface DataInput { /** * Reads eight input bytes and returns - * a double value. It does this - * by first constructing a long + * a {@code double} value. It does this + * by first constructing a {@code long} * value in exactly the manner - * of the readlong - * method, then converting this long - * value to a double in exactly - * the manner of the method Double.longBitsToDouble. + * 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 writeDouble - * method of interface DataOutput. + * bytes written by the {@code writeDouble} + * method of interface {@code DataOutput}. * - * @return the double 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 @@ interface DataInput { * until it encounters a line terminator or * end of * file; the characters read are then - * returned as a String. Note + * returned as a {@code String}. Note * that because this * method processes bytes, * it does not support input of the full Unicode * character set. *

    * If end of file is encountered - * before even one byte can be read, then null + * before even one byte can be read, then {@code null} * is returned. Otherwise, each byte that is - * read is converted to type char - * by zero-extension. If the character '\n' + * 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 '\r' + * ceases. If the character {@code '\r'} * is encountered, it is discarded and, if * the following byte converts to the - * character '\n', 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 '\n' and - * '\r' is encountered, reading - * ceases. Once reading has ceased, a String + * 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 \u0100, - * that is, (char)256. + * will have a value less than {@code \u005Cu0100}, + * that is, {@code (char)256}. * * @return the next line of text from the input stream, - * or null 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 @@ interface DataInput { * Reads in a string that has been encoded using a * modified UTF-8 * format. - * The general contract of readUTF + * 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 String. + * is then returned as a {@code String}. *

    * First, two bytes are read and used to * construct an unsigned 16-bit integer in - * exactly the manner of the readUnsignedShort + * exactly the manner of the {@code readUnsignedShort} * method . This integer value is called the * UTF length and specifies the number * of additional bytes to be read. These bytes @@ -570,58 +569,58 @@ interface DataInput { * next group. *

    * If the first byte of a group - * matches the bit pattern 0xxxxxxx - * (where x means "may be 0 - * or 1"), 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. *

    * If the first byte - * of a group matches the bit pattern 110xxxxx, - * then the group consists of that byte a - * and a second byte b. If there - * is no byte b (because byte - * a was the last of the bytes - * to be read), or if byte b does - * not match the bit pattern 10xxxxxx, - * then a UTFDataFormatException + * 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:

    *

    (char)(((a& 0x1F) << 6) | (b & 0x3F))
          * 
    * If the first byte of a group - * matches the bit pattern 1110xxxx, - * then the group consists of that byte a - * and two more bytes b and c. - * If there is no byte c (because - * byte a 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 b or byte c - * does not match the bit pattern 10xxxxxx, - * then a UTFDataFormatException + * 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:

    *

    
          * (char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F))
          * 
    * If the first byte of a group matches the - * pattern 1111xxxx or the pattern - * 10xxxxxx, then a UTFDataFormatException + * pattern {@code 1111xxxx} or the pattern + * {@code 10xxxxxx}, then a {@code UTFDataFormatException} * is thrown. *

    * If end of file is encountered * at any time during this entire process, - * then an EOFException is thrown. + * then an {@code EOFException} is thrown. *

    * 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 String, + * the input stream, to form a {@code String}, * which is returned. *

    - * The writeUTF - * method of interface DataOutput + * 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. diff --git a/src/share/classes/java/io/LineNumberInputStream.java b/src/share/classes/java/io/LineNumberInputStream.java index 11cfdf8b8b9cf0dce2f40ebed416e5c19ed333e2..1f37a98e92809f45f0c84e5549bc0504dad1bcc5 100644 --- a/src/share/classes/java/io/LineNumberInputStream.java +++ b/src/share/classes/java/io/LineNumberInputStream.java @@ -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 @@ package java.io; * functionality of keeping track of the current line number. *

    * A line is a sequence of bytes ending with a carriage return - * character ('\r'), a newline character - * ('\n'), 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. *

    - * The line number begins at 0, and is incremented by - * 1 when a read 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 @@ class LineNumberInputStream extends FilterInputStream { /** * Reads the next byte of data from this input stream. The value - * byte is returned as an int in the range - * 0 to 255. 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 - * -1 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. *

    - * The read method of - * LineNumberInputStream calls the read + * 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 -1 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 @@ class LineNumberInputStream extends FilterInputStream { } /** - * Reads up to len 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. *

    - * The read method of - * LineNumberInputStream repeatedly calls the - * read 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 - * -1 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 @@ class LineNumberInputStream extends FilterInputStream { } /** - * Skips over and discards n bytes of data from this - * input stream. The skip 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 0. The actual number of bytes skipped is - * returned. If n 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. *

    - * The skip method of LineNumberInputStream creates + * The {@code skip} method of {@code LineNumberInputStream} creates * a byte array and then repeatedly reads into it until - * n 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 @@ class LineNumberInputStream extends FilterInputStream { *

    * Note that if the underlying input stream is able to supply * k input characters without blocking, the - * LineNumberInputStream can guarantee only to provide + * {@code LineNumberInputStream} can guarantee only to provide * k/2 characters without blocking, because the * k characters from the underlying input stream might - * consist of k/2 pairs of '\r' and - * '\n', which are converted to just - * k/2 '\n' characters. + * consist of k/2 pairs of {@code '\u005Cr'} and + * {@code '\u005Cn'}, which are converted to just + * k/2 {@code '\u005Cn'} characters. * * @return the number of bytes that can be read from this input stream * without blocking. @@ -243,12 +243,12 @@ class LineNumberInputStream extends FilterInputStream { /** * Marks the current position in this input stream. A subsequent - * call to the reset 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. *

    - * The mark method of - * LineNumberInputStream remembers the current line - * number in a private variable, and then calls the mark + * 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 @@ class LineNumberInputStream extends FilterInputStream { /** * Repositions this stream to the position at the time the - * mark method was last called on this input stream. + * {@code mark} method was last called on this input stream. *

    - * The reset method of - * LineNumberInputStream resets the line number to be - * the line number at the time the mark method was - * called, and then calls the reset 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. *

    * Stream marks are intended to be used in diff --git a/src/share/classes/java/io/RandomAccessFile.java b/src/share/classes/java/io/RandomAccessFile.java index 893fc94ab63b38a4cb89726982edd5a542212c2b..cf1e5c7cef46337826dae10e05aed0ba601908a7 100644 --- a/src/share/classes/java/io/RandomAccessFile.java +++ b/src/share/classes/java/io/RandomAccessFile.java @@ -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 @@ import sun.nio.ch.FileChannelImpl; * 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 - * getFilePointer method and set by the seek + * {@code getFilePointer} method and set by the {@code seek} * method. *

    * 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 EOFException (which is a kind of - * IOException) is thrown. If any byte cannot be read for - * any reason other than end-of-file, an IOException other - * than EOFException is thrown. In particular, an - * IOException 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * href="#mode">RandomAccessFile(File,String) constructor. * *

    - * If there is a security manager, its checkRead method - * is called with the name 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 - * checkWrite method - * is also called with the name 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * 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 - * checkRead 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 - * checkWrite 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * 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. * - *

    If there is a security manager, its checkRead method is - * called with the pathname of the file argument as its + *

    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 checkWrite 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * 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 - * checkRead 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 - * checkWrite 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * object associated with this file. * *

    The {@link java.nio.channels.FileChannel#position() - * position} 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { /** * Opens a file and returns the file descriptor. The file is - * opened in read-write mode if the O_RDWR bit in mode + * 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 name 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { /** * Reads a byte of data from this file. The byte is returned as an - * integer in the range 0 to 255 (0x00-0x0ff). This + * integer in the range 0 to 255 ({@code 0x00-0x0ff}). This * method blocks if no input is yet available. *

    - * Although RandomAccessFile is not a subclass of - * InputStream, 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 - * InputStream. + * {@code InputStream}. * - * @return the next byte of data, or -1 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { private native int readBytes(byte b[], int off, int len) throws IOException; /** - * Reads up to len 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. *

    - * Although RandomAccessFile is not a subclass of - * InputStream, 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 - * InputStream. + * {@code InputStream}. * * @param b the buffer into which the data is read. - * @param off the start offset in array b + * @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 - * -1 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 b is null. - * @exception IndexOutOfBoundsException If off is negative, - * len is negative, or len is greater than - * b.length - off + * @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 b.length 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. *

    - * Although RandomAccessFile is not a subclass of - * InputStream, 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 - * InputStream. + * {@code InputStream}. * * @param b the buffer into which the data is read. * @return the total number of bytes read into the buffer, or - * -1 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 b is null. + * @exception NullPointerException If {@code b} is {@code null}. */ public int read(byte b[]) throws IOException { return readBytes(b, 0, b.length); } /** - * Reads b.length 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Reads exactly len 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Attempts to skip over n bytes of input discarding the + * Attempts to skip over {@code n} bytes of input discarding the * skipped bytes. *

    * * 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 n bytes have been skipped is only one - * possibility. This method never throws an EOFException. - * The actual number of bytes skipped is returned. If n + * 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * Writes the specified byte to this file. The write starts at * the current file pointer. * - * @param b the byte 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { private native void writeBytes(byte b[], int off, int len) throws IOException; /** - * Writes b.length 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Writes len bytes from the specified byte array - * starting at offset off 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * @param pos the offset position, measured in bytes from the * beginning of the file, at which to set the file * pointer. - * @exception IOException if pos is less than - * 0 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * Sets the length of this file. * *

    If the present length of the file as returned by the - * length method is greater than the newLength + * {@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 getFilePointer method is greater - * than newLength then after this method returns the offset - * will be equal to newLength. + * 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}. * *

    If the present length of the file as returned by the - * length method is smaller than the newLength + * {@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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { // /** - * Reads a boolean 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 0 represents - * false. Any other value represents true. + * 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 boolean 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { /** * 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 b, where + * If the byte read is {@code b}, where * 0 <= b <= 255, * then the result is: *

    @@ -616,7 +616,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
          * is detected, or an exception is thrown.
          *
          * @return     the next byte of this file as a signed eight-bit
    -     *             byte.
    +     *             {@code byte}.
          * @exception  EOFException  if this file has reached the end.
          * @exception  IOException   if an I/O error occurs.
          */
    @@ -651,8 +651,8 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
          * 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
    -     * b1 and b2, where each of the two values is
    -     * between 0 and 255, 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:
          * 
          *     (short)((b1 << 8) | b2)
    @@ -679,7 +679,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
          * 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
    -     * b1 and b2, where
    +     * {@code b1} and {@code b2}, where
          * 0 <= b1, b2 <= 255,
          * then the result is equal to:
          * 
    @@ -707,7 +707,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
          * 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
    -     * b1 and b2, where
    +     * {@code b1} and {@code b2}, where
          * 0 <= b1, b2 <= 255,
          * then the result is equal to:
          * 
    @@ -718,7 +718,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
          * stream is detected, or an exception is thrown.
          *
          * @return     the next two bytes of this file, interpreted as a
    -     *                  char.
    +     *                  {@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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
         /**
          * 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 b1,
    -     * b2, b3, and b4, where
    +     * If the bytes read, in order, are {@code b1},
    +     * {@code b2}, {@code b3}, and {@code b4}, where
          * 0 <= b1, b2, b3, b4 <= 255,
          * then the result is equal to:
          * 
    @@ -746,7 +746,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
          * stream is detected, or an exception is thrown.
          *
          * @return     the next four bytes of this file, interpreted as an
    -     *             int.
    +     *             {@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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
          * 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
    -     * b1, b2, b3,
    -     * b4, b5, b6,
    -     * b7, and b8, where:
    +     * {@code b1}, {@code b2}, {@code b3},
    +     * {@code b4}, {@code b5}, {@code b6},
    +     * {@code b7}, and {@code b8,} where:
          * 
          *     0 <= b1, b2, b3, b4, b5, b6, b7, b8 <=255,
          * 
    @@ -784,7 +784,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * stream is detected, or an exception is thrown. * * @return the next eight bytes of this file, interpreted as a - * long. + * {@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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Reads a float from this file. This method reads an - * int value, starting at the current file pointer, - * as if by the readInt method - * and then converts that int to a float - * using the intBitsToFloat method in class - * Float. + * 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}. *

    * 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 - * float. + * {@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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Reads a double from this file. This method reads a - * long value, starting at the current file pointer, - * as if by the readLong method - * and then converts that long to a double - * using the longBitsToDouble method in - * class Double. + * 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}. *

    * 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 - * double. + * {@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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * therefore, support the full Unicode character set. * *

    A line of text is terminated by a carriage-return character - * ('\r'), a newline character ('\n'), 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { *

    * The first two bytes are read, starting from the current file * pointer, as if by - * readUnsignedShort. 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Writes a boolean to the file as a one-byte value. The - * value true is written out as the value - * (byte)1; the value false is written out - * as the value (byte)0. 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 boolean 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Writes a byte 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 byte 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Writes a short 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 short 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Writes a char 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 char 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Writes an int 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 int 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Writes a long 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 long 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Converts the float argument to an int using the - * floatToIntBits method in class Float, - * and then writes that int 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 float 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { } /** - * Converts the double argument to a long using the - * doubleToLongBits method in class Double, - * and then writes that long 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 double 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { /** * Writes a string to the file as a sequence of characters. Each * character is written to the data output stream as if by the - * writeChar method. The write starts at the current + * {@code writeChar} method. The write starts at the current * position of the file pointer. * - * @param s a String 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 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { *

    * First, two bytes are written to the file, starting at the * current file pointer, as if by the - * writeShort 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 diff --git a/src/share/classes/java/io/StreamTokenizer.java b/src/share/classes/java/io/StreamTokenizer.java index 81ec5d5d221a68fee0c8707ec1adfaec621bdc68..3c7c7cc214c3fc2d42419bb96638e9561c12089b 100644 --- a/src/share/classes/java/io/StreamTokenizer.java +++ b/src/share/classes/java/io/StreamTokenizer.java @@ -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 @@ package java.io; import java.util.Arrays; /** - * The StreamTokenizer 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 @@ import java.util.Arrays; * strings, and various comment styles. *

    * Each byte read from the input stream is regarded as a character - * in the range '\u0000' through '\u00FF'. + * in the range {@code '\u005Cu0000'} through {@code '\u005Cu00FF'}. * The character value is used to look up five possible attributes of * the character: white space, alphabetic, * numeric, string quote, and comment character. @@ -53,8 +53,8 @@ import java.util.Arrays; *

    * A typical application first constructs an instance of this class, * sets up the syntax tables, and then repeatedly loops calling the - * nextToken method in each iteration of the loop until - * it returns the value TT_EOF. + * {@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 @@ public class StreamTokenizer { private static final byte CT_COMMENT = 16; /** - * After a call to the nextToken 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: *

      - *
    • TT_WORD indicates that the token is a word. - *
    • TT_NUMBER indicates that the token is a number. - *
    • TT_EOL indicates that the end of line has been read. + *
    • {@code TT_WORD} indicates that the token is a word. + *
    • {@code TT_NUMBER} indicates that the token is a number. + *
    • {@code TT_EOL} indicates that the end of line has been read. * The field can only have this value if the - * eolIsSignificant method has been called with the - * argument true. - *
    • TT_EOF indicates that the end of the input stream + * {@code eolIsSignificant} method has been called with the + * argument {@code true}. + *
    • {@code TT_EOF} indicates that the end of the input stream * has been reached. *
    *

    @@ -160,8 +160,8 @@ public class StreamTokenizer { * the string. *

    * The current token is a word when the value of the - * ttype field is TT_WORD. The current token is - * a quoted string token when the value of the ttype 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. *

    * The initial value of this field is null. @@ -175,7 +175,7 @@ public class StreamTokenizer { /** * 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 ttype field is TT_NUMBER. + * the {@code ttype} field is {@code TT_NUMBER}. *

    * The initial value of this field is 0.0. * @@ -201,14 +201,14 @@ public class StreamTokenizer { * stream. The stream tokenizer is initialized to the following * default state: *

      - *
    • All byte values 'A' through 'Z', - * 'a' through 'z', and - * '\u00A0' through '\u00FF' are + *
    • All byte values {@code 'A'} through {@code 'Z'}, + * {@code 'a'} through {@code 'z'}, and + * {@code '\u005Cu00A0'} through {@code '\u005Cu00FF'} are * considered to be alphabetic. - *
    • All byte values '\u0000' through - * '\u0020' are considered to be white space. - *
    • '/' is a comment character. - *
    • Single quote '\'' and double quote '"' + *
    • All byte values {@code '\u005Cu0000'} through + * {@code '\u005Cu0020'} are considered to be white space. + *
    • {@code '/'} is a comment character. + *
    • Single quote {@code '\u005C''} and double quote {@code '"'} * are string quote characters. *
    • Numbers are parsed. *
    • Ends of lines are treated as white space, not as separate tokens. @@ -252,7 +252,7 @@ public class StreamTokenizer { /** * Resets this tokenizer's syntax table so that all characters are - * "ordinary." See the ordinaryChar 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 @@ public class StreamTokenizer { * Specifies that all characters c in the range * low <= c <= high * are "ordinary" in this tokenizer. See the - * ordinaryChar 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 @@ public class StreamTokenizer { * 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 ttype field to the + * single-character token and sets {@code ttype} field to the * character value. * *

      Making a line terminator character "ordinary" may interfere - * with the ability of a StreamTokenizer to count - * lines. The lineno 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 @@ public class StreamTokenizer { * Specifies that matching pairs of this character delimit string * constants in this tokenizer. *

      - * When the nextToken method encounters a string - * constant, the ttype field is set to the string - * delimiter and the sval 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. *

      * If a string quote character is encountered, then a string is @@ -371,7 +371,7 @@ public class StreamTokenizer { * 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 - * "\n" and "\t" are recognized and + * {@code "\u005Cn"} and {@code "\u005Ct"} are recognized and * converted to single characters as the string is parsed. * *

      Any other attribute settings for the specified character are cleared. @@ -398,9 +398,9 @@ public class StreamTokenizer { *

      * 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 ttype - * field to the value TT_NUMBER and putting the numeric - * value of the token into the nval 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 @@ public class StreamTokenizer { /** * 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 nextToken method returns - * TT_EOL and also sets the ttype 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. *

      * A line is a sequence of characters ending with either a - * carriage-return character ('\r') or a newline - * character ('\n'). 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. *

      - * If the flag 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 true indicates that end-of-line characters - * are separate tokens; false 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 @@ public class StreamTokenizer { /** * Determines whether or not the tokenizer recognizes C-style comments. - * If the flag argument is true, this stream tokenizer + * If the flag argument is {@code true}, this stream tokenizer * recognizes C-style comments. All text between successive - * occurrences of /* and */ are discarded. + * occurrences of {@code /*} and */ are discarded. *

      - * If the flag argument is false, then C-style comments + * If the flag argument is {@code false}, then C-style comments * are not treated specially. * - * @param flag true 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 @@ public class StreamTokenizer { /** * Determines whether or not the tokenizer recognizes C++-style comments. - * If the flag argument is true, this stream tokenizer + * If the flag argument is {@code true}, this stream tokenizer * recognizes C++-style comments. Any occurrence of two consecutive - * slash characters ('/') 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. *

      - * If the flag argument is false, then C++-style + * If the flag argument is {@code false}, then C++-style * comments are not treated specially. * - * @param flag true 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 @@ public class StreamTokenizer { /** * Determines whether or not word token are automatically lowercased. - * If the flag argument is true, then the value in the - * sval field is lowercased whenever a word token is - * returned (the ttype field has the - * value TT_WORD by the nextToken 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. *

      - * If the flag argument is false, then the - * sval field is not modified. + * If the flag argument is {@code false}, then the + * {@code sval} field is not modified. * - * @param fl true 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 @@ public class StreamTokenizer { /** * Parses the next token from the input stream of this tokenizer. - * The type of the next token is returned in the ttype + * The type of the next token is returned in the {@code ttype} * field. Additional information about the token may be in the - * nval field or the sval field of this + * {@code nval} field or the {@code sval} field of this * tokenizer. *

      * Typical clients of this @@ -516,7 +516,7 @@ public class StreamTokenizer { * calling nextToken to parse successive tokens until TT_EOF * is returned. * - * @return the value of the ttype 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 @@ public class StreamTokenizer { } /** - * Causes the next call to the nextToken method of this - * tokenizer to return the current value in the ttype - * field, and not to modify the value in the nval or - * sval 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 diff --git a/src/share/classes/java/lang/AbstractStringBuilder.java b/src/share/classes/java/lang/AbstractStringBuilder.java index 3605343ae3623682fc87274ac5f8981bef80aa13..eb38da21c0abc1d0e69e41fae57af217ce7e93ab 100644 --- a/src/share/classes/java/lang/AbstractStringBuilder.java +++ b/src/share/classes/java/lang/AbstractStringBuilder.java @@ -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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { * array is allocated with greater capacity. The new capacity is the * larger of: *

        - *
      • The minimumCapacity argument. - *
      • Twice the old capacity, plus 2. + *
      • The {@code minimumCapacity} argument. + *
      • Twice the old capacity, plus {@code 2}. *
      - * If the minimumCapacity 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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { * 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 k less than newLength, the character at + * index k less than {@code newLength}, the character at * index k in the new character sequence is the same as the * character at index k in the old sequence if k is less * than the length of the old character sequence; otherwise, it is the - * null character '\u0000'. + * null character {@code '\u005Cu0000'}. * - * In other words, if the newLength 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. *

      - * If the newLength argument is greater than or equal + * If the {@code newLength} argument is greater than or equal * to the current length, sufficient null characters - * ('\u0000') are appended so that - * length becomes the newLength argument. + * ({@code '\u005Cu0000'}) are appended so that + * length becomes the {@code newLength} argument. *

      - * The newLength argument must be greater than or equal - * to 0. + * The {@code newLength} argument must be greater than or equal + * to {@code 0}. * * @param newLength the new length * @throws IndexOutOfBoundsException if the - * newLength argument is negative. + * {@code newLength} argument is negative. */ public void setLength(int newLength) { if (newLength < 0) @@ -182,21 +182,21 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { } /** - * Returns the char value in this sequence at the specified index. - * The first char value is at index 0, the next at index - * 1, 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. *

      * The index argument must be greater than or equal to - * 0, and less than the length of this sequence. + * {@code 0}, and less than the length of this sequence. * - *

      If the char value specified by the index is a + *

      If the {@code char} value specified by the index is a * surrogate, the surrogate * value is returned. * - * @param index the index of the desired char value. - * @return the char value at the specified index. - * @throws IndexOutOfBoundsException if index is - * negative or greater than or equal to length(). + * @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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { /** * Returns the character (Unicode code point) at the specified - * index. The index refers to char values - * (Unicode code units) and ranges from 0 to - * {@link #length()} - 1. + * index. The index refers to {@code char} values + * (Unicode code units) and ranges from {@code 0} to + * {@link #length()}{@code - 1}. * - *

      If the char value specified at the given index + *

      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 - * char 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 char value at the given index is returned. + * the {@code char} value at the given index is returned. * - * @param index the index to the char values + * @param index the index to the {@code char} values * @return the code point value of the character at the - * index - * @exception IndexOutOfBoundsException if the index + * {@code index} + * @exception IndexOutOfBoundsException if the {@code index} * argument is negative or not less than the length of this * sequence. */ @@ -234,22 +234,22 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { /** * Returns the character (Unicode code point) before the specified - * index. The index refers to char values - * (Unicode code units) and ranges from 1 to {@link + * index. The index refers to {@code char} values + * (Unicode code units) and ranges from {@code 1} to {@link * #length()}. * - *

      If the char value at (index - 1) - * is in the low-surrogate range, (index - 2) is not - * negative, and the char value at (index - - * 2) is in the high-surrogate range, then the + *

      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 char value at index - - * 1 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 index + * @exception IndexOutOfBoundsException if the {@code index} * argument is less than 1 or greater than the length * of this sequence. */ @@ -264,22 +264,22 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { /** * Returns the number of Unicode code points in the specified text * range of this sequence. The text range begins at the specified - * beginIndex and extends to the char at - * index endIndex - 1. Thus the length (in - * chars) of the text range is - * endIndex-beginIndex. 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 char of + * @param beginIndex the index to the first {@code char} of * the text range. - * @param endIndex the index after the last char 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 - * beginIndex is negative, or endIndex + * {@code beginIndex} is negative, or {@code endIndex} * is larger than the length of this sequence, or - * beginIndex is larger than endIndex. + * {@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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { /** * Returns the index within this sequence that is offset from the - * given index by codePointOffset code + * given {@code index} by {@code codePointOffset} code * points. Unpaired surrogates within the text range given by - * index and codePointOffset 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 index + * @exception IndexOutOfBoundsException if {@code index} * is negative or larger then the length of this sequence, - * or if codePointOffset is positive and the subsequence - * starting with index has fewer than - * codePointOffset code points, - * or if codePointOffset is negative and the subsequence - * before index has fewer than the absolute value of - * codePointOffset 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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { /** * Characters are copied from this sequence into the - * destination character array dst. The first character to - * be copied is at index srcBegin; the last character to - * be copied is at index srcEnd-1. The total number of - * characters to be copied is srcEnd-srcBegin. The - * characters are copied into the subarray of dst starting - * at index dstBegin 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: *

            * dstbegin + (srcEnd-srcBegin) - 1
            * 
      @@ -330,19 +330,19 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { * @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 dst. - * @throws NullPointerException if dst is - * null. + * @param dstBegin offset into {@code dst}. + * @throws NullPointerException if {@code dst} is + * {@code null}. * @throws IndexOutOfBoundsException if any of the following is true: *
        - *
      • srcBegin is negative - *
      • dstBegin is negative - *
      • the srcBegin argument is greater than - * the srcEnd argument. - *
      • srcEnd is greater than - * this.length(). - *
      • dstBegin+srcEnd-srcBegin is greater than - * dst.length + *
      • {@code srcBegin} is negative + *
      • {@code dstBegin} is negative + *
      • the {@code srcBegin} argument is greater than + * the {@code srcEnd} argument. + *
      • {@code srcEnd} is greater than + * {@code this.length()}. + *
      • {@code dstBegin+srcEnd-srcBegin} is greater than + * {@code dst.length} *
      */ public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) @@ -357,18 +357,18 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { } /** - * The character at the specified index is set to ch. 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 ch at position index. + * character {@code ch} at position {@code index}. *

      * The index argument must be greater than or equal to - * 0, 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 index is - * negative or greater than or equal to length(). + * @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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { } /** - * Removes the char at the specified position in this - * sequence. This sequence is shortened by one char. + * Removes the {@code char} at the specified position in this + * sequence. This sequence is shortened by one {@code char}. * *

      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 chars to remove by calling - * Character.charCount(thisSequence.codePointAt(index)), - * where thisSequence 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 char to remove + * @param index Index of {@code char} to remove * @return This object. - * @throws StringIndexOutOfBoundsException if the index + * @throws StringIndexOutOfBoundsException if the {@code index} * is negative or greater than or equal to - * length(). + * {@code length()}. */ public AbstractStringBuilder deleteCharAt(int index) { if ((index < 0) || (index >= count)) @@ -767,12 +767,12 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { /** * Replaces the characters in a substring of this sequence - * with characters in the specified String. The substring - * begins at the specified start and extends to the character - * at index end - 1 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 - * String is inserted at start. (This + * {@code String} is inserted at {@code start}. (This * sequence will be lengthened to accommodate the * specified String if necessary.) * @@ -780,9 +780,9 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { * @param end The ending index, exclusive. * @param str String that will replace previous contents. * @return This object. - * @throws StringIndexOutOfBoundsException if start - * is negative, greater than length(), or - * greater than end. + * @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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { } /** - * Returns a new String 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 start 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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { } /** - * Returns a new String 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 start and - * extends to the character at index end - 1. + * 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 start - * or end are negative or greater than - * length(), or start is - * greater than end. + * @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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { *

            * this.toString().startsWith(str, k)
            * 
      - * is true. + * 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, -1 is returned. - * @throws java.lang.NullPointerException if str is - * null. + * 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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { * @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 str is - * null. + * @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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { /** * 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 this.length(). + * considered to occur at the index value {@code this.length()}. * The returned index is the largest value k such that *
            * this.toString().startsWith(str, k)
      @@ -1304,9 +1304,9 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
            * @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, -1 is returned.
      -     * @throws  java.lang.NullPointerException  if str is
      -     *          null.
      +     *          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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
            * @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 str is
      -     *          null.
      +     * @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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
            * is never reversed.
            *
            * Let n be the character length of this character sequence
      -     * (not the length in char values) just prior to
      -     * execution of the reverse method. Then the
      +     * (not the length in {@code char} values) just prior to
      +     * execution of the {@code reverse} method. Then the
            * character at index k in the new character sequence is
            * equal to the character at index n-k-1 in the old
            * character sequence.
      @@ -1351,7 +1351,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
            * 

      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 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { /** * Returns a string representing the data in this sequence. - * A new String 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 String is then returned. Subsequent + * object. This {@code String} is then returned. Subsequent * changes to this sequence do not affect the contents of the - * String. + * {@code String}. * * @return a string representation of this sequence of characters. */ diff --git a/src/share/classes/java/lang/Byte.java b/src/share/classes/java/lang/Byte.java index 4c0b1c2233bb97b90b962560f48af5c0c99385d5..799936f4a4426c40b6426d11cc2ec433cf13a48d 100644 --- a/src/share/classes/java/lang/Byte.java +++ b/src/share/classes/java/lang/Byte.java @@ -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 @@ public final class Byte extends Number implements Comparable { * 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 '-'} - * ('\u002D') to indicate a negative value or an - * ASCII plus sign {@code '+'} ('\u002B') 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 @@ public final class Byte extends Number implements Comparable { * *

    • Any character of the string is not a digit of the * specified radix, except that the first character may be a minus - * sign {@code '-'} ('\u002D') or plus sign - * {@code '+'} ('\u002B') provided that the + * sign {@code '-'} ({@code '\u005Cu002D'}) or plus sign + * {@code '+'} ({@code '\u005Cu002B'}) provided that the * string is longer than length 1. * *
    • The value represented by the string is not a value of type @@ -157,9 +157,9 @@ public final class Byte extends Number implements Comparable { * 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 '-'} ('\u002D') to indicate a negative + * {@code '-'} ({@code '\u005Cu002D'}) to indicate a negative * value or an ASCII plus sign {@code '+'} - * ('\u002B') 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. @@ -445,6 +445,47 @@ public final class Byte extends Number implements Comparable { return x - y; } + /** + * 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 28. + * + * @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 28. + * + * @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. diff --git a/src/share/classes/java/lang/Double.java b/src/share/classes/java/lang/Double.java index 8bf9853537d69117a498ddbf1f35720fc7fe72ce..5e1afaea747f5f9d90f55113586ed047b9d129c9 100644 --- a/src/share/classes/java/lang/Double.java +++ b/src/share/classes/java/lang/Double.java @@ -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 @@ public final class Double extends Number implements Comparable { *
    • 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 -}' - * ('\u002D'); 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 m: *
        *
      • If m is infinity, it is represented by the characters @@ -156,7 +156,7 @@ public final class Double extends Number implements Comparable { *
      • If m is greater than or equal to 10-3 but less * than 107, then it is represented as the integer part of * m, in decimal form with no leading zeroes, followed by - * '{@code .}' ('\u002E'), followed by one or + * '{@code .}' ({@code '\u005Cu002E'}), followed by one or * more decimal digits representing the fractional part of m. * *
      • If m is less than 10-3 or greater than or @@ -168,9 +168,9 @@ public final class Double extends Number implements Comparable { * 10n so that 1 ≤ a {@literal <} 10. The * magnitude is then represented as the integer part of a, * as a single decimal digit, followed by '{@code .}' - * ('\u002E'), followed by decimal digits + * ({@code '\u005Cu002E'}), followed by decimal digits * representing the fractional part of a, followed by the - * letter '{@code E}' ('\u0045'), followed + * letter '{@code E}' ({@code '\u005Cu0045'}), followed * by a representation of n as a decimal integer, as * produced by the method {@link Integer#toString(int)}. *
      @@ -208,7 +208,7 @@ public final class Double extends Number implements Comparable { *
    • 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 -}' - * ('\u002D'); 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 m: * *
        diff --git a/src/share/classes/java/lang/Float.java b/src/share/classes/java/lang/Float.java index 65a230a12a59cb3ea5785a3b042f7e06703c182d..4e73507911b0ae126de6330cc1386a03cca841c6 100644 --- a/src/share/classes/java/lang/Float.java +++ b/src/share/classes/java/lang/Float.java @@ -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 @@ public final class Float extends Number implements Comparable { *
      • 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 -}' ('\u002D'); if the sign is + * '{@code -}' ({@code '\u005Cu002D'}); if the sign is * positive, no sign character appears in the result. As for * the magnitude m: *
          @@ -154,7 +154,7 @@ public final class Float extends Number implements Comparable { * less than 107, then it is represented as the * integer part of m, in decimal form with no leading * zeroes, followed by '{@code .}' - * ('\u002E'), followed by one or more + * ({@code '\u005Cu002E'}), followed by one or more * decimal digits representing the fractional part of * m. *
        • If m is less than 10-3 or greater than or @@ -166,10 +166,10 @@ public final class Float extends Number implements Comparable { * 10n so that 1 ≤ a {@literal <} 10. * The magnitude is then represented as the integer part of * a, as a single decimal digit, followed by - * '{@code .}' ('\u002E'), followed by + * '{@code .}' ({@code '\u005Cu002E'}), followed by * decimal digits representing the fractional part of * a, followed by the letter '{@code E}' - * ('\u0045'), followed by a representation + * ({@code '\u005Cu0045'}), followed by a representation * of n as a decimal integer, as produced by the * method {@link java.lang.Integer#toString(int)}. * @@ -210,7 +210,7 @@ public final class Float extends Number implements Comparable { *
        • 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 -}' - * ('\u002D'); 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 m: * *
            diff --git a/src/share/classes/java/lang/Integer.java b/src/share/classes/java/lang/Integer.java index dee52ae1fa852717c2730b7b4120d94f1460b1a1..88acdfa11dafb9afc54c84c9b476ecc1438e34fa 100644 --- a/src/share/classes/java/lang/Integer.java +++ b/src/share/classes/java/lang/Integer.java @@ -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 @@ public final class Integer extends Number implements Comparable { * *

            If the first argument is negative, the first element of the * result is the ASCII minus character {@code '-'} - * ('\u002D'). If the first argument is not + * ({@code '\u005Cu002D'}). If the first argument is not * negative, no sign character appears in the result. * *

            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'} - * ('\u0030'); 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 @@ public final class Integer extends Number implements Comparable { * {@code 0123456789abcdefghijklmnopqrstuvwxyz} *

    • * - * These are '\u0030' through - * '\u0039' and '\u0061' through - * '\u007A'. If {@code radix} is + * These are {@code '\u005Cu0030'} through + * {@code '\u005Cu0039'} and {@code '\u005Cu0061'} through + * {@code '\u005Cu007A'}. If {@code radix} is * N, then the first N of these characters * are used as radix-N digits in the order shown. Thus, * the digits for hexadecimal (radix 16) are @@ -128,7 +128,6 @@ public final class Integer extends Number implements Comparable { * @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; @@ -158,6 +157,36 @@ public final class Integer extends Number implements Comparable { return new String(buf, charPos, (33 - charPos)); } + /** + * Returns a string representation of the first argument as an + * unsigned integer value in the radix specified by the second + * argument. + * + *

      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. + * + *

      Note that since the first argument is treated as an unsigned + * value, no leading sign character is printed. + * + *

      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. + * + *

      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 @@ public final class Integer extends Number implements Comparable { * 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'} - * ('\u0030'); 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. + * + *

      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)}. + * + *

      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: * *

      * {@code 0123456789abcdef} *
      * - * These are the characters '\u0030' through - * '\u0039' and '\u0061' through - * '\u0066'. 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 @@ public final class Integer extends Number implements Comparable { * @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 @@ public final class Integer extends Number implements Comparable { * argument. This value is converted to a string of ASCII digits * in octal (base 8) with no extra leading {@code 0}s. * + *

      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)}. + * *

      If the unsigned magnitude is zero, it is represented by a - * single zero character {@code '0'} - * ('\u0030'); 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: * *

      * {@code 01234567} *
      * - * These are the characters '\u0030' through - * '\u0037'. + * 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 @@ public final class Integer extends Number implements Comparable { * 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'} - * ('\u0030'); otherwise, the first character of - * the representation of the unsigned magnitude will not be the - * zero character. The characters {@code '0'} - * ('\u0030') and {@code '1'} - * ('\u0031') are used as binary digits. + * + *

      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)}. + * + *

      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; @@ -334,6 +384,24 @@ public final class Integer extends Number implements Comparable { return new String(0, size, buf); } + /** + * 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 @@ -393,9 +461,9 @@ public final class Integer extends Number implements Comparable { * 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 '-'} ('\u002D') to + * ASCII minus sign {@code '-'} ({@code '\u005Cu002D'}) to * indicate a negative value or an ASCII plus sign {@code '+'} - * ('\u002B') to indicate a positive value. The + * ({@code '\u005Cu002B'}) to indicate a positive value. The * resulting integer value is returned. * *

      An exception of type {@code NumberFormatException} is @@ -410,8 +478,8 @@ public final class Integer extends Number implements Comparable { * *

    • Any character of the string is not a digit of the specified * radix, except that the first character may be a minus sign - * {@code '-'} ('\u002D') or plus sign - * {@code '+'} ('\u002B') provided that the + * {@code '-'} ({@code '\u005Cu002D'}) or plus sign + * {@code '+'} ({@code '\u005Cu002B'}) provided that the * string is longer than length 1. * *
    • The value represented by the string is not a value of type @@ -511,8 +579,8 @@ public final class Integer extends Number implements Comparable { * 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 '-'} - * ('\u002D') to indicate a negative value or an - * ASCII plus sign {@code '+'} ('\u002B') 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, @@ -528,6 +596,102 @@ public final class Integer extends Number implements Comparable { return parseInt(s,10); } + /** + * 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. + * + *

      An exception of type {@code NumberFormatException} is + * thrown if any of the following situations occurs: + *

        + *
      • The first argument is {@code null} or is a string of + * length zero. + * + *
      • The radix is either smaller than + * {@link java.lang.Character#MIN_RADIX} or + * larger than {@link java.lang.Character#MAX_RADIX}. + * + *
      • 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. + * + *
      • The value represented by the string is larger than the + * largest unsigned {@code int}, 232-1. + * + *
      + * + * + * @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 @@ -1030,6 +1194,83 @@ public final class Integer extends Number implements Comparable { 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 232. + * + * @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. + * + *

      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 diff --git a/src/share/classes/java/lang/Long.java b/src/share/classes/java/lang/Long.java index a87f4096d4df77eaf41d37ce490bb56960547136..f4dc32dcdff8af61d14ff6324c9c982cdfd2a56b 100644 --- a/src/share/classes/java/lang/Long.java +++ b/src/share/classes/java/lang/Long.java @@ -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 @@ public final class Long extends Number implements Comparable { * *

      If the first argument is negative, the first element of the * result is the ASCII minus sign {@code '-'} - * ('\u002d'). If the first argument is not + * ({@code '\u005Cu002d'}). If the first argument is not * negative, no sign character appears in the result. * *

      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'} - * ('\u0030'); 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 @@ public final class Long extends Number implements Comparable { * {@code 0123456789abcdefghijklmnopqrstuvwxyz} *

    * - * These are '\u0030' through - * '\u0039' and '\u0061' through - * '\u007a'. If {@code radix} is + * These are {@code '\u005Cu0030'} through + * {@code '\u005Cu0039'} and {@code '\u005Cu0061'} through + * {@code '\u005Cu007a'}. If {@code radix} is * N, then the first N of these characters * are used as radix-N digits in the order shown. Thus, * the digits for hexadecimal (radix 16) are @@ -139,6 +141,88 @@ public final class Long extends Number implements Comparable { return new String(buf, charPos, (65 - charPos)); } + /** + * Returns a string representation of the first argument as an + * unsigned integer value in the radix specified by the second + * argument. + * + *

    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. + * + *

    Note that since the first argument is treated as an unsigned + * value, no leading sign character is printed. + * + *

    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. + * + *

    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 @@ public final class Long extends Number implements Comparable { * 264 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'} - * ('\u0030'); 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. + * + *

    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)}. + * + *

    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: * *

    * {@code 0123456789abcdef} *
    * - * These are the characters '\u0030' through - * '\u0039' and '\u0061' through - * '\u0066'. 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 @@ public final class Long extends Number implements Comparable { * @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 @@ public final class Long extends Number implements Comparable { * ASCII digits in octal (base 8) with no extra leading * {@code 0}s. * + *

    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)}. + * *

    If the unsigned magnitude is zero, it is represented by a - * single zero character {@code '0'} - * ('\u0030'); 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: * *

    * {@code 01234567} *
    * - * These are the characters '\u0030' through - * '\u0037'. + * 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 @@ public final class Long extends Number implements Comparable { * 264 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'} - * ('\u0030'); otherwise, the first character of - * the representation of the unsigned magnitude will not be the - * zero character. The characters {@code '0'} - * ('\u0030') and {@code '1'} - * ('\u0031') are used as binary digits. + * {@code 0}s. + * + *

    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)}. + * + *

    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; @@ -270,6 +376,24 @@ public final class Long extends Number implements Comparable { return new String(0, size, buf); } + /** + * 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 @@ -343,14 +467,14 @@ public final class Long extends Number implements Comparable { * 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 '-'} ('\u002D') to + * ASCII minus sign {@code '-'} ({@code '\u005Cu002D'}) to * indicate a negative value or an ASCII plus sign {@code '+'} - * ('\u002B') to indicate a positive value. The + * ({@code '\u005Cu002B'}) to indicate a positive value. The * resulting {@code long} value is returned. * *

    Note that neither the character {@code L} - * ('\u004C') nor {@code l} - * ('\u006C') 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 @@ public final class Long extends Number implements Comparable { * *

  • Any character of the string is not a digit of the specified * radix, except that the first character may be a minus sign - * {@code '-'} ('\u002d') or plus sign {@code - * '+'} ('\u002B') provided that the string is + * {@code '-'} ({@code '\u005Cu002d'}) or plus sign {@code + * '+'} ({@code '\u005Cu002B'}) provided that the string is * longer than length 1. * *
  • The value represented by the string is not a value of type @@ -460,16 +584,16 @@ public final class Long extends Number implements Comparable { * 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 '-'} - * (\u002D') to indicate a negative value or an - * ASCII plus sign {@code '+'} ('\u002B') 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. * *

    Note that neither the character {@code L} - * ('\u004C') nor {@code l} - * ('\u006C') 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. * @@ -484,6 +608,121 @@ public final class Long extends Number implements Comparable { return parseLong(s, 10); } + /** + * 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. + * + *

    An exception of type {@code NumberFormatException} is + * thrown if any of the following situations occurs: + *

      + *
    • The first argument is {@code null} or is a string of + * length zero. + * + *
    • The radix is either smaller than + * {@link java.lang.Character#MIN_RADIX} or + * larger than {@link java.lang.Character#MAX_RADIX}. + * + *
    • 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. + * + *
    • The value represented by the string is larger than the + * largest unsigned {@code long}, 264-1. + * + *
    + * + * + * @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 @@ -909,8 +1148,8 @@ public final class Long extends Number implements Comparable { * * *

    Note that, in every case, neither {@code L} - * ('\u004C') nor {@code l} - * ('\u006C') 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 @@ public final class Long extends Number implements Comparable { 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. + * + *

    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 diff --git a/src/share/classes/java/lang/Short.java b/src/share/classes/java/lang/Short.java index 6509039fe0ce209b0fdfca7350bcabd9aaf8b7c9..2a1d8b5502d167ffcd2e82e42b55e63c2f39c5a1 100644 --- a/src/share/classes/java/lang/Short.java +++ b/src/share/classes/java/lang/Short.java @@ -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 @@ public final class Short extends Number implements Comparable { * 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 '-'} - * ('\u002D') to indicate a negative value or an - * ASCII plus sign {@code '+'} ('\u002B') 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 @@ public final class Short extends Number implements Comparable { * *

  • Any character of the string is not a digit of the * specified radix, except that the first character may be a minus - * sign {@code '-'} ('\u002D') or plus sign - * {@code '+'} ('\u002B') provided that the + * sign {@code '-'} ({@code '\u005Cu002D'}) or plus sign + * {@code '+'} ({@code '\u005Cu002B'}) provided that the * string is longer than length 1. * *
  • The value represented by the string is not a value of type @@ -126,9 +126,9 @@ public final class Short extends Number implements Comparable { * 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 '-'} ('\u002D') to indicate a + * sign {@code '-'} ({@code '\u005Cu002D'}) to indicate a * negative value or an ASCII plus sign {@code '+'} - * ('\u002B') 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 @@ public final class Short extends Number implements Comparable { 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 216. + * + * @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 216. + * + * @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; } diff --git a/src/share/classes/java/lang/String.java b/src/share/classes/java/lang/String.java index 50b3f7b6b4816d59a7a45d53d550cee077f3216c..79c71d119a55baf9e3bdcc670ab53ffb307eaf3a 100644 --- a/src/share/classes/java/lang/String.java +++ b/src/share/classes/java/lang/String.java @@ -39,8 +39,8 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; /** - * The String class represents character strings. All - * string literals in Java programs, such as "abc", 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. *

    * Strings are constant; their values cannot be changed after they @@ -63,7 +63,7 @@ import java.util.regex.PatternSyntaxException; * String d = cde.substring(1, 2); *

  • *

    - * The class String 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 @@ import java.util.regex.PatternSyntaxException; * 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 StringBuilder(or StringBuffer) - * class and its append method. + * through the {@code StringBuilder}(or {@code StringBuffer}) + * class and its {@code append} method. * String conversions are implemented through the method - * toString, defined by Object 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, * The Java Language Specification. @@ -85,16 +85,16 @@ import java.util.regex.PatternSyntaxException; * or method in this class will cause a {@link NullPointerException} to be * thrown. * - *

    A String represents a string in the UTF-16 format + *

    A {@code String} represents a string in the UTF-16 format * in which supplementary characters are represented by surrogate * pairs (see the section Unicode - * Character Representations in the Character class for + * Character Representations in the {@code Character} class for * more information). - * Index values refer to char code units, so a supplementary - * character uses two positions in a String. - *

    The String 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}. + *

    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., char values). + * dealing with Unicode code units (i.e., {@code char} values). * * @author Lee Boynton * @author Arthur van Hoff @@ -131,9 +131,9 @@ public final class String * A String instance is written initially into an ObjectOutputStream in the * following format: *

    -     *      TC_STRING (utf String)
    +     *      {@code TC_STRING} (utf String)
          * 
    - * The String is written by method DataOutput.writeUTF. + * 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 @@ public final class String } /** - * Returns the char value at the - * specified index. An index ranges from 0 to - * length() - 1. The first char value of the sequence - * is at index 0, the next at index 1, + * 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. * - *

    If the char value specified by the index is a + *

    If the {@code char} value specified by the index is a * surrogate, the surrogate * value is returned. * - * @param index the index of the char value. - * @return the char value at the specified index of this string. - * The first char value is at index 0. - * @exception IndexOutOfBoundsException if the index + * @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 @@ public final class String /** * Returns the character (Unicode code point) at the specified - * index. The index refers to char values - * (Unicode code units) and ranges from 0 to - * {@link #length()} - 1. + * index. The index refers to {@code char} values + * (Unicode code units) and ranges from {@code 0} to + * {@link #length()}{@code - 1}. * - *

    If the char value specified at the given index + *

    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 String, and the - * char 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 char value at the given index is returned. + * the {@code char} value at the given index is returned. * - * @param index the index to the char values + * @param index the index to the {@code char} values * @return the code point value of the character at the - * index - * @exception IndexOutOfBoundsException if the index + * {@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 @@ public final class String /** * Returns the character (Unicode code point) before the specified - * index. The index refers to char values - * (Unicode code units) and ranges from 1 to {@link + * index. The index refers to {@code char} values + * (Unicode code units) and ranges from {@code 1} to {@link * CharSequence#length() length}. * - *

    If the char value at (index - 1) - * is in the low-surrogate range, (index - 2) is not - * negative, and the char value at (index - - * 2) is in the high-surrogate range, then the + *

    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 char value at index - - * 1 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 index + * @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 @@ public final class String /** * Returns the number of Unicode code points in the specified text - * range of this String. The text range begins at the - * specified beginIndex and extends to the - * char at index endIndex - 1. Thus the - * length (in chars) of the text range is - * endIndex-beginIndex. 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 char of + * @param beginIndex the index to the first {@code char} of * the text range. - * @param endIndex the index after the last char 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 - * beginIndex is negative, or endIndex - * is larger than the length of this String, or - * beginIndex is larger than endIndex. + * {@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 @@ public final class String } /** - * Returns the index within this String that is - * offset from the given index by - * codePointOffset code points. Unpaired surrogates - * within the text range given by index and - * codePointOffset 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 String - * @exception IndexOutOfBoundsException if index + * @return the index within this {@code String} + * @exception IndexOutOfBoundsException if {@code index} * is negative or larger then the length of this - * String, or if codePointOffset is positive - * and the substring starting with index has fewer - * than codePointOffset code points, - * or if codePointOffset is negative and the substring - * before index has fewer than the absolute value - * of codePointOffset 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 @@ public final class String * Copies characters from this string into the destination character * array. *

    - * The first character to be copied is at index srcBegin; - * the last character to be copied is at index srcEnd-1 + * 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 - * srcEnd-srcBegin). The characters are copied into the - * subarray of dst starting at index dstBegin + * {@code srcEnd-srcBegin}). The characters are copied into the + * subarray of {@code dst} starting at index {@code dstBegin} * and ending at index: *

          *     dstbegin + (srcEnd-srcBegin) - 1
    @@ -842,13 +842,13 @@ public final class String
          * @param      dstBegin   the start offset in the destination array.
          * @exception IndexOutOfBoundsException If any of the following
          *            is true:
    -     *            
    • srcBegin is negative. - *
    • srcBegin is greater than srcEnd - *
    • srcEnd is greater than the length of this + *
      • {@code srcBegin} is negative. + *
      • {@code srcBegin} is greater than {@code srcEnd} + *
      • {@code srcEnd} is greater than the length of this * string - *
      • dstBegin is negative - *
      • dstBegin+(srcEnd-srcBegin) is larger than - * dst.length
      + *
    • {@code dstBegin} is negative + *
    • {@code dstBegin+(srcEnd-srcBegin)} is larger than + * {@code dst.length}
    */ public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) { if (srcBegin < 0) { @@ -1135,14 +1135,14 @@ public final class String * Compares two strings lexicographically. * The comparison is based on the Unicode value of each character in * the strings. The character sequence represented by this - * String 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 String object + * a negative integer if this {@code String} object * lexicographically precedes the argument string. The result is a - * positive integer if this String object lexicographically + * positive integer if this {@code String} object lexicographically * follows the argument string. The result is zero if the strings - * are equal; compareTo returns 0 exactly when - * the {@link #equals(Object)} method would return true. + * are equal; {@code compareTo} returns {@code 0} exactly when + * the {@link #equals(Object)} method would return {@code true}. *

    * 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 @@ public final class String * positions, let k be the smallest such index; then the string * whose character at position k has the smaller value, as * determined by using the < operator, lexicographically precedes the - * other string. In this case, compareTo returns the - * difference of the two character values at position k 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: *

          * this.charAt(k)-anotherString.charAt(k)
          * 
    * If there is no index position at which they differ, then the shorter * string lexicographically precedes the longer string. In this case, - * compareTo returns the difference of the lengths of the + * {@code compareTo} returns the difference of the lengths of the * strings -- that is, the value: *
          * this.length()-anotherString.length()
          * 
    * - * @param anotherString the String to be compared. - * @return the value 0 if the argument string is equal to - * this string; a value less than 0 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 0 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 @@ public final class String } /** - * A Comparator that orders String objects as by - * compareToIgnoreCase. This comparator is serializable. + * A Comparator that orders {@code String} objects as by + * {@code compareToIgnoreCase}. This comparator is serializable. *

    * Note that this Comparator does not take locale into account, * and will result in an unsatisfactory ordering for certain locales. @@ -1253,9 +1253,9 @@ public final class String /** * Compares two strings lexicographically, ignoring case * differences. This method returns an integer whose sign is that of - * calling compareTo with normalized versions of the strings + * calling {@code compareTo} with normalized versions of the strings * where case differences have been eliminated by calling - * Character.toLowerCase(Character.toUpperCase(character)) on + * {@code Character.toLowerCase(Character.toUpperCase(character))} on * each character. *

    * Note that this method does not take locale into account, @@ -1263,7 +1263,7 @@ public final class String * The java.text package provides collators to allow * locale-sensitive ordering. * - * @param str the String 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 @@ public final class String * @param ooffset the starting offset of the subregion in the string * argument. * @param len the number of characters to compare. - * @return true 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; - * false otherwise. + * {@code false} otherwise. */ public boolean regionMatches(int toffset, String other, int ooffset, int len) { @@ -1360,7 +1360,7 @@ public final class String *

    * * - * @param ignoreCase if true, 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 @@ public final class String * @param ooffset the starting offset of the subregion in the string * argument. * @param len the number of characters to compare. - * @return true 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; - * false otherwise. Whether the matching is exact - * or case insensitive depends on the ignoreCase + * {@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 @@ public final class String * * @param prefix the prefix. * @param toffset where to begin looking in this string. - * @return true 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 toffset; false otherwise. - * The result is false if toffset 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 - * String object; otherwise the result is the same + * {@code String} object; otherwise the result is the same * as the result of the expression *
          *          this.substring(toffset).startsWith(prefix)
    @@ -1453,12 +1453,12 @@ public final class String
          * Tests if this string starts with the specified prefix.
          *
          * @param   prefix   the prefix.
    -     * @return  true 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; false otherwise.
    -     *          Note also that true 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
    -     *          String object as determined by the
    +     *          {@code String} object as determined by the
          *          {@link #equals(Object)} method.
          * @since   1. 0
          */
    @@ -1470,11 +1470,11 @@ public final class String
          * Tests if this string ends with the specified suffix.
          *
          * @param   suffix   the suffix.
    -     * @return  true 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; false otherwise. Note that the
    -     *          result will be true if the argument is the
    -     *          empty string or is equal to this String 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 @@ public final class String
     
         /**
          * Returns a hash code for this string. The hash code for a
    -     * String object is computed as
    +     * {@code String} object is computed as
          * 
          * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
          * 
    - * using int arithmetic, where s[i] is the - * ith character of the string, n is the length of - * the string, and ^ indicates exponentiation. + * using {@code int} arithmetic, where {@code s[i]} is the + * ith 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 @@ public final class String /** * Returns the index within this string of the first occurrence of * the specified character. If a character with value - * ch occurs in the character sequence represented by - * this String 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 ch in the range from 0 to 0xFFFF + * values of {@code ch} in the range from 0 to 0xFFFF * (inclusive), this is the smallest value k such that: *
          * this.charAt(k) == ch
          * 
    - * is true. For other values of ch, it is the + * is true. For other values of {@code ch}, it is the * smallest value k such that: *
          * this.codePointAt(k) == ch
          * 
    * is true. In either case, if no such character occurs in this - * string, then -1 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 - * -1 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 @@ public final class String * Returns the index within this string of the first occurrence of the * specified character, starting the search at the specified index. *

    - * If a character with value ch occurs in the - * character sequence represented by this String - * object at an index no smaller than fromIndex, 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 ch in the range from 0 to 0xFFFF (inclusive), + * of {@code ch} in the range from 0 to 0xFFFF (inclusive), * this is the smallest value k such that: *

          * (this.charAt(k) == ch) && (k >= fromIndex)
          * 
    - * is true. For other values of ch, it is the + * is true. For other values of {@code ch}, it is the * smallest value k such that: *
          * (this.codePointAt(k) == ch) && (k >= fromIndex)
          * 
    * is true. In either case, if no such character occurs in this - * string at or after position fromIndex, then - * -1 is returned. + * string at or after position {@code fromIndex}, then + * {@code -1} is returned. * *

    - * There is no restriction on the value of fromIndex. 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: -1 is returned. + * this string: {@code -1} is returned. * - *

    All indices are specified in char values + *

    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 fromIndex, or -1 + * 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 @@ public final class String /** * Returns the index within this string of the last occurrence of - * the specified character. For values of ch 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 k such that: *

          * this.charAt(k) == ch
          * 
    - * is true. For other values of ch, it is the + * is true. For other values of {@code ch}, it is the * largest value k such that: *
          * this.codePointAt(k) == ch
          * 
    * is true. In either case, if no such character occurs in this - * string, then -1 is returned. The - * String 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 - * -1 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 @@ public final class String /** * Returns the index within this string of the last occurrence of * the specified character, searching backward starting at the - * specified index. For values of ch 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 k such that: *
          * (this.charAt(k) == ch) && (k <= fromIndex)
          * 
    - * is true. For other values of ch, it is the + * is true. For other values of {@code ch}, it is the * largest value k such that: *
          * (this.codePointAt(k) == ch) && (k <= fromIndex)
          * 
    * is true. In either case, if no such character occurs in this - * string at or before position fromIndex, then - * -1 is returned. + * string at or before position {@code fromIndex}, then + * {@code -1} is returned. * - *

    All indices are specified in char values + *

    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 fromIndex. 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 @@ public final class String * -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 fromIndex, or -1 + * 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 @@ public final class String * @param beginIndex the beginning index, inclusive. * @return the specified substring. * @exception IndexOutOfBoundsException if - * beginIndex is negative or larger than the - * length of this String 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 @@ public final class String /** * Returns a new string that is a substring of this string. The - * substring begins at the specified beginIndex and - * extends to the character at index endIndex - 1. - * Thus the length of the substring is endIndex-beginIndex. + * 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}. *

    * Examples: *

    @@ -1944,11 +1944,11 @@ public final class String
          * @param      endIndex     the ending index, exclusive.
          * @return     the specified substring.
          * @exception  IndexOutOfBoundsException  if the
    -     *             beginIndex is negative, or
    -     *             endIndex is larger than the length of
    -     *             this String object, or
    -     *             beginIndex is larger than
    -     *             endIndex.
    +     *             {@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 @@ public final class String
         /**
          * Concatenates the specified string to the end of this string.
          * 

    - * If the length of the argument string is 0, then this - * String object is returned. Otherwise, a new - * String 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 String object and the character + * represented by this {@code String} object and the character * sequence represented by the argument string.

    * Examples: *

    @@ -2011,8 +2011,8 @@ public final class String
          * "to".concat("get").concat("her") returns "together"
          * 
    * - * @param str the String that is concatenated to the end - * of this String. + * @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 @@ public final class String /** * Returns a new string resulting from replacing all occurrences of - * oldChar in this string with newChar. + * {@code oldChar} in this string with {@code newChar}. *

    - * If the character oldChar does not occur in the - * character sequence represented by this String object, - * then a reference to this String object is returned. - * Otherwise, a new String 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 String object, except that every - * occurrence of oldChar is replaced by an occurrence - * of newChar. + * represented by this {@code String} object, except that every + * occurrence of {@code oldChar} is replaced by an occurrence + * of {@code newChar}. *

    * Examples: *

    @@ -2054,7 +2054,7 @@ public final class String
          * @param   oldChar   the old character.
          * @param   newChar   the new character.
          * @return  a string derived from this string by replacing every
    -     *          occurrence of oldChar with newChar.
    +     *          occurrence of {@code oldChar} with {@code newChar}.
          */
         public String replace(char oldChar, char newChar) {
             if (oldChar != newChar) {
    @@ -2119,8 +2119,8 @@ public final class String
          * sequence of char values.
          *
          * @param s the sequence to search for
    -     * @return true if this string contains s, false otherwise
    -     * @throws NullPointerException if s is null
    +     * @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 @@ public final class String
          * @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 target or
    -     *         replacement is null.
    +     * @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 @@ public final class String
         }
     
         /**
    -     * Converts all of the characters in this String to lower
    -     * case using the rules of the given Locale.  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
    -     * String may be a different length than the original String.
    +     * {@code String} may be a different length than the original {@code String}.
          * 

    * Examples of lowercase mappings are in the following table: *

  • @@ -2452,7 +2452,7 @@ public final class String *
    * * @param locale use the case transformation rules for this locale - * @return the String, 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 @@ public final class String } /** - * Converts all of the characters in this String 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 - * toLowerCase(Locale.getDefault()). + * {@code toLowerCase(Locale.getDefault())}. *

    * Note: 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, "TITLE".toLowerCase() in a Turkish locale - * returns "t\u005Cu0131tle", 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 - * toLowerCase(Locale.ENGLISH). + * {@code toLowerCase(Locale.ENGLISH)}. *

    - * @return the String, converted to lowercase. + * @return the {@code String}, converted to lowercase. * @see java.lang.String#toLowerCase(Locale) */ public String toLowerCase() { @@ -2576,11 +2576,11 @@ public final class String } /** - * Converts all of the characters in this String to upper - * case using the rules of the given Locale. 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 - * String may be a different length than the original String. + * {@code String} may be a different length than the original {@code String}. *

    * Examples of locale-sensitive and 1:M case mappings are in the following table. *

    @@ -2617,7 +2617,7 @@ public final class String * * * @param locale use the case transformation rules for this locale - * @return the String, 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 @@ public final class String } /** - * Converts all of the characters in this String 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 - * toUpperCase(Locale.getDefault()). + * {@code toUpperCase(Locale.getDefault())}. *

    * Note: 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, "title".toUpperCase() in a Turkish locale - * returns "T\u005Cu0130TLE", 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 - * toUpperCase(Locale.ENGLISH). + * {@code toUpperCase(Locale.ENGLISH)}. *

    - * @return the String, converted to uppercase. + * @return the {@code String}, converted to uppercase. * @see java.lang.String#toUpperCase(Locale) */ public String toUpperCase() { @@ -2742,21 +2742,21 @@ public final class String * Returns a copy of the string, with leading and trailing whitespace * omitted. *

    - * If this String 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 String object both have codes - * greater than '\u0020' (the space character), then a - * reference to this String 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. *

    * Otherwise, if there is no character with a code greater than - * '\u0020' in the string, then a new - * String 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. *

    * Otherwise, let k be the index of the first character in the - * string whose code is greater than '\u0020', and let + * string whose code is greater than {@code '\u005Cu0020'}, and let * m be the index of the last character in the string whose code - * is greater than '\u0020'. A new String + * 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 k and ends with the * character at index m-that is, the result of @@ -2893,12 +2893,12 @@ public final class String } /** - * Returns the string representation of the Object argument. + * Returns the string representation of the {@code Object} argument. * - * @param obj an Object. - * @return if the argument is null, then a string equal to - * "null"; otherwise, the value of - * obj.toString() 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 @@ public final class String } /** - * Returns the string representation of the char 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 char 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 @@ public final class String /** * Returns the string representation of a specific subarray of the - * char array argument. + * {@code char} array argument. *

    - * The offset argument is the index of the first - * character of the subarray. The count 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 - * String. - * @param count the length of the value of the String. + * {@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 offset is - * negative, or count is negative, or - * offset+count is larger than - * data.length. + * @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 @@ public final class String * @param data the character array. * @param offset initial offset of the subarray. * @param count length of the subarray. - * @return a String 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 @@ public final class String * array specified. * * @param data the character array. - * @return a String 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 @@ public final class String } /** - * Returns the string representation of the boolean argument. + * Returns the string representation of the {@code boolean} argument. * - * @param b a boolean. - * @return if the argument is true, a string equal to - * "true" is returned; otherwise, a string equal to - * "false" 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 char + * Returns the string representation of the {@code char} * argument. * - * @param c a char. - * @return a string of length 1 containing - * as its single character the argument c. + * @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 @@ public final class String } /** - * Returns the string representation of the int argument. + * Returns the string representation of the {@code int} argument. *

    * The representation is exactly the one returned by the - * Integer.toString method of one argument. + * {@code Integer.toString} method of one argument. * - * @param i an int. - * @return a string representation of the int 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 @@ public final class String } /** - * Returns the string representation of the long argument. + * Returns the string representation of the {@code long} argument. *

    * The representation is exactly the one returned by the - * Long.toString method of one argument. + * {@code Long.toString} method of one argument. * - * @param l a long. - * @return a string representation of the long 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 @@ public final class String } /** - * Returns the string representation of the float argument. + * Returns the string representation of the {@code float} argument. *

    * The representation is exactly the one returned by the - * Float.toString method of one argument. + * {@code Float.toString} method of one argument. * - * @param f a float. - * @return a string representation of the float 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 @@ public final class String } /** - * Returns the string representation of the double argument. + * Returns the string representation of the {@code double} argument. *

    * The representation is exactly the one returned by the - * Double.toString method of one argument. + * {@code Double.toString} method of one argument. * - * @param d a double. - * @return a string representation of the double 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 @@ public final class String * Returns a canonical representation for the string object. *

    * A pool of strings, initially empty, is maintained privately by the - * class String. + * class {@code String}. *

    * When the intern method is invoked, if the pool already contains a - * string equal to this String 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 String object is added to the - * pool and a reference to this String object is returned. + * returned. Otherwise, this {@code String} object is added to the + * pool and a reference to this {@code String} object is returned. *

    - * It follows that for any two strings s and t, - * s.intern() == t.intern() is true - * if and only if s.equals(t) is true. + * 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}. *

    * All literal strings and string-valued constant expressions are * interned. String literals are defined in section 3.10.5 of the diff --git a/src/share/classes/java/text/SimpleDateFormat.java b/src/share/classes/java/text/SimpleDateFormat.java index 85bf158dcd993dc7dc27ed857e86233998e33856..7cbed983731baeb1582d979783e1355346fa82e2 100644 --- a/src/share/classes/java/text/SimpleDateFormat.java +++ b/src/share/classes/java/text/SimpleDateFormat.java @@ -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 @@ public class SimpleDateFormat extends DateFormat { // 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()); } diff --git a/src/share/classes/java/util/Calendar.java b/src/share/classes/java/util/Calendar.java index 51ec6becb559aad656cd12174337170818601a79..21de73437a4d226cc6eaecf53055e6d7b7a02da4 100644 --- a/src/share/classes/java/util/Calendar.java +++ b/src/share/classes/java/util/Calendar.java @@ -2705,7 +2705,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable, V> extends AbstractMap /** * 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); diff --git a/src/share/classes/java/util/Properties.java b/src/share/classes/java/util/Properties.java index 1cd19a0e40e94875d09368ae18d360e82e5cb163..7c7e13b6a9dc0a6539aef1a2570b09b35d11fa7b 100644 --- a/src/share/classes/java/util/Properties.java +++ b/src/share/classes/java/util/Properties.java @@ -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.io.BufferedWriter; import java.lang.reflect.*; /** - * The Properties class represents a persistent set of - * properties. The Properties 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. *

    @@ -46,17 +46,17 @@ import java.lang.reflect.*; * "defaults"; this second property list is searched if * the property key is not found in the original property list. *

    - * Because Properties inherits from Hashtable, the - * put and putAll methods can be applied to a - * Properties 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 - * Strings. The setProperty method should be used - * instead. If the store or save method is called - * on a "compromised" Properties object that contains a - * non-String key or value, the call will fail. Similarly, - * the call to the propertyNames or list method - * will fail if it is called on a "compromised" Properties - * object that contains a non-String 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. * *

    * The {@link #load(java.io.Reader) load(Reader)} / @@ -146,15 +146,15 @@ class Properties extends Hashtable { } /** - * Calls the Hashtable method put. Provided for + * Calls the Hashtable method {@code put}. Provided for * parallelism with the getProperty method. Enforces use of * strings for property keys and values. The value returned is the - * result of the Hashtable call to put. + * result of the Hashtable call to {@code put}. * * @param key the key to be placed into this property list. * @param value the value corresponding to key. * @return the previous value of the specified key in this property - * list, or null 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 @@ class Properties extends Hashtable { * kinds of line, natural lines and logical lines. * A natural line is defined as a line of * characters that is terminated either by a set of line terminator - * characters (\n or \r or \r\n) + * 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 - * \. 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 @@ class Properties extends Hashtable { *

    * A natural line that contains only white space characters is * considered blank and is ignored. A comment line has an ASCII - * '#' or '!' 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 - * (' ', '\u0020'), tab - * ('\t', '\u0009'), and form feed - * ('\f', '\u000C') to be white + * ({@code ' '}, {@code '\u005Cu0020'}), tab + * ({@code '\t'}, {@code '\u005Cu0009'}), and form feed + * ({@code '\f'}, {@code '\u005Cu000C'}) to be white * space. * *

    @@ -215,31 +215,31 @@ class Properties extends Hashtable { *

    * 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 '=', - * ':', 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,

    * - * \:\=

    + * {@code \:\=}

    * - * would be the two-character key ":=". Line - * terminator characters can be included using \r and - * \n 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 '=' or ':', 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 - * "". 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. * *

    * As an example, each of the following three lines specifies the key - * "Truth" and the associated element value - * "Beauty": + * {@code "Truth"} and the associated element value + * {@code "Beauty"}: *

    *

          * Truth = Beauty
    @@ -254,11 +254,11 @@ class Properties extends Hashtable {
          *                                  cantaloupe, watermelon, \
          *                                  kiwi, mango
          * 
    - * The key is "fruits" and the associated element is: + * The key is {@code "fruits"} and the associated element is: *

    *

    "apple, banana, pear, cantaloupe, watermelon, kiwi, mango"
    - * Note that a space appears before each \ so that a space - * will appear after each comma in the final result; the \, + * 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 not replaced by one or more other * characters. @@ -267,8 +267,8 @@ class Properties extends Hashtable { *

    *

    cheeses
          * 
    - * specifies that the key is "cheeses" and the associated - * element is the empty string "".

    + * specifies that the key is {@code "cheeses"} and the associated + * element is the empty string {@code ""}.

    *

    * * @@ -283,17 +283,17 @@ class Properties extends Hashtable { *

      *
    • Octal escapes are not recognized. * - *
    • The character sequence \b does not + *
    • The character sequence {@code \b} does not * represent a backspace character. * *
    • The method does not treat a backslash character, - * \, 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 "\z" 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 "\b" as equivalent to the single - * character 'b'. + * sequence {@code "\b"} as equivalent to the single + * character {@code 'b'}. * *
    • Escapes are not necessary for single and double quotes; * however, by the rule above, single and double quote characters @@ -689,20 +689,20 @@ class Properties extends Hashtable { } /** - * Calls the store(OutputStream out, String comments) 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 store(OutputStream out, - * String comments) method or the - * storeToXML(OutputStream os, String comment) 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 Properties object + * @exception ClassCastException if this {@code Properties} object * contains any keys or values that are not - * Strings. + * {@code Strings}. */ @Deprecated public void save(OutputStream out, String comments) { @@ -714,37 +714,37 @@ class Properties extends Hashtable { /** * Writes this property list (key and element pairs) in this - * Properties 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. *

      - * Properties from the defaults table of this Properties + * Properties from the defaults table of this {@code Properties} * table (if any) are not written out by this method. *

      - * If the comments argument is not null, then an ASCII # + * 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 comments 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 Writer - * and if the next character in comments is not character # or - * character ! then an ASCII # 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. *

      * Next, a comment line is always written, consisting of an ASCII - * # character, the current date and time (as if produced - * by the toString method of Date for the - * current time), and a line separator as generated by the Writer. + * {@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}. *

      - * Then every entry in this Properties 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 =, then the associated + * written, then an ASCII {@code =}, then the associated * element string. For the key, all space characters are - * written with a preceding \ 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 \ - * character. The key and element characters #, - * !, =, and : 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. *

      * After the entries have been written, the output stream is flushed. @@ -755,9 +755,9 @@ class Properties extends Hashtable { * @param comments a description of the property list. * @exception IOException if writing this property list to the specified * output stream throws an IOException. - * @exception ClassCastException if this Properties object - * contains any keys or values that are not Strings. - * @exception NullPointerException if writer 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 @@ class Properties extends Hashtable { /** * Writes this property list (key and element pairs) in this - * Properties table to the output stream in a format suitable - * for loading into a Properties 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. *

      - * Properties from the defaults table of this Properties + * Properties from the defaults table of this {@code Properties} * table (if any) are not written out by this method. *

      * This method outputs the comments, properties keys and values in @@ -786,12 +786,12 @@ class Properties extends Hashtable { *

    • The stream is written using the ISO 8859-1 character encoding. * *
    • Characters not in Latin-1 in the comments are written as - * \uxxxx for their appropriate unicode + * {@code \u005Cu}xxxx for their appropriate unicode * hexadecimal value xxxx. * - *
    • Characters less than \u0020 and characters greater - * than \u007E in property keys or values are written - * as \uxxxx for the appropriate hexadecimal + *
    • Characters less than {@code \u005Cu0020} and characters greater + * than {@code \u005Cu007E} in property keys or values are written + * as {@code \u005Cu}xxxx for the appropriate hexadecimal * value xxxx. *
    *

    @@ -802,9 +802,9 @@ class Properties extends Hashtable { * @param comments a description of the property list. * @exception IOException if writing this property list to the specified * output stream throws an IOException. - * @exception ClassCastException if this Properties object - * contains any keys or values that are not Strings. - * @exception NullPointerException if out 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 @@ class Properties extends Hashtable { * results in an IOException. * @throws InvalidPropertiesFormatException Data on input stream does not * constitute a valid XML document with the mandated document type. - * @throws NullPointerException if in is null. + * @throws NullPointerException if {@code in} is null. * @see #storeToXML(OutputStream, String, String) * @since 1.5 */ @@ -879,14 +879,14 @@ class Properties extends Hashtable { * props.storeToXML(os, comment, "UTF-8");. * * @param os the output stream on which to emit the XML document. - * @param comment a description of the property list, or null + * @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 IOException. - * @throws NullPointerException if os is null. - * @throws ClassCastException if this Properties object + * @throws NullPointerException if {@code os} is null. + * @throws ClassCastException if this {@code Properties} object * contains any keys or values that are not - * Strings. + * {@code Strings}. * @see #loadFromXML(InputStream) * @since 1.5 */ @@ -907,13 +907,13 @@ class Properties extends Hashtable { * <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> * * - *

    If the specified comment is null then no comment + *

    If the specified comment is {@code null} then no comment * will be stored in the document. * *

    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 null + * @param comment a description of the property list, or {@code null} * if no comment is desired. * @param encoding the name of a supported * @@ -921,11 +921,11 @@ class Properties extends Hashtable { * * @throws IOException if writing to the specified output stream * results in an IOException. - * @throws NullPointerException if os is null, - * or if encoding is null. - * @throws ClassCastException if this Properties 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 - * Strings. + * {@code Strings}. * @see #loadFromXML(InputStream) * @since 1.5 */ @@ -941,7 +941,7 @@ class Properties extends Hashtable { * 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 - * null 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. diff --git a/src/share/classes/java/util/concurrent/FutureTask.java b/src/share/classes/java/util/concurrent/FutureTask.java index 45c91d062ea5d0a307705b1b4443cc20d6fdd843..e9b6e053dd07ea83772a7a9113e10cf271d3eac8 100644 --- a/src/share/classes/java/util/concurrent/FutureTask.java +++ b/src/share/classes/java/util/concurrent/FutureTask.java @@ -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 get - * 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}). * - *

    A FutureTask can be used to wrap a {@link Callable} or - * {@link java.lang.Runnable} object. Because FutureTask - * implements Runnable, a FutureTask can be - * submitted to an {@link Executor} for execution. + *

    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. * *

    In addition to serving as a standalone class, this class provides - * protected 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 The result type returned by this FutureTask's get method + * @param The result type returned by this FutureTask's {@code get} methods */ public class FutureTask implements RunnableFuture { - /** 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. + */ + + /** + * 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 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 FutureTask that will, upon running, execute the - * given Callable. + * 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 callable) { if (callable == null) throw new NullPointerException(); - sync = new Sync(callable); + this.callable = callable; + this.state = NEW; // ensure visibility of callable } /** - * Creates a FutureTask that will, upon running, execute the - * given Runnable, and arrange that get 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 @@ public class FutureTask implements RunnableFuture { * you don't need a particular result, consider using * constructions of the form: * {@code Future f = new FutureTask(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 class FutureTask implements RunnableFuture { */ 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 - * isDone (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 @@ public class FutureTask implements RunnableFuture { 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 run method + * + *

    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 ExecutionException - * 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 run method + * + *

    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 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 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; } /** - * Synchronization control for FutureTask. Note that this must be - * a non-static inner class in order to invoke the protected - * done method. For clarity, all inner class support - * methods are same as outer, prefixed with "inner". - * - * Uses AQS sync state to represent run status + * Ensures that any interrupt from a possible cancel(true) is only + * delivered to a task while in run or runAndReset. */ - 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 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 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; - } + 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(); + } - 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; - } + /** + * 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(); } + } - 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; - } - if (compareAndSetState(s, RAN)) { - result = v; - releaseShared(0); - done(); - return; + /** + * Removes and signals all waiting threads, invokes done(), and + * nulls out callable. + */ + 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; } + 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; + int s = state; + if (s > COMPLETING) { + if (q != null) + q.thread = null; + return s; } - if (mayInterruptIfRunning) { - Thread r = runner; - if (r != null) - r.interrupt(); + 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; + } + LockSupport.parkNanos(this, nanos); } - releaseShared(0); - done(); - return true; + else + LockSupport.park(this); } + } - 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; + /** + * 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; } - set(result); - } else { - releaseShared(0); // cancel + break; } } + } - 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; - } + // 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); } } + } diff --git a/src/share/classes/javax/crypto/Cipher.java b/src/share/classes/javax/crypto/Cipher.java index 8aa8b182d75b1bf973c27ccecc14bd5f76ab8da7..408d9b91172ea88793d3e907834e22bc772a7ff4 100644 --- a/src/share/classes/javax/crypto/Cipher.java +++ b/src/share/classes/javax/crypto/Cipher.java @@ -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 @@ public class Cipher { return matches(regexp, value) ? S_YES : S_NO; } - // Map for previously compiled patterns - // XXX use ConcurrentHashMap once available - private final static Map patternCache = - Collections.synchronizedMap(new HashMap()); + // ConcurrentMap for previously compiled patterns + private final static ConcurrentMap patternCache = + new ConcurrentHashMap(); 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(); } diff --git a/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java b/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java index c4b1e4d912052b3f818971459645ff71ef94e5d7..f05be51c14f9759d11c30f9496e2601fbff338cd 100644 --- a/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java +++ b/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java @@ -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 @@ public class SQLInputImpl implements SQLInput { "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 diff --git a/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java b/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java index 2217e4e2cab9e870d597665565525994cd4a10c1..b46a880bd08562fefd65d7967084378b10d0f9bb 100644 --- a/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java +++ b/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java @@ -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 @@ public class SQLOutputImpl implements SQLOutput { * 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 @@ public class SQLOutputImpl implements SQLOutput { @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 @@ public class SQLOutputImpl implements SQLOutput { @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 @@ public class SQLOutputImpl implements SQLOutput { @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 @@ public class SQLOutputImpl implements SQLOutput { @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 @@ public class SQLOutputImpl implements SQLOutput { @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)); - } diff --git a/src/share/classes/javax/sql/rowset/serial/SerialStruct.java b/src/share/classes/javax/sql/rowset/serial/SerialStruct.java index a9462eb8688bab6b4a3324aa474fae746cd46a9b..74d54bbeda1d944138e5a5f195a11eb251747217 100644 --- a/src/share/classes/javax/sql/rowset/serial/SerialStruct.java +++ b/src/share/classes/javax/sql/rowset/serial/SerialStruct.java @@ -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 java.sql.*; 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 @@ public class SerialStruct implements Struct, Serializable, Cloneable { * @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 class SerialStruct implements Struct, Serializable, Cloneable { public Object[] getAttributes(Map> map) throws SerialException { - return attribs; + Object[] val = this.attribs; + return (val == null) ? null : Arrays.copyOf(val, val.length); } diff --git a/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java b/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java index af901795fb4c6cdde83527100a72db72595c3849..a47375fddbf73ef3e2e4fd3092025562b96495dc 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java @@ -1115,9 +1115,8 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) { Rectangle tabRect = rects[tabIndex]; - String propKey = (isSelected ? "selectedLabelShift" : "labelShift"); - int nudge = DefaultLookup.getInt( - tabPane, this, "TabbedPane." + propKey, 1); + int nudge = (isSelected ? DefaultLookup.getInt(tabPane, this, "TabbedPane.selectedLabelShift", -1) : + DefaultLookup.getInt(tabPane, this, "TabbedPane.labelShift", 1)); switch (tabPlacement) { case BOTTOM: diff --git a/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java b/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java index e9ca8ca6349ac098dd9cfe73a27511ed39e58c3f..cfe0c4fa7d2dd01ffc731e8c9e0f418fc059e351 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java @@ -447,10 +447,20 @@ public class SynthComboBoxUI extends BasicComboBoxUI implements private class SynthComboBoxRenderer extends JLabel implements ListCellRenderer, UIResource { public SynthComboBoxRenderer() { super(); - setName("ComboBox.renderer"); setText(" "); } + @Override + public String getName() { + // SynthComboBoxRenderer should have installed Name while constructor is working. + // The setName invocation in the SynthComboBoxRenderer() constructor doesn't work + // because of the opaque property is installed in the constructor based on the + // component name (see GTKStyle.isOpaque()) + String name = super.getName(); + + return name == null ? "ComboBox.renderer" : name; + } + @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { diff --git a/src/share/classes/sun/awt/OSInfo.java b/src/share/classes/sun/awt/OSInfo.java index c8cce594b63921fd86e912cde147dff4f158e732..58dd6cc1fd0606ec573069ee4bfd0b599d09e463 100644 --- a/src/share/classes/sun/awt/OSInfo.java +++ b/src/share/classes/sun/awt/OSInfo.java @@ -39,6 +39,7 @@ public class OSInfo { WINDOWS, LINUX, SOLARIS, + MACOSX, UNKNOWN } @@ -100,6 +101,10 @@ public class OSInfo { return SOLARIS; } + if (osName.startsWith("Mac OS X")) { + return MACOSX; + } + // determine another OS here } diff --git a/src/share/classes/sun/security/ssl/EngineArgs.java b/src/share/classes/sun/security/ssl/EngineArgs.java index f91e8cc4d8d9446b7f5a3f3d92a1f6f2ce212afe..5f89d0c73b762a84c0d80de7751e818eb64294ea 100644 --- a/src/share/classes/sun/security/ssl/EngineArgs.java +++ b/src/share/classes/sun/security/ssl/EngineArgs.java @@ -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 @@ class EngineArgs { 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 @@ class EngineArgs { /* * 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]); } } diff --git a/src/share/classes/sun/security/ssl/SSLEngineImpl.java b/src/share/classes/sun/security/ssl/SSLEngineImpl.java index 8616a71ef13286d3cb2e84162c83b23eb255928e..f9b1386587c297a7d96db72ec396a322ee8ce256 100644 --- a/src/share/classes/sun/security/ssl/SSLEngineImpl.java +++ b/src/share/classes/sun/security/ssl/SSLEngineImpl.java @@ -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 @@ final public class SSLEngineImpl extends SSLEngine { ea.resetPos(); fatal(Alerts.alert_internal_error, - "problem unwrapping net record", e); + "problem wrapping app data", e); return null; // make compiler happy } finally { /* diff --git a/src/solaris/classes/sun/awt/X11/XWindowPeer.java b/src/solaris/classes/sun/awt/X11/XWindowPeer.java index 9d7daf0889e2351885423856469d11c28c50c49a..9ce07cdbb3476eaa088aa9a40727e5b26bdfb0a5 100644 --- a/src/solaris/classes/sun/awt/X11/XWindowPeer.java +++ b/src/solaris/classes/sun/awt/X11/XWindowPeer.java @@ -255,6 +255,21 @@ class XWindowPeer extends XPanelPeer implements WindowPeer, } } + if (owner != null || isSimpleWindow()) { + XNETProtocol protocol = XWM.getWM().getNETProtocol(); + if (protocol != null && protocol.active()) { + XToolkit.awtLock(); + try { + XAtomList net_wm_state = getNETWMState(); + net_wm_state.add(protocol.XA_NET_WM_STATE_SKIP_TASKBAR); + setNETWMState(net_wm_state); + } finally { + XToolkit.awtUnlock(); + } + + } + } + // Init warning window(for applets) if (((Window)target).getWarningString() != null) { // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip @@ -480,14 +495,6 @@ class XWindowPeer extends XPanelPeer implements WindowPeer, bounds.x, bounds.y, bounds.width, bounds.height); XWM.setMotifDecor(this, false, 0, 0); - XNETProtocol protocol = XWM.getWM().getNETProtocol(); - if (protocol != null && protocol.active()) { - XAtomList net_wm_state = getNETWMState(); - net_wm_state.add(protocol.XA_NET_WM_STATE_SKIP_TASKBAR); - setNETWMState(net_wm_state); - } - - boolean isResized = !bounds.getSize().equals(oldBounds.getSize()); boolean isMoved = !bounds.getLocation().equals(oldBounds.getLocation()); if (isMoved || isResized) { diff --git a/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java b/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java index 632089e2fae3f742151c2801798c1084c16bc21e..4bf55cdf41e3d3a4c0c52a342ccea6b01670f234 100644 --- a/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java +++ b/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java @@ -37,8 +37,12 @@ import java.util.Properties; * 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. and .attach_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 @@ public class LinuxVirtualMachine extends HotSpotVirtualMachine { } // Return the socket file for the given process. - // Checks working directory of process for .java_pid. If not - // found it looks in temp directory. private String findSocketFile(int pid) { - // First check for a .java_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 diff --git a/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java b/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java index d40f8a709ab3e4c8cbaefefe8f6aff9d8d547fc8..cb8a3f16a3f6ecb30f5be28853a2e2d4d75a52f0 100644 --- a/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java +++ b/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java @@ -38,11 +38,12 @@ import java.util.Properties; * 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. and .attach_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 @@ public class SolarisVirtualMachine extends HotSpotVirtualMachine { } } - // The door is attached to .java_pid in the target VM's working - // directory or temporary directory. + // The door is attached to .java_pid in the temporary directory. private int openDoor(int pid) throws IOException { - // First check for a .java_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 diff --git a/src/solaris/native/java/lang/UNIXProcess_md.c b/src/solaris/native/java/lang/UNIXProcess_md.c index a10e3ac77016e903586c90ca8fdc196c6fe249cd..aa8112dbf400456a9c42379643e6329fb25f0465 100644 --- a/src/solaris/native/java/lang/UNIXProcess_md.c +++ b/src/solaris/native/java/lang/UNIXProcess_md.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/solaris/native/java/lang/java_props_md.c b/src/solaris/native/java/lang/java_props_md.c index 0a24f8653dbb334417e2b987abb68d65a76586d7..974e4dbb3ac13941e784a2e9d496dbef3550992d 100644 --- a/src/solaris/native/java/lang/java_props_md.c +++ b/src/solaris/native/java/lang/java_props_md.c @@ -310,7 +310,7 @@ static int ParseLocale(int cat, char ** std_language, char ** std_script, } #ifdef JAVASE_EMBEDDED -/* Determine the default embedded toolkit based on whether lib/xawt/ +/* Determine the default embedded toolkit based on whether libawt_xawt * exists in the JRE. This can still be overridden by -Dawt.toolkit=XXX */ static char* getEmbeddedToolkit() { @@ -325,8 +325,8 @@ static char* getEmbeddedToolkit() { realpath((char *)dlinfo.dli_fname, buf); len = strlen(buf); p = strrchr(buf, '/'); - /* Default AWT Toolkit on Linux and Solaris is XAWT. */ - strncpy(p, "/xawt/", MAXPATHLEN-len-1); + /* Default AWT Toolkit on Linux and Solaris is XAWT (libawt_xawt.so). */ + strncpy(p, "/libawt_xawt.so", MAXPATHLEN-len-1); /* Check if it exists */ if (stat(buf, &statbuf) == -1 && errno == ENOENT) { /* No - this is a reduced-headless-jre so use special HToolkit */ diff --git a/src/solaris/native/sun/awt/awt_LoadLibrary.c b/src/solaris/native/sun/awt/awt_LoadLibrary.c index fa75aa2d053a409f286af62fc9b8b6af8790e1c8..5a070a6ff02900103a680f8643fc1d2764243427 100644 --- a/src/solaris/native/sun/awt/awt_LoadLibrary.c +++ b/src/solaris/native/sun/awt/awt_LoadLibrary.c @@ -105,7 +105,7 @@ AWT_OnLoad(JavaVM *vm, void *reserved) /* * The code below is responsible for: - * 1. Loading appropriate awt library, i.e. xawt/libmawt or headless/libwawt + * 1. Loading appropriate awt library, i.e. libawt_xawt or libawt_headless * 2. Setting "awt.toolkit" system property to use the appropriate Java toolkit class, * (if user has specified the toolkit in env varialble) */ @@ -130,10 +130,10 @@ AWT_OnLoad(JavaVM *vm, void *reserved) /* Calculate library name to load */ if (AWTIsHeadless()) { - strncpy(p, "/headless/libmawt.so", MAXPATHLEN-len-1); + strncpy(p, "/libawt_headless.so", MAXPATHLEN-len-1); } else { /* Default AWT Toolkit on Linux and Solaris is XAWT. */ - strncpy(p, "/xawt/libmawt.so", MAXPATHLEN-len-1); + strncpy(p, "/libawt_xawt.so", MAXPATHLEN-len-1); } if (toolkit) { @@ -161,7 +161,7 @@ JNI_OnLoad(JavaVM *vm, void *reserved) /* * This entry point must remain in libawt.so as part of a contract * with the CDE variant of Java Media Framework. (sdtjmplay) - * Reflect this call over to the correct libmawt.so. + * Reflect this call over to the correct libawt_.so. */ JNIEXPORT void JNICALL Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this, @@ -191,7 +191,7 @@ Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this, /* * This entry point must remain in libawt.so as part of a contract * with the CDE variant of Java Media Framework. (sdtjmplay) - * Reflect this call over to the correct libmawt.so. + * Reflect this call over to the correct libawt_.so. */ JNIEXPORT void JNICALL Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jargv) @@ -250,7 +250,7 @@ return_type name arglist \ /* * These entry point must remain in libawt.so ***for Java Plugin ONLY*** - * Reflect this call over to the correct libmawt.so. + * Reflect this call over to the correct libawt_.so. */ REFLECT_VOID_FUNCTION(getAwtLockFunctions, diff --git a/test/Makefile b/test/Makefile index 2ebaf24867b03cbbafe4d0e96cf34835e1d195a9..75979ce82f1091d63afaf683d1022c0dddd70aca 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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_security2: $(call TestDirs, javax/crypto javax/xml/crypto com/sun/crypto) 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) diff --git a/test/ProblemList.txt b/test/ProblemList.txt index 2f4d91ee17619541dad1ea5f17cdfeb4265bfce5..7e59e1d21adfceddfc73394fa001582dca7fe180 100644 --- a/test/ProblemList.txt +++ b/test/ProblemList.txt @@ -476,6 +476,9 @@ java/rmi/server/RMISocketFactory/useSocketFactory/activatable/UseCustomSocketFac 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 @@ sun/tools/jps/jps-Vvml.sh generic-all # 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 diff --git a/test/tools/launcher/SomeException.java b/test/java/beans/Introspector/7122138/Test7122138.java similarity index 62% rename from test/tools/launcher/SomeException.java rename to test/java/beans/Introspector/7122138/Test7122138.java index 5454e1afa42dd54d993ac2c3df480201fa1c21b2..6832304d0a9dec9ac0ce0f900c3e25300715db43 100644 --- a/test/tools/launcher/SomeException.java +++ b/test/java/beans/Introspector/7122138/Test7122138.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -22,11 +22,24 @@ */ /* - * - * - * Used by unresolvedExceptions.sh + * @test + * @bug 7122138 + * @summary Tests generic methods reflection + * @author Sergey Malenkov + * @library .. */ -public class SomeException extends RuntimeException { +import pack.Sub; + +public class Test7122138 { + public static void main(String[] args) throws Exception { + Class type = Sub.class; + Sub object = type.newInstance(); + String name = "name"; + BeanUtils.getPropertyDescriptor(type, name).getWriteMethod().invoke(object, name); + if (!name.equals(object.getName())) { + throw new Error("name is not set"); + } + } } diff --git a/test/java/beans/Introspector/7122138/pack/Sub.java b/test/java/beans/Introspector/7122138/pack/Sub.java new file mode 100644 index 0000000000000000000000000000000000000000..b30d13224643ffd9fb4aad9cb5e6da0cfed455e9 --- /dev/null +++ b/test/java/beans/Introspector/7122138/pack/Sub.java @@ -0,0 +1,4 @@ +package pack; + +public class Sub extends Super { +} diff --git a/test/java/beans/Introspector/7122138/pack/Super.java b/test/java/beans/Introspector/7122138/pack/Super.java new file mode 100644 index 0000000000000000000000000000000000000000..77359680d7c4435da3f3f2eb154710980b60b767 --- /dev/null +++ b/test/java/beans/Introspector/7122138/pack/Super.java @@ -0,0 +1,14 @@ +package pack; + +class Super { + + T name; + + public void setName(T name) { + this.name = name; + } + + public T getName() { + return name; + } +} diff --git a/test/java/lang/Integer/Unsigned.java b/test/java/lang/Integer/Unsigned.java new file mode 100644 index 0000000000000000000000000000000000000000..c7b831d65feb0ca9345802cb6318b90d785f178a --- /dev/null +++ b/test/java/lang/Integer/Unsigned.java @@ -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; + } +} diff --git a/test/java/lang/Long/Unsigned.java b/test/java/lang/Long/Unsigned.java new file mode 100644 index 0000000000000000000000000000000000000000..22e50e61dae32db4fab39edccd6e92b065eb8418 --- /dev/null +++ b/test/java/lang/Long/Unsigned.java @@ -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; + } +} diff --git a/test/java/text/Format/DateFormat/Bug7130335.java b/test/java/text/Format/DateFormat/Bug7130335.java new file mode 100644 index 0000000000000000000000000000000000000000..bd00c117f25e89f5bbec0b4118a5587f4c49a142 --- /dev/null +++ b/test/java/text/Format/DateFormat/Bug7130335.java @@ -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); + } + } +} diff --git a/test/java/util/Calendar/Bug7017458.java b/test/java/util/Calendar/Bug7017458.java new file mode 100644 index 0000000000000000000000000000000000000000..e516b8bc6c0b05301f1f1831c959a0af9b8e72d4 --- /dev/null +++ b/test/java/util/Calendar/Bug7017458.java @@ -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; + } + } + } +} + diff --git a/test/java/util/Currency/tablea1.txt b/test/java/util/Currency/tablea1.txt index 8b2e1b5871f2faabe0ec66fef817f28e7f64494c..240fcb844efd2ed95c14a1fffbf1f06d141f44c1 100644 --- a/test/java/util/Currency/tablea1.txt +++ b/test/java/util/Currency/tablea1.txt @@ -1,12 +1,12 @@ # # -# Based on BSi's ISO4217 data - "TABLE A1.doc" + amendments up until MA151.doc -# (As of 7 April 2011) +# Based on BSi's ISO4217 data - "TABLE A1.doc" + amendments up until MA153.doc +# (As of 12 January 2012) # # Version FILEVERSION=1 -DATAVERSION=151 +DATAVERSION=153 # ISO 4217 currency data AF AFN 971 2 @@ -267,7 +267,7 @@ UY UYU 858 2 UZ UZS 860 2 VU VUV 548 0 VE VEF 937 2 -VN VND 704 2 +VN VND 704 0 VG USD 840 2 VI USD 840 2 WF XPF 953 0 diff --git a/test/java/util/EnumMap/UniqueNullValue.java b/test/java/util/EnumMap/UniqueNullValue.java new file mode 100644 index 0000000000000000000000000000000000000000..0f7be4dd8af1e70acbf54e9f685cbac7283416bc --- /dev/null +++ b/test/java/util/EnumMap/UniqueNullValue.java @@ -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 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"); + } + } +} diff --git a/test/java/util/concurrent/FutureTask/DoneTimedGetLoops.java b/test/java/util/concurrent/FutureTask/DoneTimedGetLoops.java new file mode 100644 index 0000000000000000000000000000000000000000..c1b81c286afcdc32d0ef4a3751cecb790665502f --- /dev/null +++ b/test/java/util/concurrent/FutureTask/DoneTimedGetLoops.java @@ -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 { + 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 normalRef + = new AtomicReference(); + final AtomicReference abnormalRef + = new AtomicReference(); + + 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");} +} diff --git a/test/java/util/concurrent/FutureTask/ExplicitSet.java b/test/java/util/concurrent/FutureTask/ExplicitSet.java new file mode 100644 index 0000000000000000000000000000000000000000..bd939e6c4196c73f09a2cfd9ec5b15a6a644e9a0 --- /dev/null +++ b/test/java/util/concurrent/FutureTask/ExplicitSet.java @@ -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 { + SettableTask() { + super(new Callable() { + 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");} +} diff --git a/test/javax/swing/JComboBox/7082443/bug7082443.java b/test/javax/swing/JComboBox/7082443/bug7082443.java new file mode 100644 index 0000000000000000000000000000000000000000..747e57a56abc45cdc6bc18558d14b5776158bbdf --- /dev/null +++ b/test/javax/swing/JComboBox/7082443/bug7082443.java @@ -0,0 +1,81 @@ +/* + * 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 7082443 + * @summary JComboBox not backward compatible (with Java 6) + * @author Pavel Porvatov + */ + +import javax.swing.*; +import java.awt.*; + +public class bug7082443 { + public static final String GTK_LAF_CLASS = "GTKLookAndFeel"; + + public static void main(String[] args) throws Exception { + for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) { + if (lookAndFeelInfo.getClassName().contains(GTK_LAF_CLASS)) { + UIManager.setLookAndFeel(lookAndFeelInfo.getClassName()); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + TestComboBox testComboBox = new TestComboBox(); + + if (testComboBox.isOldRendererOpaque()) { + System.out.println("Passed for " + GTK_LAF_CLASS); + } else { + throw new RuntimeException("Failed for " + GTK_LAF_CLASS); + } + } + }); + + return; + } + } + + System.out.println(GTK_LAF_CLASS + " is not found. The test skipped"); + } + + private static class TestComboBox extends JComboBox { + private final ListCellRenderer renderer = new ListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, + boolean isSelected, boolean cellHasFocus) { + return TestComboBox.super.getRenderer().getListCellRendererComponent(list, value, index, + isSelected, cellHasFocus); + } + }; + + @Override + public ListCellRenderer getRenderer() { + return renderer; + } + + public boolean isOldRendererOpaque() { + return ((JLabel) super.getRenderer()).isOpaque(); + } + } +} + diff --git a/test/javax/swing/JList/6462008/bug6462008.java b/test/javax/swing/JList/6462008/bug6462008.java new file mode 100644 index 0000000000000000000000000000000000000000..9e009cc0369fb8655b737a7734eef0a7bb8f795e --- /dev/null +++ b/test/javax/swing/JList/6462008/bug6462008.java @@ -0,0 +1,415 @@ +/* + * 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 6462008 + * @summary Tests that mouse/keyboard work properly on JList with lead < 0 or > list.getModel().getSize() + * @author Shannon Hickey + * @run main bug6462008 + */ +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.util.*; +import sun.awt.SunToolkit; + +public class bug6462008 { + + private static final int DONT_CARE = -2; + private static int anchorLead; + private static boolean isAquaLAF; + private static int controlKey; + private static JList list; + private static SunToolkit toolkit; + private static Robot robot; + + public static void main(String[] args) throws Exception { + toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + robot = new Robot(); + robot.setAutoDelay(100); + + isAquaLAF = "Aqua".equals(UIManager.getLookAndFeel().getID()); + controlKey = isAquaLAF ? KeyEvent.VK_META : KeyEvent.VK_CONTROL; + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + setAnchorLead(-1); + toolkit.realSync(); + + testListSelection(); + + setAnchorLead(100); + toolkit.realSync(); + + testListSelection(); + } + + public static void testListSelection() throws Exception { + + // Space + robot.keyPress(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SPACE); + + toolkit.realSync(); + checkSelection(); + resetList(); + toolkit.realSync(); + + // Control + Space + robot.keyPress(KeyEvent.VK_CONTROL); + robot.keyPress(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_CONTROL); + + toolkit.realSync(); + checkSelection(); + resetList(); + toolkit.realSync(); + + // Shift + Space + robot.keyPress(KeyEvent.VK_SHIFT); + robot.keyPress(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SHIFT); + + toolkit.realSync(); + checkSelection(); + resetList(); + toolkit.realSync(); + + // Control + Shift + Space + robot.keyPress(KeyEvent.VK_CONTROL); + robot.keyPress(KeyEvent.VK_SHIFT); + robot.keyPress(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SHIFT); + robot.keyRelease(KeyEvent.VK_CONTROL); + + toolkit.realSync(); + checkSelection(); + resetList(); + toolkit.realSync(); + + + // Control + A Multiple Selection + + robot.keyPress(controlKey); + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_A); + robot.keyRelease(controlKey); + + toolkit.realSync(); + checkSelectionAL(-1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); + resetList(); + setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + toolkit.realSync(); + + // Control + A Single Selection + robot.keyPress(controlKey); + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_A); + robot.keyRelease(controlKey); + + toolkit.realSync(); + checkSelectionAL(0, 0, 0); + resetList(); + setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + setSelectionInterval(5, 5); + toolkit.realSync(); + + + // Control + A Selection interval (5, 5) + robot.keyPress(controlKey); + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_A); + robot.keyRelease(controlKey); + + toolkit.realSync(); + checkSelection(5); + resetList(); + toolkit.realSync(); + + // Page Down + // Not applicable for the Aqua L&F + if (!isAquaLAF) { + robot.keyPress(KeyEvent.VK_PAGE_DOWN); + robot.keyRelease(KeyEvent.VK_PAGE_DOWN); + + toolkit.realSync(); + checkSelection(9, 9, 9); + resetList(); + toolkit.realSync(); + } + + // Shift + Page Down + /* + * We really want to use robot here, but there seems to be a bug in AWT's + * robot implementation (see 6463168). For now, we'll invoke the action + * directly instead. When the bug is fixed, we'll use the following four + * lines instead: + * robot.keyPress(KeyEvent.VK_SHIFT); + * robot.keyPress(KeyEvent.VK_PAGE_DOWN); + * robot.keyRelease(KeyEvent.VK_PAGE_DOWN); + * robot.keyRelease(KeyEvent.VK_SHIFT); + */ + + scrollDownExtendSelection(); + + toolkit.realSync(); + checkSelection(0, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); + resetList(); + toolkit.realSync(); + + // Down + robot.keyPress(KeyEvent.VK_DOWN); + robot.keyRelease(KeyEvent.VK_DOWN); + + toolkit.realSync(); + checkSelectionAL(0, 0, 0); + resetList(); + toolkit.realSync(); + + // L + robot.keyPress(KeyEvent.VK_L); + robot.keyRelease(KeyEvent.VK_L); + + toolkit.realSync(); + checkSelectionAL(0, 0, 0); + resetList(); + toolkit.realSync(); + + // Click item 4 + Point p = clickItem4(); + robot.mouseMove(p.x, p.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + + toolkit.realSync(); + checkSelectionAL(4, 4, 4); + resetList(); + toolkit.realSync(); + + + // Control + Click item 4 + robot.keyPress(controlKey); + p = clickItem4(); + robot.mouseMove(p.x, p.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.keyRelease(controlKey); + + + toolkit.realSync(); + checkSelectionAL(4, 4, 4); + resetList(); + toolkit.realSync(); + + // Shift + Click item 4 + robot.keyPress(KeyEvent.VK_SHIFT); + p = clickItem4(); + robot.mouseMove(p.x, p.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.keyRelease(KeyEvent.VK_SHIFT); + + + toolkit.realSync(); + checkSelectionAL(0, 4, 0, 1, 2, 3, 4); + resetList(); + toolkit.realSync(); + + + // Control + Shift + Click item 4 + robot.keyPress(controlKey); + robot.keyPress(KeyEvent.VK_SHIFT); + p = clickItem4(); + robot.mouseMove(p.x, p.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.keyRelease(KeyEvent.VK_SHIFT); + robot.keyRelease(controlKey); + + toolkit.realSync(); + checkSelectionAL(0, 4); + resetList(); + toolkit.realSync(); + } + + private static DefaultListModel getModel() { + DefaultListModel listModel = new DefaultListModel(); + for (int i = 0; i < 10; i++) { + listModel.addElement("List Item " + i); + } + return listModel; + } + + private static Point clickItem4() throws Exception { + + final Point[] result = new Point[1]; + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + Rectangle r = list.getCellBounds(4, 4); + Point p = new Point(r.x + r.width / 2, r.y + r.height / 2); + SwingUtilities.convertPointToScreen(p, list); + result[0] = p; + } + }); + + return result[0]; + } + + private static void resetList() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + list.getSelectionModel().clearSelection(); + setAnchorLeadNonThreadSafe(); + } + }); + } + + private static void scrollDownExtendSelection() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + list.getActionMap().get("scrollDownExtendSelection"). + actionPerformed(new ActionEvent(list, + ActionEvent.ACTION_PERFORMED, null)); + } + }); + } + + private static void setSelectionMode(final int selectionMode) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + list.getSelectionModel().setSelectionMode(selectionMode); + setAnchorLeadNonThreadSafe(); + } + }); + } + + private static void setSelectionInterval(final int index0, final int index1) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + list.getSelectionModel().setSelectionInterval(index0, index1); + setAnchorLeadNonThreadSafe(); + } + }); + } + + private static void setAnchorLead(final int anchorLeadValue) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + anchorLead = anchorLeadValue; + setAnchorLeadNonThreadSafe(); + } + }); + } + + private static void setAnchorLeadNonThreadSafe() { + list.getSelectionModel().setAnchorSelectionIndex(anchorLead); + ((DefaultListSelectionModel) list.getSelectionModel()).moveLeadSelectionIndex(anchorLead); + } + + private static void createAndShowGUI() { + JFrame frame = new JFrame("bug6462008"); + frame.setSize(200, 500); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + list = new JList(getModel()); + JPanel panel = new JPanel(new BorderLayout()); + panel.add(list); + frame.getContentPane().add(panel); + + frame.setVisible(true); + } + + private static void checkSelection(int... sels) throws Exception { + checkSelectionAL(DONT_CARE, DONT_CARE, sels); + } + + private static void checkSelectionAL(final int anchor, final int lead, final int... sels) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + checkSelectionNonThreadSafe(anchor, lead, sels); + } + }); + } + + private static void checkSelectionNonThreadSafe(int anchor, int lead, int... sels) { + ListSelectionModel lsm = list.getSelectionModel(); + + int actualAnchor = lsm.getAnchorSelectionIndex(); + int actualLead = lsm.getLeadSelectionIndex(); + + if (anchor != DONT_CARE && actualAnchor != anchor) { + throw new RuntimeException("anchor is " + actualAnchor + ", should be " + anchor); + } + + if (lead != DONT_CARE && actualLead != lead) { + throw new RuntimeException("lead is " + actualLead + ", should be " + lead); + } + + Arrays.sort(sels); + boolean[] checks = new boolean[list.getModel().getSize()]; + for (int i : sels) { + checks[i] = true; + } + + int index0 = Math.min(lsm.getMinSelectionIndex(), 0); + int index1 = Math.max(lsm.getMaxSelectionIndex(), list.getModel().getSize() - 1); + + for (int i = index0; i <= index1; i++) { + if (lsm.isSelectedIndex(i)) { + if (i < 0 || i >= list.getModel().getSize() || !checks[i]) { + throw new RuntimeException(i + " is selected when it should not be"); + } + } else if (i >= 0 && i < list.getModel().getSize() && checks[i]) { + throw new RuntimeException(i + " is supposed to be selected"); + } + } + } +} diff --git a/test/javax/swing/JPopupMenu/4966112/bug4966112.java b/test/javax/swing/JPopupMenu/4966112/bug4966112.java new file mode 100644 index 0000000000000000000000000000000000000000..f1d496dc1fff8e545c07adb117a4a480fc138f3d --- /dev/null +++ b/test/javax/swing/JPopupMenu/4966112/bug4966112.java @@ -0,0 +1,312 @@ +/* + * 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 4966112 + * @summary Some Composite components does not show the Context Popup. + * @library ../../regtesthelpers + * @build Util + * @author Alexander Zuev + * @run main bug4966112 + */ +import javax.swing.*; +import javax.swing.event.PopupMenuListener; +import javax.swing.event.PopupMenuEvent; +import java.awt.*; +import java.awt.event.*; +import sun.awt.SunToolkit; + +public class bug4966112 { + + private static final int NO_MOUSE_BUTTON = -1; + private static volatile boolean shown = false; + private static volatile int popupButton = NO_MOUSE_BUTTON; + private static volatile JButton testButton; + private static volatile JSplitPane jsp; + private static volatile JSpinner spin; + private static volatile JFileChooser filec; + private static int buttonMask; + private static Robot robot; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + robot = new Robot(); + robot.setAutoDelay(100); + + createAndShowButton(); + toolkit.realSync(); + + setClickPoint(testButton); + clickMouse(InputEvent.BUTTON1_MASK); + clickMouse(InputEvent.BUTTON2_MASK); + clickMouse(InputEvent.BUTTON3_MASK); + + toolkit.realSync(); + closeFrame(); + + if (popupButton == NO_MOUSE_BUTTON) { + System.out.println("Test can't identify the popup trigger button. Test skipped"); + return; + } + + setButtonMask(); + + // Test Split Pane + createAndShowSplitPane(); + toolkit.realSync(); + + clickMouse(jsp); + toolkit.realSync(); + closeFrame(); + + if (!shown) { + throw new RuntimeException("Popup was not shown on splitpane"); + } + + // Test Spinner + createAndShowSpinner(); + toolkit.realSync(); + + clickMouse(spin); + toolkit.realSync(); + closeFrame(); + + if (!shown) { + throw new RuntimeException("Popup was not shown on spinner"); + } + + // Test File Chooser + createAndShowFileChooser(); + toolkit.realSync(); + + clickMouse(filec); + toolkit.realSync(); + + Util.hitKeys(robot, KeyEvent.VK_ESCAPE); + toolkit.realSync(); + + Util.hitKeys(robot, KeyEvent.VK_ESCAPE); + toolkit.realSync(); + closeFrame(); + + if (!shown) { + throw new RuntimeException("Popup was not shown on filechooser"); + } + } + + private static void clickMouse(JComponent c) throws Exception { + setClickPoint(c); + clickMouse(buttonMask); + } + + private static void clickMouse(int buttons) { + robot.mousePress(buttons); + robot.mouseRelease(buttons); + } + + private static void setButtonMask() { + switch (popupButton) { + case MouseEvent.BUTTON1: + buttonMask = InputEvent.BUTTON1_MASK; + break; + case MouseEvent.BUTTON2: + buttonMask = InputEvent.BUTTON2_MASK; + break; + case MouseEvent.BUTTON3: + buttonMask = InputEvent.BUTTON3_MASK; + break; + } + } + + private static void setClickPoint(final JComponent c) throws Exception { + final Point[] result = new Point[1]; + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + Point p = c.getLocationOnScreen(); + Dimension size = c.getSize(); + result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2); + } + }); + + robot.mouseMove(result[0].x, result[0].y); + } + + private static JPopupMenu createJPopupMenu() { + JPopupMenu jpm = new JPopupMenu(); + jpm.add("One"); + jpm.add("Two"); + jpm.add("Three"); + jpm.addPopupMenuListener(new PopupMenuListener() { + + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + shown = true; + } + + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { + } + + public void popupMenuCanceled(PopupMenuEvent e) { + } + }); + + AutoClosable.INSTANCE.setPopup(jpm); + return jpm; + } + + private static void createAndShowButton() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + JFrame frame = new JFrame("Button Frame"); + frame.setLayout(new BorderLayout()); + testButton = new JButton("Popup Tester"); + + testButton.addMouseListener(new MouseAdapter() { + + void setPopupTrigger(MouseEvent e) { + if (e.isPopupTrigger()) { + popupButton = e.getButton(); + } + } + + public void mouseClicked(MouseEvent e) { + setPopupTrigger(e); + } + + public void mousePressed(MouseEvent e) { + setPopupTrigger(e); + } + + public void mouseReleased(MouseEvent e) { + setPopupTrigger(e); + } + }); + + frame.add(testButton, BorderLayout.CENTER); + frame.pack(); + frame.setVisible(true); + AutoClosable.INSTANCE.setFrame(frame); + } + }); + } + + private static void createAndShowSplitPane() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + JFrame frame = new JFrame("Test SplitPane"); + frame.setSize(250, 200); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLayout(new BorderLayout()); + + shown = false; + jsp = new JSplitPane(); + jsp.setRightComponent(new JPanel()); + jsp.setLeftComponent(new JPanel()); + jsp.setComponentPopupMenu(createJPopupMenu()); + + frame.add(jsp, BorderLayout.CENTER); + + jsp.setDividerLocation(150); + + frame.setLocation(400, 300); + frame.setVisible(true); + AutoClosable.INSTANCE.setFrame(frame); + } + }); + } + + private static void createAndShowSpinner() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + JFrame frame = new JFrame("JSpinner Test"); + frame.setLayout(new BorderLayout()); + frame.setSize(200, 100); + shown = false; + spin = new JSpinner(); + spin.setComponentPopupMenu(createJPopupMenu()); + frame.add(spin, BorderLayout.CENTER); + frame.setVisible(true); + AutoClosable.INSTANCE.setFrame(frame); + } + }); + } + + private static void createAndShowFileChooser() throws Exception { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + JFrame frame = new JFrame("FileChooser test dialog"); + frame.setSize(100, 100); + + shown = false; + filec = new JFileChooser(); + filec.setComponentPopupMenu(createJPopupMenu()); + filec.showOpenDialog(frame); + + frame.setVisible(true); + AutoClosable.INSTANCE.setFrame(frame); + } + }); + } + + private static void closeFrame() { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + AutoClosable.INSTANCE.close(); + } + }); + } + + private static class AutoClosable { + + static final AutoClosable INSTANCE = new AutoClosable(); + private JFrame frame; + private JPopupMenu popup; + + public void setFrame(JFrame frame) { + this.frame = frame; + } + + public void setPopup(JPopupMenu popup) { + this.popup = popup; + } + + public void close() { + frame.dispose(); + if (popup != null) { + popup.setVisible(false); + } + } + } +} diff --git a/test/javax/swing/JPopupMenu/6827786/bug6827786.java b/test/javax/swing/JPopupMenu/6827786/bug6827786.java new file mode 100644 index 0000000000000000000000000000000000000000..7255ccb20f68c3f9d756c730e441c96e80f051d6 --- /dev/null +++ b/test/javax/swing/JPopupMenu/6827786/bug6827786.java @@ -0,0 +1,145 @@ +/* + * 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. + */ + +/* + * @test + * @bug 6827786 + * @summary Tests duplicate mnemonics + * @author Peter Zhelezniakov + * @library ../../regtesthelpers + * @build Util + * @run main bug6827786 + */ +import java.awt.*; +import java.awt.event.KeyEvent; +import javax.swing.*; +import sun.awt.SunToolkit; + +public class bug6827786 { + + private static JMenu menu; + private static Component focusable; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + focusable.requestFocus(); + } + }); + + toolkit.realSync(); + checkfocus(); + + // select menu + Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_F); + // select submenu + Util.hitKeys(robot, KeyEvent.VK_S); + toolkit.realSync(); + // verify submenu is selected + verify(1); + + Util.hitKeys(robot, KeyEvent.VK_S); + toolkit.realSync(); + // verify last item is selected + verify(2); + + Util.hitKeys(robot, KeyEvent.VK_S); + toolkit.realSync(); + // selection should wrap to first item + verify(0); + + System.out.println("PASSED"); + + } + + private static void checkfocus() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + if (!focusable.isFocusOwner()) { + throw new RuntimeException("Button is not the focus owner."); + } + } + }); + } + + private static void verify(final int index) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + MenuElement[] path = + MenuSelectionManager.defaultManager().getSelectedPath(); + MenuElement item = path[3]; + if (item != menu.getMenuComponent(index)) { + System.err.println("Selected: " + item); + System.err.println("Should be: " + + menu.getMenuComponent(index)); + throw new RuntimeException("Test Failed"); + } + } + }); + } + + private static JMenuBar createMenuBar() { + menu = new JMenu("File"); + menu.setMnemonic('F'); + + menu.add(new JMenuItem("Save", 'S')); + + JMenu sub = new JMenu("Submenu"); + sub.setMnemonic('S'); + sub.add(new JMenuItem("Sub Item")); + menu.add(sub); + + menu.add(new JMenuItem("Special", 'S')); + + JMenuBar bar = new JMenuBar(); + bar.add(menu); + return bar; + } + + private static void createAndShowGUI() { + JFrame frame = new JFrame("bug6827786"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setJMenuBar(createMenuBar()); + focusable = new JButton("Set Focus Here"); + frame.add(focusable); + frame.pack(); + frame.setVisible(true); + } +} diff --git a/test/javax/swing/JTabbedPane/7010561/bug7010561.java b/test/javax/swing/JTabbedPane/7010561/bug7010561.java new file mode 100644 index 0000000000000000000000000000000000000000..c79a398b0e96b401d1c02879f49f723ba13c93ac --- /dev/null +++ b/test/javax/swing/JTabbedPane/7010561/bug7010561.java @@ -0,0 +1,94 @@ +/* + * 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. + */ + +import javax.swing.*; +import javax.swing.plaf.basic.BasicTabbedPaneUI; +import javax.swing.plaf.synth.SynthLookAndFeel; +import java.lang.reflect.Method; + +/* @test + @bug 7010561 + @summary Tab text position with Synth based LaF is different to Java 5/6 + @author Pavel Porvatov +*/ +public class bug7010561 { + private static int[] TAB_PLACEMENT = { + SwingConstants.BOTTOM, + SwingConstants.BOTTOM, + SwingConstants.TOP, + SwingConstants.TOP, + + }; + + private static boolean[] IS_SELECTED = { + false, + true, + false, + true + }; + + private static int[] RETURN_VALUE = { + -1, + 1, + 1, + -1 + }; + + public static void main(String[] args) throws Exception { + UIManager.setLookAndFeel(new SynthLookAndFeel()); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + JTabbedPane tabbedPane = new JTabbedPane(); + + tabbedPane.addTab("Tab 1", new JLabel("Tab 1")); + + // Ensure internal TabbedPane fields are initialized + tabbedPane.doLayout(); + + BasicTabbedPaneUI basicTabbedPaneUI = (BasicTabbedPaneUI) tabbedPane.getUI(); + + try { + Method method = BasicTabbedPaneUI.class.getDeclaredMethod("getTabLabelShiftY", int.class, + int.class, boolean.class); + + method.setAccessible(true); + + for (int i = 0; i < 4; i++) { + int res = ((Integer) method.invoke(basicTabbedPaneUI, TAB_PLACEMENT[i], 0, + IS_SELECTED[i])).intValue(); + + if (res != RETURN_VALUE[i]) { + throw new RuntimeException("Test bug7010561 failed on index " + i); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + + System.out.println("Test bug7010561 passed"); + } + }); + } +} diff --git a/test/javax/swing/JTree/6263446/bug6263446.java b/test/javax/swing/JTree/6263446/bug6263446.java new file mode 100644 index 0000000000000000000000000000000000000000..b50a633db04622ff008dedd6cbf96d25604d5d45 --- /dev/null +++ b/test/javax/swing/JTree/6263446/bug6263446.java @@ -0,0 +1,272 @@ +/* + * 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 6263446 + * @summary Tests that double-clicking to edit a cell doesn't select the content. + * @author Shannon Hickey + * @run main bug6263446 + */ +import java.awt.*; +import java.awt.event.InputEvent; +import java.lang.reflect.Field; +import javax.swing.*; +import javax.swing.tree.*; +import sun.awt.SunToolkit; + +public class bug6263446 { + + private static final String FIRST = "AAAAAAAAAAA"; + private static final String SECOND = "BB"; + private static final String ALL = FIRST + " " + SECOND; + private static JTree tree; + private static Robot robot; + private static SunToolkit toolkit; + + public static void main(String[] args) throws Exception { + toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + Point point = getClickPoint(); + robot.mouseMove(point.x, point.y); + + // click count 3 + click(1); + assertNotEditing(); + + click(2); + assertNotEditing(); + + click(3); + assertEditing(); + cancelCellEditing(); + assertNotEditing(); + + click(4); + checkSelectedText(FIRST); + + click(5); + checkSelectedText(ALL); + + // click count 4 + setClickCountToStart(4); + + click(1); + assertNotEditing(); + + click(2); + assertNotEditing(); + + click(3); + assertNotEditing(); + + click(4); + assertEditing(); + cancelCellEditing(); + assertNotEditing(); + + click(5); + checkSelectedText(FIRST); + + click(6); + checkSelectedText(ALL); + + // start path editing + startPathEditing(); + assertEditing(); + + click(1); + checkSelection(null); + + click(2); + checkSelection(FIRST); + + click(3); + checkSelection(ALL); + } + + private static void click(int times) { + robot.delay(500); + for (int i = 0; i < times; i++) { + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + } + + private static Point getClickPoint() throws Exception { + final Point[] result = new Point[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + Rectangle rect = tree.getRowBounds(0); + // UPDATE !!! + Point p = new Point(rect.x + rect.width / 2, rect.y + 2); + SwingUtilities.convertPointToScreen(p, tree); + result[0] = p; + + } + }); + + return result[0]; + } + + private static TreeModel createTreeModel() { + return new DefaultTreeModel(new DefaultMutableTreeNode(ALL)); + } + + private static void createAndShowGUI() { + + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + tree = new JTree(createTreeModel()); + tree.setRootVisible(true); + tree.setEditable(true); + + + frame.getContentPane().add(tree); + frame.pack(); + frame.setVisible(true); + } + + private static void setClickCountToStart(final int clicks) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + try { + DefaultTreeCellEditor editor = + (DefaultTreeCellEditor) tree.getCellEditor(); + Field field = DefaultTreeCellEditor.class.getDeclaredField("realEditor"); + field.setAccessible(true); + DefaultCellEditor ce = (DefaultCellEditor) field.get(editor); + ce.setClickCountToStart(clicks); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } + } + }); + + toolkit.realSync(); + + } + + private static void startPathEditing() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + tree.startEditingAtPath(tree.getPathForRow(0)); + } + }); + } + + private static void cancelCellEditing() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + tree.getCellEditor().cancelCellEditing(); + } + }); + } + + private static void checkSelection(final String sel) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + try { + DefaultTreeCellEditor editor = + (DefaultTreeCellEditor) tree.getCellEditor(); + Field field = DefaultTreeCellEditor.class.getDeclaredField("realEditor"); + field.setAccessible(true); + DefaultCellEditor ce = (DefaultCellEditor) field.get(editor); + JTextField tf = (JTextField) ce.getComponent(); + String text = tf.getSelectedText(); + + if (sel == null) { + if (text != null && text.length() != 0) { + throw new RuntimeException("Nothing should be selected, but \"" + text + "\" is selected."); + } + } else if (!sel.equals(text)) { + throw new RuntimeException("\"" + sel + "\" should be selected, but \"" + text + "\" is selected."); + } + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } + } + }); + } + + private static void checkSelectedText(String sel) throws Exception { + assertEditing(); + checkSelection(sel); + cancelCellEditing(); + assertNotEditing(); + } + + private static void assertEditing() throws Exception { + assertEditingNoTreeLock(true); + } + + private static void assertNotEditing() throws Exception { + assertEditingNoTreeLock(false); + } + + private static void assertEditingNoTreeLock(final boolean editing) throws Exception { + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + if (editing && !tree.isEditing()) { + throw new RuntimeException("Tree should be editing"); + } + if (!editing && tree.isEditing()) { + throw new RuntimeException("Tree should not be editing"); + } + } + }); + + } + +} diff --git a/test/javax/swing/SwingUtilities/4917669/bug4917669.java b/test/javax/swing/SwingUtilities/4917669/bug4917669.java new file mode 100644 index 0000000000000000000000000000000000000000..fcfbb1715d766012c98d130bb6ccdfbd3e11e4fc --- /dev/null +++ b/test/javax/swing/SwingUtilities/4917669/bug4917669.java @@ -0,0 +1,106 @@ + +/* + * Copyright (c) 2008, 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 4917669 + * @summary 1.4 REGRESSION: MenuItem accelerator doesn't work if parent menu is in JDialog + * @author Alexander Zuev + * @library ../../regtesthelpers + * @run main bug4917669 + */ + +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; +import sun.awt.SunToolkit; + +public class bug4917669 { + + private static volatile boolean passed = false; + private static JFrame mainFrame; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(500); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowDialog(); + } + }); + + toolkit.realSync(); + + Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_O); + toolkit.realSync(); + + if (!passed) { + throw new RuntimeException("Action did not received by menu item."); + } + } + + private static void createAndShowDialog() { + JDialog dialog = new JDialog(mainFrame, "Test Dialog", false); + JMenuBar mb = new JMenuBar(); + JMenu file = new JMenu("File"); + JMenuItem menuItem = new JMenuItem("Open"); + menuItem.setAccelerator(KeyStroke.getKeyStroke("control O")); + menuItem.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + passed = true; + } + }); + file.add(menuItem); + mb.add(file); + dialog.setJMenuBar(mb); + + dialog.setSize(100, 100); + dialog.setLocation(200, 200); + dialog.setVisible(true); + } + + private static void createAndShowGUI() { + mainFrame = new JFrame("Bug4917669"); + mainFrame.setLayout(new BorderLayout()); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + mainFrame.setSize(50, 50); + mainFrame.setVisible(true); + } + +} diff --git a/test/javax/swing/UITest/UITest.java b/test/javax/swing/UITest/UITest.java new file mode 100644 index 0000000000000000000000000000000000000000..413bd1f3ee696312d0d0b2406d93104d15279b24 --- /dev/null +++ b/test/javax/swing/UITest/UITest.java @@ -0,0 +1,113 @@ +/* + * 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 4843282 4886871 + * @summary Makes sure windows is only listed on Windows platform, and + * GTK is not on Windows and Mac. + * added as tabs + * @author Scott Violet + */ +import javax.swing.*; +import javax.swing.UIManager.LookAndFeelInfo; +import sun.awt.OSInfo; +import sun.awt.OSInfo.OSType; + +public class UITest { + + public static void main(String[] args) { + OSType os = OSInfo.getOSType(); + LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels(); + + switch (os) { + case WINDOWS: + + // Make sure we don't have GTK. + if (hasLAF("gtk", lafInfo)) { + throw new RuntimeException("On windows, but GTK is present"); + } + + // Make sure we don't have Aqua. + if (hasLAF("mac", lafInfo)) { + throw new RuntimeException("On windows, but Aqua is present"); + } + + // Make sure we have Windows. + if (!hasLAF("windows", lafInfo)) { + throw new RuntimeException("On windows and don't have Windows"); + } + + break; + + case MACOSX: + + // Make sure we don't have GTK. + if (hasLAF("gtk", lafInfo)) { + throw new RuntimeException("On mac, but GTK is present"); + } + + // Make sure we don't have Windows. + if (hasLAF("windows", lafInfo)) { + throw new RuntimeException("On mac, but Windows is present"); + } + + // Make sure we have Aqua. + if (!hasLAF("mac", lafInfo)) { + throw new RuntimeException("On mac and don't have Aqua"); + } + + break; + + default: + // Not windows and mac + + // Make sure we don't have Windows. + if (hasLAF("windows", lafInfo)) { + throw new RuntimeException("Not on windows and have Windows"); + } + + // Make sure we don't have Aqua. + if (hasLAF("mac", lafInfo)) { + throw new RuntimeException("Not on mac and have Aqua"); + } + + // Make sure we have GTK. + if (!hasLAF("gtk", lafInfo)) { + throw new RuntimeException( + "Not on Windows and Mac and don't have GTK!"); + } + } + + } + + public static boolean hasLAF(String name, LookAndFeelInfo[] lafInfo) { + + for (int counter = 0; counter < lafInfo.length; counter++) { + if (lafInfo[counter].getName().toLowerCase().indexOf(name) != -1) { + return true; + } + } + return false; + } +} diff --git a/test/javax/swing/plaf/basic/BasicHTML/4251579/bug4251579.java b/test/javax/swing/plaf/basic/BasicHTML/4251579/bug4251579.java new file mode 100644 index 0000000000000000000000000000000000000000..2069995928f2e1562fadc32508f2ca1ef2518f20 --- /dev/null +++ b/test/javax/swing/plaf/basic/BasicHTML/4251579/bug4251579.java @@ -0,0 +1,100 @@ + +/* + * Copyright (c) 2008, 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 4251579 + * @summary Tests if style sheets are working in JLabel + * @author Denis Sharypov + * @run main bug4251579 + */ +import java.awt.*; +import javax.swing.*; + +import sun.awt.SunToolkit; + +public class bug4251579 { + + private static JLabel htmlComponent; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + final Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + boolean passed = false; + + Point p = htmlComponent.getLocationOnScreen(); + Dimension d = htmlComponent.getSize(); + int x0 = p.x; + int y = p.y + d.height / 2; + + for (int x = x0; x < x0 + d.width; x++) { + if (robot.getPixelColor(x, y).equals(Color.blue)) { + passed = true; + break; + } + } + + if (!passed) { + throw new RuntimeException("Test failed."); + } + + } + }); + } + + private static void createAndShowGUI() { + + String htmlText = + "" + + "" + + " should be rendered with BLUE class definition

    " + + ""; + + JFrame mainFrame = new JFrame("bug4251579"); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + htmlComponent = new JLabel(htmlText); + mainFrame.getContentPane().add(htmlComponent); + + mainFrame.pack(); + mainFrame.setVisible(true); + } +} diff --git a/test/javax/swing/text/html/CSS/4530474/bug4530474.java b/test/javax/swing/text/html/CSS/4530474/bug4530474.java new file mode 100644 index 0000000000000000000000000000000000000000..8242c14f64aaba2ffcd6ad0affeb71233bd9b67e --- /dev/null +++ b/test/javax/swing/text/html/CSS/4530474/bug4530474.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2008, 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 4530474 + * @summary Tests if background-color CSS attribute in HTML font tag in class attribute + * @author Denis Sharypov + * @run main bug4530474 + */ + +import java.awt.*; +import javax.swing.*; + +import java.io.*; + +import sun.awt.SunToolkit; + +public class bug4530474 { + + private static final Color TEST_COLOR = Color.BLUE; + private static JEditorPane jep; + + public static void main(String args[]) throws Exception { + + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + final Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + + boolean passed = false; + + Point p = jep.getLocationOnScreen(); + Dimension d = jep.getSize(); + int x0 = p.x; + int y = p.y + d.height / 3; + + StringBuilder builder = new StringBuilder("Test color: "); + builder.append(TEST_COLOR.toString()); + builder.append(" resut colors: "); + + for (int x = x0; x < x0 + d.width; x++) { + Color color = robot.getPixelColor(x, y); + builder.append(color); + + if (TEST_COLOR.equals(color)) { + passed = true; + break; + } + } + + if (!passed) { + throw new RuntimeException("Test Fail. " + builder.toString()); + } + } + }); + + } + + private static void createAndShowGUI() { + + JFrame mainFrame = new JFrame("bug4530474"); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + jep = new JEditorPane(); + + try { + File file = new File(System.getProperty("test.src", "."), "test.html"); + jep.setPage(file.toURL()); + } catch (Exception e) { + throw new RuntimeException(e); + } + + mainFrame.getContentPane().add(jep); + + mainFrame.pack(); + mainFrame.setVisible(true); + } +} diff --git a/test/javax/swing/text/html/CSS/4530474/test.css b/test/javax/swing/text/html/CSS/4530474/test.css new file mode 100644 index 0000000000000000000000000000000000000000..9f0de8bfa5c2912eab26d3e1b610ac4cd26fb8e5 --- /dev/null +++ b/test/javax/swing/text/html/CSS/4530474/test.css @@ -0,0 +1,4 @@ +font.blackwhite { + background-color: blue; + color: #FFFFFF; +} diff --git a/test/javax/swing/text/html/CSS/4530474/test.html b/test/javax/swing/text/html/CSS/4530474/test.html new file mode 100644 index 0000000000000000000000000000000000000000..03ec318ebae991d1e8de47e76668e6a69ac1a8a1 --- /dev/null +++ b/test/javax/swing/text/html/CSS/4530474/test.html @@ -0,0 +1,7 @@ + + + + + www + + diff --git a/test/javax/xml/crypto/dsig/KeySelectors.java b/test/javax/xml/crypto/dsig/KeySelectors.java index a22e27a00a2046826cba198aaa5e9f2663521d30..2924d991ae36cdc62b3a0302494b3f864ea61ea1 100644 --- a/test/javax/xml/crypto/dsig/KeySelectors.java +++ b/test/javax/xml/crypto/dsig/KeySelectors.java @@ -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 @@ class KeySelectors { } public byte[] getEncoded() { - return (byte[]) bytes.clone(); + return bytes.clone(); } }; } @@ -196,9 +198,9 @@ class KeySelectors { * matching public key. */ static class CollectionKeySelector extends KeySelector { - private CertificateFactory certFac; + private CertificateFactory cf; private File certDir; - private Vector certs; + private Vector 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 @@ class KeySelectors { 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(); 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 match(int matchType, Object value, + Vector pool) { + Vector 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 @@ class KeySelectors { 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 result = match(MATCH_SUBJECT, name, certs); int numOfMatches = (result==null? 0:result.size()); if (numOfMatches != 1) { @@ -306,7 +307,7 @@ class KeySelectors { ((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 @@ class KeySelectors { 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 @@ class KeySelectors { } else if (xmlStructure instanceof X509Data) { List content = ((X509Data)xmlStructure).getContent(); int size = content.size(); - Vector result = null; + Vector 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 @@ class KeySelectors { ((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); diff --git a/test/javax/xml/crypto/dsig/ValidationTests.java b/test/javax/xml/crypto/dsig/ValidationTests.java index 27d2bb47db2e02b933eb2528f9fac6ca0a2c9c41..4ee123e42e193b78088e39a4882a2e0ec84ae1ad 100644 --- a/test/javax/xml/crypto/dsig/ValidationTests.java +++ b/test/javax/xml/crypto/dsig/ValidationTests.java @@ -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.XMLCryptoContext; 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 @@ public class ValidationTests { 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,36 +83,44 @@ public class ValidationTests { 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 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(); 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 @@ public class ValidationTests { } // 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 class ValidationTests { } } - 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); } /** diff --git a/test/javax/xml/crypto/dsig/X509KeySelector.java b/test/javax/xml/crypto/dsig/X509KeySelector.java index bbe9a7c5ec66fc3378f9b66377d228156705afd8..a21e42910b4532b8006d4671264832d64d4f0bfb 100644 --- a/test/javax/xml/crypto/dsig/X509KeySelector.java +++ b/test/javax/xml/crypto/dsig/X509KeySelector.java @@ -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 @@ class X509KeySelector extends KeySelector { */ private KeySelectorResult keyStoreSelect(CertSelector cs) throws KeyStoreException { - Enumeration aliases = ks.aliases(); + Enumeration 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 @@ class X509KeySelector extends KeySelector { } catch (IOException ioe) { throw new KeySelectorException(ioe); } - Collection certs = new ArrayList(); + Collection certs = new ArrayList<>(); Iterator xi = xd.getContent().iterator(); while (xi.hasNext()) { @@ -345,7 +345,7 @@ class X509KeySelector extends KeySelector { 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 @@ class X509KeySelector extends KeySelector { } 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()); } diff --git a/test/javax/xml/crypto/dsig/data/xmldsig-xfilter2.xml b/test/javax/xml/crypto/dsig/data/xmldsig-xfilter2.xml new file mode 100644 index 0000000000000000000000000000000000000000..7e0f63ef40b1ca0ba9b399b4a75fe2330c310267 --- /dev/null +++ b/test/javax/xml/crypto/dsig/data/xmldsig-xfilter2.xml @@ -0,0 +1,7 @@ + //FooBar //NotToBeSigned //ReallyToBeSigned 6S7pEM13ZCDvVUbP9XB8iRWFbAI= / 2jmj7l5rSw0yVb/vlWAYkK/YBwk=cJBwfPGWSI9CiuFinTvWJLbF8bGVK5SRB/N/NjCM5IMxakBjra+KSg==

    /X9TgR11EilS30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuA +HTRv8mZgt2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOu +K2HXKu/yIgMZndFIAcc=

    l2BQjxUjC8yykrmCouuEC/BYHPU=9+GghdabPd7LvKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3 +zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImog9/hWuWfBpKL +Zl6Ae1UlZAFMO/7PSSo=5LRac3QkDCDOPaeNF5dJQ2r0hgIWZomZV7Z9pHrRqMoepJD5xnJpJY7aA4eUSS+AHS1qOm5I6VTZ +68hsOdPZCDFF/DiR38BzTxi4ZD0PhtmOjBh32lSNG1nhEq6e9RsyzhUw5FVYHAPnCx2bX4/8Rz8i +EMuG0IcCiAbbzsCfGBw=
    \ No newline at end of file diff --git a/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.java b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.java new file mode 100644 index 0000000000000000000000000000000000000000..cd9564e46aed2194ad9ddd34c01fde520ffd5141 --- /dev/null +++ b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.java @@ -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); + } + } +} diff --git a/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.sh b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.sh new file mode 100644 index 0000000000000000000000000000000000000000..7fbbbed9c2cfcb4e86b2021c3bb977028a2b6ac2 --- /dev/null +++ b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.sh @@ -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 diff --git a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/CookieHttpsClientTest.java b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/CookieHttpsClientTest.java index 6996ca06359f3812a19781d2ac1d38ec9de1bf91..cc20b42377cbc6e5cb000d0bd3661ed0ee84b44d 100644 --- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/CookieHttpsClientTest.java +++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/CookieHttpsClientTest.java @@ -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; diff --git a/test/tools/launcher/Arrrghs.java b/test/tools/launcher/Arrrghs.java index f505b7e60320d59da1a60af1ee0537a30b1f413d..6c75737a91173d6b363833e08778ea78be9d3967 100644 --- a/test/tools/launcher/Arrrghs.java +++ b/test/tools/launcher/Arrrghs.java @@ -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.InputStream; 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 @@ public class Arrrghs { * 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 @@ public class Arrrghs { 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 @@ public class Arrrghs { 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 @@ public class Arrrghs { * 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 env = pb.environment(); @@ -146,8 +146,7 @@ public class Arrrghs { * 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 @@ public class Arrrghs { } // 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 @@ public class Arrrghs { */ 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 @@ public class Arrrghs { 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 @@ public class Arrrghs { * @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 @@ public class Arrrghs { 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"); diff --git a/test/tools/launcher/ChangeDataModel.java b/test/tools/launcher/ChangeDataModel.java new file mode 100644 index 0000000000000000000000000000000000000000..6b4b6bb19c4109ba9650ecd8fa15409603a052de --- /dev/null +++ b/test/tools/launcher/ChangeDataModel.java @@ -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 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); + } + } +} diff --git a/test/tools/launcher/ChangeDataModel.sh b/test/tools/launcher/ChangeDataModel.sh deleted file mode 100644 index f0656039cb0ee2d946001a7d22ead70953d3529f..0000000000000000000000000000000000000000 --- a/test/tools/launcher/ChangeDataModel.sh +++ /dev/null @@ -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; diff --git a/test/tools/launcher/CreatePlatformFile.java b/test/tools/launcher/CreatePlatformFile.java deleted file mode 100644 index 1658d476cb0b315e0cd0bf2875729a277d2b074b..0000000000000000000000000000000000000000 --- a/test/tools/launcher/CreatePlatformFile.java +++ /dev/null @@ -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"); - } - } - } -} diff --git a/test/tools/launcher/DefaultLocaleTestRun.java b/test/tools/launcher/DefaultLocaleTestRun.java index d3c08421e4f6bdddb1cc76dda2398f70e97ba4f9..c1183e78814702116c9fe16bed5e7e3ca83f050d 100644 --- a/test/tools/launcher/DefaultLocaleTestRun.java +++ b/test/tools/launcher/DefaultLocaleTestRun.java @@ -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"); diff --git a/test/tools/launcher/ExecutionEnvironment.java b/test/tools/launcher/ExecutionEnvironment.java index 720df5e126e5c6da286659662535c399e7f6e602..427c3fd0dc5439278fa12af071aa79cc585745af 100644 --- a/test/tools/launcher/ExecutionEnvironment.java +++ b/test/tools/launcher/ExecutionEnvironment.java @@ -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.List; 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 @@ public class ExecutionEnvironment { 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 @@ public class ExecutionEnvironment { 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 codeList = new ArrayList(); + List 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 @@ public class ExecutionEnvironment { 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 @@ public class ExecutionEnvironment { * environment should be pristine. */ private static void ensureEcoFriendly() { - TestHelper.TestResult tr = null; + TestResult tr = null; - Map env = new HashMap(); + Map 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 @@ public class ExecutionEnvironment { * data model */ static void ensureNoExec() { - Map env = new HashMap(); + Map 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 @@ public class ExecutionEnvironment { */ static void verifyJavaLibraryPath() { - TestHelper.TestResult tr = null; + TestResult tr = null; - Map env = new HashMap(); + Map 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 @@ public class ExecutionEnvironment { // 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 @@ public class ExecutionEnvironment { } } - 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 @@ public class ExecutionEnvironment { */ 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 @@ public class ExecutionEnvironment { 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 @@ public class ExecutionEnvironment { * 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 class ExecutionEnvironment { } public static void main(String... args) throws Exception { - if (TestHelper.isWindows) { + if (isWindows) { System.out.println("Warning: noop on windows"); return; } diff --git a/test/tools/launcher/I18NJarTest.java b/test/tools/launcher/I18NJarTest.java index 70193296c175d66b8f2c40a17f3c0977b8902e7c..9c033b47f8f507a8e279d0d46712d4e17fa68828 100644 --- a/test/tools/launcher/I18NJarTest.java +++ b/test/tools/launcher/I18NJarTest.java @@ -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 @@ import java.util.Locale; * 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 @@ public class I18NJarTest { } 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 @@ public class I18NJarTest { // 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"); diff --git a/test/tools/launcher/I18NTest.java b/test/tools/launcher/I18NTest.java new file mode 100644 index 0000000000000000000000000000000000000000..3af5d593afc29fd27574d1ac50412407e4659ebb --- /dev/null +++ b/test/tools/launcher/I18NTest.java @@ -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 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); + } +} diff --git a/test/tools/launcher/MiscTests.java b/test/tools/launcher/MiscTests.java index 55d3e8b44e2ecd4912ffc8d5fa42fb1fcafe2fef..25461821492c998bf27f71c3ea992e362e2024e2 100644 --- a/test/tools/launcher/MiscTests.java +++ b/test/tools/launcher/MiscTests.java @@ -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 @@ public class MiscTests { 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 class MiscTests { 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"); } } } diff --git a/test/tools/launcher/Settings.java b/test/tools/launcher/Settings.java index de01993b9dbdf0a3bb0fd96b8220873c4898daab..850dec11235168a88b829674026bdc5b240c1e59 100644 --- a/test/tools/launcher/Settings.java +++ b/test/tools/launcher/Settings.java @@ -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 @@ import java.io.IOException; * @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 @@ public class Settings { 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 @@ public class Settings { 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 @@ public class Settings { 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 @@ public class Settings { } 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"); diff --git a/test/tools/launcher/Test7029048.java b/test/tools/launcher/Test7029048.java index 69c94d52e57938e6f62d310589119fd147d68fb8..2f00b3a3fcd22beca31e5a5e6ea5c2223f0109dc 100644 --- a/test/tools/launcher/Test7029048.java +++ b/test/tools/launcher/Test7029048.java @@ -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.HashMap; 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 @@ public class Test7029048 { 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 @@ public class Test7029048 { private static final Map 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 @@ public class Test7029048 { List 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 @@ public class Test7029048 { 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 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 @@ public class Test7029048 { 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 @@ public class Test7029048 { Files.deleteIfExists(dstServerLibjvm.toPath()); } - if (TestHelper.isDualMode) { + if (isDualMode) { if (!dstOtherServerDir.exists()) { Files.createDirectories(dstOtherServerDir.toPath()); } else { @@ -223,7 +223,7 @@ public class Test7029048 { 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 @@ public class Test7029048 { 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 @@ public class Test7029048 { 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 @@ public class Test7029048 { * 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 class Test7029048 { } 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 @@ public class Test7029048 { 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 { diff --git a/test/tools/launcher/TestHelper.java b/test/tools/launcher/TestHelper.java index c0f1119554ca554150a3d210414564e4eb562bfc..a64d97d3d0184a132a007aafc75cdcc3ba019521 100644 --- a/test/tools/launcher/TestHelper.java +++ b/test/tools/launcher/TestHelper.java @@ -29,6 +29,7 @@ import java.io.FileOutputStream; 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.SimpleFileVisitor; 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 @@ public enum TestHelper { 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"); } @@ -180,6 +203,19 @@ public enum TestHelper { createJar(null, jarName, mainClass, mainDefs); } + /* + * 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 @@ -239,6 +275,11 @@ public enum TestHelper { Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING); } + static void createFile(File outFile, List 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 @@ public enum TestHelper { }; } + 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. diff --git a/test/tools/launcher/UnicodeCleanup.java b/test/tools/launcher/UnicodeCleanup.java deleted file mode 100644 index fc756ada9dfc35385ef5d7c8a4a9c9b26edb7440..0000000000000000000000000000000000000000 --- a/test/tools/launcher/UnicodeCleanup.java +++ /dev/null @@ -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); - } - } -} diff --git a/test/tools/launcher/UnicodeTest.java b/test/tools/launcher/UnicodeTest.java index ffd9520d5d726f486c5f1586677b7fec9cc025da..d44582df18c035c7d22993b4c3b7ae241cba4b0b 100644 --- a/test/tools/launcher/UnicodeTest.java +++ b/test/tools/launcher/UnicodeTest.java @@ -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()); - public static void main(String[] args) throws Exception { + 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(); + + /* + * 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 @@ public class UnicodeTest { { "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 @@ public class UnicodeTest { } 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 @@ public class UnicodeTest { } 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, diff --git a/test/tools/launcher/UnicodeTest.sh b/test/tools/launcher/UnicodeTest.sh deleted file mode 100644 index f64969b3a398161fe4d34a8c40e8b41016ba4f73..0000000000000000000000000000000000000000 --- a/test/tools/launcher/UnicodeTest.sh +++ /dev/null @@ -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 - diff --git a/test/tools/launcher/UnresolvedExceptions.java b/test/tools/launcher/UnresolvedExceptions.java index 70431d4a11dd859c5cc4a96eda7509867747c653..aa70a8f3e6570302e3ae01b0acfd913eec220a85 100644 --- a/test/tools/launcher/UnresolvedExceptions.java +++ b/test/tools/launcher/UnresolvedExceptions.java @@ -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 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"); } } +} diff --git a/test/tools/launcher/deleteI18n.sh b/test/tools/launcher/deleteI18n.sh deleted file mode 100644 index 1514bddc52fdb1d33078985a0c0584963961de41..0000000000000000000000000000000000000000 --- a/test/tools/launcher/deleteI18n.sh +++ /dev/null @@ -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 - - diff --git a/test/tools/launcher/i18nTest.sh b/test/tools/launcher/i18nTest.sh deleted file mode 100644 index ea01d59ad7b97cf668a5032dec4b91a2b64b334c..0000000000000000000000000000000000000000 --- a/test/tools/launcher/i18nTest.sh +++ /dev/null @@ -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 diff --git a/test/tools/launcher/unresolvedExceptions.sh b/test/tools/launcher/unresolvedExceptions.sh deleted file mode 100644 index 3244bd949a95a3e7595cb27f13ecc1e0b1e63a82..0000000000000000000000000000000000000000 --- a/test/tools/launcher/unresolvedExceptions.sh +++ /dev/null @@ -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