diff --git a/src/share/classes/com/sun/security/auth/callback/TextCallbackHandler.java b/src/share/classes/com/sun/security/auth/callback/TextCallbackHandler.java index 9a21dc9ddfe895962c22b1d65a4d94e5dfbd3e79..43d38d935ddeb896c5984783604303fe3990126f 100644 --- a/src/share/classes/com/sun/security/auth/callback/TextCallbackHandler.java +++ b/src/share/classes/com/sun/security/auth/callback/TextCallbackHandler.java @@ -129,7 +129,7 @@ public class TextCallbackHandler implements CallbackHandler { System.err.print(pc.getPrompt()); System.err.flush(); - pc.setPassword(Password.readPassword(System.in)); + pc.setPassword(Password.readPassword(System.in, pc.isEchoOn())); } else if (callbacks[i] instanceof ConfirmationCallback) { confirmation = (ConfirmationCallback) callbacks[i]; diff --git a/src/share/classes/com/sun/security/sasl/Provider.java b/src/share/classes/com/sun/security/sasl/Provider.java index c1900e582fb3fd503fa17eba50d251e442debd88..effc5b7bbc39b4d9d50c8eb6c504bc03a87c9938 100644 --- a/src/share/classes/com/sun/security/sasl/Provider.java +++ b/src/share/classes/com/sun/security/sasl/Provider.java @@ -51,7 +51,7 @@ public final class Provider extends java.security.Provider { " server mechanisms for: DIGEST-MD5, GSSAPI, CRAM-MD5)"; public Provider() { - super("SunSASL", 1.5, info); + super("SunSASL", 1.7d, info); AccessController.doPrivileged(new PrivilegedAction() { public Void run() { diff --git a/src/share/classes/java/lang/String.java b/src/share/classes/java/lang/String.java index 316da645f3c8dfb16eab5681c957b2aa92a26bd2..e4327434c389d48259d59f0ec5cc0759b36bfb1c 100644 --- a/src/share/classes/java/lang/String.java +++ b/src/share/classes/java/lang/String.java @@ -2301,6 +2301,54 @@ public final class String * @spec JSR-51 */ public String[] split(String regex, int limit) { + /* fastpath if the regex is a + (1)one-char String and this character is not one of the + RegEx's meta characters ".$|()[{^?*+\\", or + (2)two-char String and the first char is the backslash and + the second is not the ascii digit or ascii letter. + */ + char ch = 0; + if (((regex.count == 1 && + ".$|()[{^?*+\\".indexOf(ch = regex.charAt(0)) == -1) || + (regex.length() == 2 && + regex.charAt(0) == '\\' && + (((ch = regex.charAt(1))-'0')|('9'-ch)) < 0 && + ((ch-'a')|('z'-ch)) < 0 && + ((ch-'A')|('Z'-ch)) < 0)) && + (ch < Character.MIN_HIGH_SURROGATE || + ch > Character.MAX_LOW_SURROGATE)) + { + int off = 0; + int next = 0; + boolean limited = limit > 0; + ArrayList list = new ArrayList(); + while ((next = indexOf(ch, off)) != -1) { + if (!limited || list.size() < limit - 1) { + list.add(substring(off, next)); + off = next + 1; + } else { // last one + //assert (list.size() == limit - 1); + list.add(substring(off, count)); + off = count; + break; + } + } + // If no match was found, return this + if (off == 0) + return new String[] { this }; + + // Add remaining segment + if (!limited || list.size() < limit) + list.add(substring(off, count)); + + // Construct result + int resultSize = list.size(); + if (limit == 0) + while (resultSize > 0 && list.get(resultSize-1).length() == 0) + resultSize--; + String[] result = new String[resultSize]; + return list.subList(0, resultSize).toArray(result); + } return Pattern.compile(regex).split(this, limit); } diff --git a/src/share/classes/sun/nio/cs/ext/ISO2022.java b/src/share/classes/sun/nio/cs/ext/ISO2022.java index 242a841d46fd7a76114b84b5173b20dad448c8b6..036dc04299dbb312023872eb8099548728eb877e 100644 --- a/src/share/classes/sun/nio/cs/ext/ISO2022.java +++ b/src/share/classes/sun/nio/cs/ext/ISO2022.java @@ -388,9 +388,9 @@ abstract class ISO2022 protected static class Encoder extends CharsetEncoder { private final Surrogate.Parser sgp = new Surrogate.Parser(); - private final byte SS2 = (byte)0x8e; - private final byte PLANE2 = (byte)0xA2; - private final byte PLANE3 = (byte)0xA3; + public static final byte SS2 = (byte)0x8e; + public static final byte PLANE2 = (byte)0xA2; + public static final byte PLANE3 = (byte)0xA3; private final byte MSB = (byte)0x80; protected final byte maximumDesignatorLength = 4; diff --git a/src/share/classes/sun/nio/cs/ext/ISO2022_CN_CNS.java b/src/share/classes/sun/nio/cs/ext/ISO2022_CN_CNS.java index e5b5d7195152650457eeb5888d24e55569c16042..72e11ff1a76deaaed8475a62d266ae6e575382d5 100644 --- a/src/share/classes/sun/nio/cs/ext/ISO2022_CN_CNS.java +++ b/src/share/classes/sun/nio/cs/ext/ISO2022_CN_CNS.java @@ -76,6 +76,15 @@ public class ISO2022_CN_CNS extends ISO2022 implements HistoricallyNamedCharset } catch (Exception e) { } } + private byte[] bb = new byte[4]; + public boolean canEncode(char c) { + int n = 0; + return (c <= '\u007f' || + (n = ((EUC_TW.Encoder)ISOEncoder).toEUC(c, bb)) == 2 || + (n == 4 && bb[0] == SS2 && + (bb[1] == PLANE2 || bb[1] == PLANE3))); + } + /* * Since ISO2022-CN-CNS possesses a CharsetEncoder * without the corresponding CharsetDecoder half the diff --git a/src/share/classes/sun/security/jgss/SunProvider.java b/src/share/classes/sun/security/jgss/SunProvider.java index 362bec5936db9f2d7ad720ecb3806cb5d51e814d..26039b9db1dc3e4e565f3d683c53ad2ff5eb304c 100644 --- a/src/share/classes/sun/security/jgss/SunProvider.java +++ b/src/share/classes/sun/security/jgss/SunProvider.java @@ -62,7 +62,7 @@ public final class SunProvider extends Provider { public SunProvider() { /* We are the Sun JGSS provider */ - super("SunJGSS", 1.0, INFO); + super("SunJGSS", 1.7d, INFO); AccessController.doPrivileged( new java.security.PrivilegedAction() { diff --git a/src/share/classes/sun/security/provider/Sun.java b/src/share/classes/sun/security/provider/Sun.java index 1cbf37c35eca9653c915e74a063569bbfb164446..ec2687da99e3928a84fcae47cea6f7d74e945b76 100644 --- a/src/share/classes/sun/security/provider/Sun.java +++ b/src/share/classes/sun/security/provider/Sun.java @@ -46,7 +46,7 @@ public final class Sun extends Provider { public Sun() { /* We are the SUN provider */ - super("SUN", 1.6, INFO); + super("SUN", 1.7, INFO); // if there is no security manager installed, put directly into // the provider. Otherwise, create a temporary map and use a diff --git a/src/share/classes/sun/security/smartcardio/SunPCSC.java b/src/share/classes/sun/security/smartcardio/SunPCSC.java index 938614e54f9144c686c4be070e1e719bfc661264..fc76ce8118ad0ba4b394e3612ed286aa8d24bdae 100644 --- a/src/share/classes/sun/security/smartcardio/SunPCSC.java +++ b/src/share/classes/sun/security/smartcardio/SunPCSC.java @@ -40,7 +40,7 @@ public final class SunPCSC extends Provider { private static final long serialVersionUID = 6168388284028876579L; public SunPCSC() { - super("SunPCSC", 1.6d, "Sun PC/SC provider"); + super("SunPCSC", 1.7d, "Sun PC/SC provider"); AccessController.doPrivileged(new PrivilegedAction() { public Void run() { put("TerminalFactory.PC/SC", "sun.security.smartcardio.SunPCSC$Factory"); diff --git a/src/share/classes/sun/security/ssl/SunJSSE.java b/src/share/classes/sun/security/ssl/SunJSSE.java index a097ebb428bcd237a98794afd9105eccca937b2a..0811fc0d83b1cd77994aae8c437e2ed468c05944 100644 --- a/src/share/classes/sun/security/ssl/SunJSSE.java +++ b/src/share/classes/sun/security/ssl/SunJSSE.java @@ -103,7 +103,7 @@ public abstract class SunJSSE extends java.security.Provider { // standard constructor protected SunJSSE() { - super("SunJSSE", 1.6d, info); + super("SunJSSE", 1.7d, info); subclassCheck(); if (Boolean.TRUE.equals(fips)) { throw new ProviderException diff --git a/src/share/classes/sun/security/util/Password.java b/src/share/classes/sun/security/util/Password.java index 5600ed60b17da82858cbde5ba7248a3f174b5c45..9f767124d491d117100b2e89633874b06c9b2189 100644 --- a/src/share/classes/sun/security/util/Password.java +++ b/src/share/classes/sun/security/util/Password.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,6 +37,14 @@ import java.util.Arrays; public class Password { /** Reads user password from given input stream. */ public static char[] readPassword(InputStream in) throws IOException { + return readPassword(in, false); + } + + /** Reads user password from given input stream. + * @param isEchoOn true if the password should be echoed on the screen + */ + public static char[] readPassword(InputStream in, boolean isEchoOn) + throws IOException { char[] consoleEntered = null; byte[] consoleBytes = null; @@ -44,7 +52,7 @@ public class Password { try { // Use the new java.io.Console class Console con = null; - if (in == System.in && ((con = System.console()) != null)) { + if (!isEchoOn && in == System.in && ((con = System.console()) != null)) { consoleEntered = con.readPassword(); // readPassword returns "" if you just print ENTER, // to be compatible with old Password class, change to null diff --git a/src/windows/classes/sun/nio/fs/WindowsFileSystem.java b/src/windows/classes/sun/nio/fs/WindowsFileSystem.java index 54712098b672f852f4903548f15df79fde5914a6..2ad40cb779889bc1a384ca86b936307d77d3812e 100644 --- a/src/windows/classes/sun/nio/fs/WindowsFileSystem.java +++ b/src/windows/classes/sun/nio/fs/WindowsFileSystem.java @@ -283,25 +283,15 @@ class WindowsFileSystem } } - // match in uppercase - StringBuilder sb = new StringBuilder(expr.length()); - for (int i=0; i UNEXPECTED RESULT!"); + failures++; + } + } + + public static void main(String[] args) { // basic assertMatch("foo.html", "foo.html"); @@ -140,21 +154,13 @@ public class Basic { assertMatch("one*two", "one\\*two"); } - - // regex syntax - { - String pattern = ".*\\.html"; - System.out.format("Test regex pattern: %s", pattern); - Path file = Paths.get("foo.html"); - boolean matched = file.getFileSystem() - .getPathMatcher("regex:" + pattern).matches(file); - if (matched) { - System.out.println(" OKAY"); - } else { - System.out.println(" ==> UNEXPECTED RESULT!"); - failures++; - } + assertRegExMatch("foo.html", ".*\\.html"); + + if (System.getProperty("os.name").startsWith("Windows")) { + assertRegExMatch("foo012", "foo\\d+"); + assertRegExMatch("fo o", "fo\\so"); + assertRegExMatch("foo", "\\w+"); } // unknown syntax diff --git a/test/java/util/prefs/CommentsInXml.java b/test/java/util/prefs/CommentsInXml.java new file mode 100644 index 0000000000000000000000000000000000000000..b65cfa29e7db7379c3cc4add683af51be79bbe3a --- /dev/null +++ b/test/java/util/prefs/CommentsInXml.java @@ -0,0 +1,60 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 4619564 + * @summary XMl Comments in Preferences File lead to ClassCastException + * @author kladko + */ + +import java.io.*; +import java.util.prefs.*; + +public class CommentsInXml { + + public static void main(String[] argv) throws Exception { + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + bos.write(new String( + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + ).getBytes()); + + Preferences ur = Preferences.userRoot(); + ur.importPreferences(new ByteArrayInputStream(bos.toByteArray())); + ur.node("hlrAgent").removeNode(); // clean + } +} diff --git a/test/java/util/prefs/ConflictInFlush.java b/test/java/util/prefs/ConflictInFlush.java new file mode 100644 index 0000000000000000000000000000000000000000..598b909d34598701251a6785550234c2f22eab39 --- /dev/null +++ b/test/java/util/prefs/ConflictInFlush.java @@ -0,0 +1,49 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 4703132 + * @summary flush() throws an IllegalStateException on a removed node + * @author Sucheta Dambalkar + */ + +import java.util.prefs.*; + +public final class ConflictInFlush{ + + public static void main(String args[]) { + Preferences root = Preferences.userRoot(); + try { + Preferences node = root.node("1/2/3"); + node.flush(); + System.out.println("Node "+node+" has been created"); + System.out.println("Removing node "+node); + node.removeNode(); + node.flush(); + }catch (BackingStoreException bse){ + bse.printStackTrace(); + } + + } +} diff --git a/test/java/util/prefs/ExportNode.java b/test/java/util/prefs/ExportNode.java new file mode 100644 index 0000000000000000000000000000000000000000..5ab802efb590e63207cd440ef3d4f4851f20fcb4 --- /dev/null +++ b/test/java/util/prefs/ExportNode.java @@ -0,0 +1,53 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + + +/* + * @test + * @bug 4387136 4947349 + * @summary Due to a bug in XMLSupport.putPreferencesInXml(...), + * node's keys would not get exported. + * @author Konstantin Kladko + */ +import java.util.prefs.*; +import java.io.*; + +public class ExportNode { + public static void main(String[] args) throws + BackingStoreException, IOException { + Preferences N1 = Preferences.userRoot().node("ExportNodeTest1"); + N1.put("ExportNodeTestName1","ExportNodeTestValue1"); + Preferences N2 = N1.node("ExportNodeTest2"); + N2.put("ExportNodeTestName2","ExportNodeTestValue2"); + ByteArrayOutputStream exportStream = new ByteArrayOutputStream(); + N2.exportNode(exportStream); + + // Removal of preference node should always succeed on Solaris/Linux + // by successfully acquiring the appropriate file lock (4947349) + N1.removeNode(); + + if (((exportStream.toString()).lastIndexOf("ExportNodeTestName2")== -1) || + ((exportStream.toString()).lastIndexOf("ExportNodeTestName1")!= -1)) { + } + } +} diff --git a/test/java/util/prefs/ExportSubtree.java b/test/java/util/prefs/ExportSubtree.java new file mode 100644 index 0000000000000000000000000000000000000000..c3d4cd7e936ac650ecdeddf77b3636a827e7ce02 --- /dev/null +++ b/test/java/util/prefs/ExportSubtree.java @@ -0,0 +1,95 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + + +/* @test + @bug 6203576 4700020 + @summary checks if the output of exportSubtree() is identical to + the output from previous release. + */ + +import java.io.*; +import java.util.prefs.*; + +public class ExportSubtree { + public static void main(String[] args) throws Exception { + try + { + //File f = new File(System.getProperty("test.src", "."), "TestPrefs.xml"); + ByteArrayInputStream bais = new ByteArrayInputStream(importPrefs.getBytes("utf-8")); + Preferences.importPreferences(bais); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Preferences.userRoot().node("testExportSubtree").exportSubtree(baos); + Preferences.userRoot().node("testExportSubtree").removeNode(); + if (!expectedResult.equals(baos.toString())) { + //System.out.print(baos.toString()); + //System.out.print(expectedResult); + throw new IOException("exportSubtree does not output expected result"); + } + } + catch( Exception e ) { + e.printStackTrace(); + } + } + + static String ls = System.getProperty("line.separator"); + static String importPrefs = + "" + + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + static String expectedResult = + "" + + ls + "" + + ls + "" + + ls + " " + + ls + " " + + ls + " " + + ls + " " + + ls + " " + + ls + " " + + ls + " " + + ls + " " + + ls + " " + + ls + " " + + ls + " " + + ls + " " + + ls + " " + + ls + "" + ls; +} diff --git a/test/java/util/prefs/PrefsSpi.java b/test/java/util/prefs/PrefsSpi.java new file mode 100644 index 0000000000000000000000000000000000000000..2009ae2d51270159f3734bce0650e323f78a1fa2 --- /dev/null +++ b/test/java/util/prefs/PrefsSpi.java @@ -0,0 +1,44 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + + +import java.util.prefs.Preferences; + +/* + * main class used by regtest PrefsSpi.sh + */ +public class PrefsSpi { + + public static void main (String[] args) throws Exception { + if (args.length != 1) + throw new Exception("Usage: java PrefsSpi REGEXP"); + + String className = Preferences.userRoot().getClass().getName(); + System.out.printf("className=%s%n", className); + + if (! className.matches(args[0])) + throw new Exception("Preferences class name \"" + className + + "\" does not match regular expression \"" + + args[0] + "\"."); + } +} diff --git a/test/java/util/prefs/PrefsSpi.sh b/test/java/util/prefs/PrefsSpi.sh new file mode 100644 index 0000000000000000000000000000000000000000..3d8e28b7afd47bbec529100677338155766ea89c --- /dev/null +++ b/test/java/util/prefs/PrefsSpi.sh @@ -0,0 +1,100 @@ +#!/bin/sh + +# +# Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, +# CA 95054 USA or visit www.sun.com if you need additional information or +# have any questions. +# + +# @test +# @bug 4991526 6514993 +# @summary Unit test for Preferences jar providers +# +# @build PrefsSpi +# @run shell PrefsSpi.sh +# @author Martin Buchholz + +# Command-line usage: sh PrefsSpi.sh /path/to/build + +if [ -z "$TESTJAVA" ]; then + if [ $# -lt 1 ]; then exit 1; fi + TESTJAVA="$1"; shift + TESTSRC="`pwd`" + TESTCLASSES="`pwd`" +fi + + java="$TESTJAVA/bin/java" +javac="$TESTJAVA/bin/javac" + jar="$TESTJAVA/bin/jar" + +Die() { printf "%s\n" "$*"; exit 1; } + +Sys() { + printf "%s\n" "$*"; "$@"; rc="$?"; + test "$rc" -eq 0 || Die "Command \"$*\" failed with exitValue $rc"; +} + +cat > StubPreferences.java <<'EOF' +import java.util.prefs.*; + +public class StubPreferences extends AbstractPreferences { + public StubPreferences() { super(null, ""); } + public String getSpi(String x) { return null; } + public void putSpi(String x, String y) { } + public void removeSpi(String x) { } + public AbstractPreferences childSpi(String x) { return null; } + public void removeNodeSpi() { } + public String[] keysSpi() { return null; } + public String[] childrenNamesSpi() { return null; } + public void syncSpi() { } + public void flushSpi() { } +} +EOF + +cat > StubPreferencesFactory.java <<'EOF' +import java.util.prefs.*; + +public class StubPreferencesFactory implements PreferencesFactory { + public Preferences userRoot() { return new StubPreferences(); } + public Preferences systemRoot() { return new StubPreferences(); } +} +EOF + +Sys rm -rf jarDir extDir +Sys mkdir -p jarDir/META-INF/services extDir +echo "StubPreferencesFactory" \ + > "jarDir/META-INF/services/java.util.prefs.PreferencesFactory" +Sys "$javac" -d jarDir StubPreferencesFactory.java StubPreferences.java + +(cd jarDir && "$jar" "cf" "../extDir/PrefsSpi.jar" ".") + +case "`uname`" in Windows*|CYGWIN* ) CPS=';';; *) CPS=':';; esac + +Sys "$java" "-cp" "$TESTCLASSES${CPS}extDir/PrefsSpi.jar" \ + -Djava.util.prefs.PreferencesFactory=StubPreferencesFactory \ + PrefsSpi "StubPreferences" +Sys "$java" "-cp" "$TESTCLASSES" \ + PrefsSpi "java.util.prefs.*" +Sys "$java" "-cp" "$TESTCLASSES${CPS}extDir/PrefsSpi.jar" \ + PrefsSpi "StubPreferences" +Sys "$java" "-cp" "$TESTCLASSES" "-Djava.ext.dirs=extDir" \ + PrefsSpi "StubPreferences" + +rm -rf jarDir extDir diff --git a/test/java/util/prefs/RemoveReadOnlyNode.java b/test/java/util/prefs/RemoveReadOnlyNode.java new file mode 100644 index 0000000000000000000000000000000000000000..82409dfc637cd1c9aef3573196b142079239d61d --- /dev/null +++ b/test/java/util/prefs/RemoveReadOnlyNode.java @@ -0,0 +1,63 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + + +/* @test + @bug 6178148 + @summary check if wrong exception gets thrown if one of the child + nodes is readonly on underlying filesystem when node is + being removed. + */ + +import java.io.*; +import java.util.prefs.*; + +public class RemoveReadOnlyNode { + public static void main(String[] args) throws Exception { + String osName = System.getProperty("os.name"); + if (osName.startsWith("Windows")) + return; + Preferences root = Preferences.userRoot(); + Preferences node1 = root.node("node1"); + Preferences node1A = node1.node("node1A"); + Preferences node1B = node1.node("node1B"); + node1B.put("mykey", "myvalue"); + node1.flush(); + String node1BDirName = System.getProperty("user.home") + + "/.java/.userPrefs" + + "/node1/node1B"; + File node1BDir = new File(node1BDirName); + node1BDir.setReadOnly(); + try { + node1.removeNode(); + } + catch (BackingStoreException ex) { + //expected exception + } finally { + Runtime.getRuntime().exec("chmod 755 " + node1BDirName).waitFor(); + try { + node1.removeNode(); + } catch (Exception e) {} + } + } +} diff --git a/test/java/util/prefs/RemoveUnregedListener.java b/test/java/util/prefs/RemoveUnregedListener.java new file mode 100644 index 0000000000000000000000000000000000000000..d48e42b4cb71027f5ad4ffa806fe34e1c60fe1c3 --- /dev/null +++ b/test/java/util/prefs/RemoveUnregedListener.java @@ -0,0 +1,63 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + + +/* @test + * @bug 4705094 + * @summary Checks if correct exception gets thrown when removing an + * unregistered NodeChangeListener . + */ + +import java.util.prefs.*; +import java.util.*; + +public class RemoveUnregedListener { + public static void main(String[] args) throws Exception { + Preferences userRoot = null; + Preferences N1 = null; + NodeChangeListenerTestAdd ncl = new NodeChangeListenerTestAdd(); + NodeChangeListenerTestAdd ncl2 = new NodeChangeListenerTestAdd(); + NodeChangeListenerTestAdd ncl3 = new NodeChangeListenerTestAdd(); + try { + userRoot = Preferences.userRoot(); + N1 = userRoot.node("N1"); + userRoot.flush(); + + //add ncl nc2 + N1.addNodeChangeListener(ncl); + N1.addNodeChangeListener(ncl2); + N1.removeNodeChangeListener(ncl3); + throw new RuntimeException(); + } catch (IllegalArgumentException iae) { + System.out.println("Test Passed!"); + } catch (Exception e) { + System.out.println("Test Failed"); + throw e; + } + } + +} +class NodeChangeListenerTestAdd implements NodeChangeListener { + public void childAdded(NodeChangeEvent evt) {} + public void childRemoved(NodeChangeEvent evt) {} +} diff --git a/test/java/util/prefs/SerializeExceptions.java b/test/java/util/prefs/SerializeExceptions.java new file mode 100644 index 0000000000000000000000000000000000000000..04e4ae3e7dd4f8d6853d0962972d4ac42e416014 --- /dev/null +++ b/test/java/util/prefs/SerializeExceptions.java @@ -0,0 +1,48 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + + +/* + * @test + * @bug 4811356 + * @summary Prefs exceptions were unintentionally not serializable + * @author Josh Bloch + */ + +import java.util.prefs.*; +import java.io.*; + +public class SerializeExceptions { + public static void main(String args[]) throws Exception { + test(new BackingStoreException("Hi")); + test(new InvalidPreferencesFormatException("Mom!")); + } + + static void test(Object o) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(bos); + out.writeObject(o); + out.flush(); + out.close(); + } +} diff --git a/test/sun/nio/cs/FindCanEncodeBugs.java b/test/sun/nio/cs/FindCanEncodeBugs.java index 7331934d5da0c9651033fab0e6d8149b1c9e811e..2fc6218995d18e09ab2652b6c9a2afa55c72b6b0 100644 --- a/test/sun/nio/cs/FindCanEncodeBugs.java +++ b/test/sun/nio/cs/FindCanEncodeBugs.java @@ -22,7 +22,7 @@ */ /* @test - @bug 5066863 5066867 5066874 5066879 5066884 5066887 5065777 + @bug 5066863 5066867 5066874 5066879 5066884 5066887 5065777 6730652 @summary canEncode() false iff encode() throws CharacterCodingException @run main/timeout=1200 FindCanEncodeBugs @author Martin Buchholz @@ -52,9 +52,7 @@ public class FindCanEncodeBugs { String csn = e.getKey(); Charset cs = e.getValue(); - if (! cs.canEncode() || - csn.matches("x-COMPOUND_TEXT") || - csn.matches("x-ISO-2022-CN-CNS")) // ISO2022_CN_CNS supports less + if (! cs.canEncode() || csn.matches("x-COMPOUND_TEXT")) continue; //System.out.println(csn);