Merge
This commit is contained in:
commit
4670b4c234
@ -29,12 +29,10 @@ import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.security.AccessController;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.CodeSource;
|
||||
import java.security.Policy;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
@ -54,7 +52,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import sun.misc.CompoundEnumeration;
|
||||
import sun.misc.Resource;
|
||||
import sun.misc.URLClassPath;
|
||||
import sun.misc.VM;
|
||||
import sun.reflect.CallerSensitive;
|
||||
import sun.reflect.Reflection;
|
||||
import sun.reflect.misc.ReflectUtil;
|
||||
@ -268,8 +265,8 @@ public abstract class ClassLoader {
|
||||
|
||||
// The packages defined in this class loader. Each package name is mapped
|
||||
// to its corresponding Package object.
|
||||
// @GuardedBy("itself")
|
||||
private final HashMap<String, Package> packages = new HashMap<>();
|
||||
private final ConcurrentHashMap<String, Package> packages
|
||||
= new ConcurrentHashMap<>();
|
||||
|
||||
private static Void checkCreateClassLoader() {
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
@ -1575,17 +1572,17 @@ public abstract class ClassLoader {
|
||||
String implVendor, URL sealBase)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
synchronized (packages) {
|
||||
Package pkg = getPackage(name);
|
||||
if (pkg != null) {
|
||||
throw new IllegalArgumentException(name);
|
||||
}
|
||||
pkg = new Package(name, specTitle, specVersion, specVendor,
|
||||
implTitle, implVersion, implVendor,
|
||||
sealBase, this);
|
||||
packages.put(name, pkg);
|
||||
return pkg;
|
||||
Package pkg = getPackage(name);
|
||||
if (pkg != null) {
|
||||
throw new IllegalArgumentException(name);
|
||||
}
|
||||
pkg = new Package(name, specTitle, specVersion, specVendor,
|
||||
implTitle, implVersion, implVendor,
|
||||
sealBase, this);
|
||||
if (packages.putIfAbsent(name, pkg) != null) {
|
||||
throw new IllegalArgumentException(name);
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1601,26 +1598,13 @@ public abstract class ClassLoader {
|
||||
* @since 1.2
|
||||
*/
|
||||
protected Package getPackage(String name) {
|
||||
Package pkg;
|
||||
synchronized (packages) {
|
||||
pkg = packages.get(name);
|
||||
}
|
||||
Package pkg = packages.get(name);
|
||||
if (pkg == null) {
|
||||
if (parent != null) {
|
||||
pkg = parent.getPackage(name);
|
||||
} else {
|
||||
pkg = Package.getSystemPackage(name);
|
||||
}
|
||||
if (pkg != null) {
|
||||
synchronized (packages) {
|
||||
Package pkg2 = packages.get(name);
|
||||
if (pkg2 == null) {
|
||||
packages.put(name, pkg);
|
||||
} else {
|
||||
pkg = pkg2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
@ -1635,22 +1619,18 @@ public abstract class ClassLoader {
|
||||
* @since 1.2
|
||||
*/
|
||||
protected Package[] getPackages() {
|
||||
Map<String, Package> map;
|
||||
synchronized (packages) {
|
||||
map = new HashMap<>(packages);
|
||||
}
|
||||
Package[] pkgs;
|
||||
if (parent != null) {
|
||||
pkgs = parent.getPackages();
|
||||
} else {
|
||||
pkgs = Package.getSystemPackages();
|
||||
}
|
||||
|
||||
Map<String, Package> map = packages;
|
||||
if (pkgs != null) {
|
||||
map = new HashMap<>(packages);
|
||||
for (Package pkg : pkgs) {
|
||||
String pkgName = pkg.getName();
|
||||
if (map.get(pkgName) == null) {
|
||||
map.put(pkgName, pkg);
|
||||
}
|
||||
map.putIfAbsent(pkg.getName(), pkg);
|
||||
}
|
||||
}
|
||||
return map.values().toArray(new Package[map.size()]);
|
||||
|
@ -26,27 +26,21 @@
|
||||
package java.lang;
|
||||
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.MalformedURLException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.jar.JarInputStream;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Attributes.Name;
|
||||
import java.util.jar.JarException;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import sun.net.www.ParseUtil;
|
||||
import sun.reflect.CallerSensitive;
|
||||
@ -538,17 +532,15 @@ public class Package implements java.lang.reflect.AnnotatedElement {
|
||||
* Returns the loaded system package for the specified name.
|
||||
*/
|
||||
static Package getSystemPackage(String name) {
|
||||
synchronized (pkgs) {
|
||||
Package pkg = pkgs.get(name);
|
||||
if (pkg == null) {
|
||||
name = name.replace('.', '/').concat("/");
|
||||
String fn = getSystemPackage0(name);
|
||||
if (fn != null) {
|
||||
pkg = defineSystemPackage(name, fn);
|
||||
}
|
||||
Package pkg = pkgs.get(name);
|
||||
if (pkg == null) {
|
||||
name = name.replace('.', '/').concat("/");
|
||||
String fn = getSystemPackage0(name);
|
||||
if (fn != null) {
|
||||
pkg = defineSystemPackage(name, fn);
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -557,74 +549,98 @@ public class Package implements java.lang.reflect.AnnotatedElement {
|
||||
static Package[] getSystemPackages() {
|
||||
// First, update the system package map with new package names
|
||||
String[] names = getSystemPackages0();
|
||||
synchronized (pkgs) {
|
||||
for (String name : names) {
|
||||
for (String name : names) {
|
||||
if (!pkgs.containsKey(name)) {
|
||||
defineSystemPackage(name, getSystemPackage0(name));
|
||||
}
|
||||
return pkgs.values().toArray(new Package[pkgs.size()]);
|
||||
}
|
||||
return pkgs.values().toArray(new Package[pkgs.size()]);
|
||||
}
|
||||
|
||||
private static Package defineSystemPackage(final String iname,
|
||||
final String fn)
|
||||
{
|
||||
return AccessController.doPrivileged(new PrivilegedAction<Package>() {
|
||||
public Package run() {
|
||||
String name = iname;
|
||||
// Get the cached code source url for the file name
|
||||
URL url = urls.get(fn);
|
||||
if (url == null) {
|
||||
// URL not found, so create one
|
||||
File file = new File(fn);
|
||||
try {
|
||||
url = ParseUtil.fileToEncodedURL(file);
|
||||
} catch (MalformedURLException e) {
|
||||
}
|
||||
if (url != null) {
|
||||
urls.put(fn, url);
|
||||
// If loading a JAR file, then also cache the manifest
|
||||
if (file.isFile()) {
|
||||
mans.put(fn, loadManifest(fn));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Convert to "."-separated package name
|
||||
name = name.substring(0, name.length() - 1).replace('/', '.');
|
||||
Package pkg;
|
||||
Manifest man = mans.get(fn);
|
||||
if (man != null) {
|
||||
pkg = new Package(name, man, url, null);
|
||||
} else {
|
||||
pkg = new Package(name, null, null, null,
|
||||
null, null, null, null, null);
|
||||
}
|
||||
pkgs.put(name, pkg);
|
||||
return pkg;
|
||||
}
|
||||
});
|
||||
// Convert to "."-separated package name
|
||||
String name = iname.substring(0, iname.length() - 1).replace('/', '.');
|
||||
// Creates a cached manifest for the file name, allowing
|
||||
// only-once, lazy reads of manifest from jar files
|
||||
CachedManifest cachedManifest = createCachedManifest(fn);
|
||||
pkgs.putIfAbsent(name, new Package(name, cachedManifest.getManifest(),
|
||||
cachedManifest.getURL(), null));
|
||||
// Ensure we only expose one Package object
|
||||
return pkgs.get(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the Manifest for the specified JAR file name.
|
||||
*/
|
||||
private static Manifest loadManifest(String fn) {
|
||||
try (FileInputStream fis = new FileInputStream(fn);
|
||||
JarInputStream jis = new JarInputStream(fis, false))
|
||||
{
|
||||
return jis.getManifest();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
private static CachedManifest createCachedManifest(String fn) {
|
||||
if (!manifests.containsKey(fn)) {
|
||||
manifests.putIfAbsent(fn, new CachedManifest(fn));
|
||||
}
|
||||
return manifests.get(fn);
|
||||
}
|
||||
|
||||
// The map of loaded system packages
|
||||
private static Map<String, Package> pkgs = new HashMap<>(31);
|
||||
private static final ConcurrentHashMap<String, Package> pkgs
|
||||
= new ConcurrentHashMap<>();
|
||||
|
||||
// Maps each directory or zip file name to its corresponding url
|
||||
private static Map<String, URL> urls = new HashMap<>(10);
|
||||
// Maps each directory or zip file name to its corresponding manifest, if
|
||||
// it exists
|
||||
private static final ConcurrentHashMap<String, CachedManifest> manifests
|
||||
= new ConcurrentHashMap<>();
|
||||
|
||||
// Maps each code source url for a jar file to its manifest
|
||||
private static Map<String, Manifest> mans = new HashMap<>(10);
|
||||
private static class CachedManifest {
|
||||
private static final Manifest EMPTY_MANIFEST = new Manifest();
|
||||
private final String fileName;
|
||||
private final URL url;
|
||||
private volatile Manifest manifest;
|
||||
|
||||
CachedManifest(final String fileName) {
|
||||
this.fileName = fileName;
|
||||
this.url = AccessController.doPrivileged(new PrivilegedAction<URL>() {
|
||||
public URL run() {
|
||||
final File file = new File(fileName);
|
||||
if (file.isFile()) {
|
||||
try {
|
||||
return ParseUtil.fileToEncodedURL(file);
|
||||
} catch (MalformedURLException e) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public URL getURL() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public Manifest getManifest() {
|
||||
if (url == null) {
|
||||
return EMPTY_MANIFEST;
|
||||
}
|
||||
Manifest m = manifest;
|
||||
if (m != null) {
|
||||
return m;
|
||||
}
|
||||
synchronized (this) {
|
||||
m = manifest;
|
||||
if (m != null) {
|
||||
return m;
|
||||
}
|
||||
m = AccessController.doPrivileged(new PrivilegedAction<Manifest>() {
|
||||
public Manifest run() {
|
||||
try (FileInputStream fis = new FileInputStream(fileName);
|
||||
JarInputStream jis = new JarInputStream(fis, false)) {
|
||||
return jis.getManifest();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
manifest = m = (m == null ? EMPTY_MANIFEST : m);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
private static native String getSystemPackage0(String name);
|
||||
private static native String[] getSystemPackages0();
|
||||
|
@ -1388,16 +1388,26 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
|
||||
Object a4, Object a5, Object a6, Object a7,
|
||||
Object a8, Object a9)
|
||||
{ return makeArray(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); }
|
||||
|
||||
private static final int ARRAYS_COUNT = 11;
|
||||
|
||||
private static MethodHandle[] makeArrays() {
|
||||
ArrayList<MethodHandle> mhs = new ArrayList<>();
|
||||
for (;;) {
|
||||
MethodHandle mh = findCollector("array", mhs.size(), Object[].class);
|
||||
if (mh == null) break;
|
||||
MethodHandle[] mhs = new MethodHandle[MAX_ARITY + 1];
|
||||
for (int i = 0; i < ARRAYS_COUNT; i++) {
|
||||
MethodHandle mh = findCollector("array", i, Object[].class);
|
||||
mh = makeIntrinsic(mh, Intrinsic.NEW_ARRAY);
|
||||
mhs.add(mh);
|
||||
mhs[i] = mh;
|
||||
}
|
||||
assert(mhs.size() == 11); // current number of methods
|
||||
return mhs.toArray(new MethodHandle[MAX_ARITY+1]);
|
||||
assert(assertArrayMethodCount(mhs));
|
||||
return mhs;
|
||||
}
|
||||
|
||||
private static boolean assertArrayMethodCount(MethodHandle[] mhs) {
|
||||
assert(findCollector("array", ARRAYS_COUNT, Object[].class) == null);
|
||||
for (int i = 0; i < ARRAYS_COUNT; i++) {
|
||||
assert(mhs[i] != null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// filling versions of the above:
|
||||
@ -1449,15 +1459,22 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
|
||||
private static final int FILL_ARRAYS_COUNT = 11; // current number of fillArray methods
|
||||
|
||||
private static MethodHandle[] makeFillArrays() {
|
||||
ArrayList<MethodHandle> mhs = new ArrayList<>();
|
||||
mhs.add(null); // there is no empty fill; at least a0 is required
|
||||
for (;;) {
|
||||
MethodHandle mh = findCollector("fillArray", mhs.size(), Object[].class, Integer.class, Object[].class);
|
||||
if (mh == null) break;
|
||||
mhs.add(mh);
|
||||
MethodHandle[] mhs = new MethodHandle[FILL_ARRAYS_COUNT];
|
||||
mhs[0] = null; // there is no empty fill; at least a0 is required
|
||||
for (int i = 1; i < FILL_ARRAYS_COUNT; i++) {
|
||||
MethodHandle mh = findCollector("fillArray", i, Object[].class, Integer.class, Object[].class);
|
||||
mhs[i] = mh;
|
||||
}
|
||||
assert(mhs.size() == FILL_ARRAYS_COUNT);
|
||||
return mhs.toArray(new MethodHandle[0]);
|
||||
assert(assertFillArrayMethodCount(mhs));
|
||||
return mhs;
|
||||
}
|
||||
|
||||
private static boolean assertFillArrayMethodCount(MethodHandle[] mhs) {
|
||||
assert(findCollector("fillArray", FILL_ARRAYS_COUNT, Object[].class, Integer.class, Object[].class) == null);
|
||||
for (int i = 1; i < FILL_ARRAYS_COUNT; i++) {
|
||||
assert(mhs[i] != null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Object copyAsPrimitiveArray(Wrapper w, Object... boxes) {
|
||||
@ -1472,9 +1489,6 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
|
||||
static MethodHandle varargsArray(int nargs) {
|
||||
MethodHandle mh = Lazy.ARRAYS[nargs];
|
||||
if (mh != null) return mh;
|
||||
mh = findCollector("array", nargs, Object[].class);
|
||||
if (mh != null) mh = makeIntrinsic(mh, Intrinsic.NEW_ARRAY);
|
||||
if (mh != null) return Lazy.ARRAYS[nargs] = mh;
|
||||
mh = buildVarargsArray(Lazy.MH_fillNewArray, Lazy.MH_arrayIdentity, nargs);
|
||||
assert(assertCorrectArity(mh, nargs));
|
||||
mh = makeIntrinsic(mh, Intrinsic.NEW_ARRAY);
|
||||
|
@ -122,18 +122,18 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedAction<Void>() {
|
||||
public Void run() {
|
||||
ThreadGroup tg = Thread.currentThread().getThreadGroup();
|
||||
for (ThreadGroup tgn = tg;
|
||||
tgn != null;
|
||||
tg = tgn, tgn = tg.getParent());
|
||||
Thread sft = new Thread(tg, proc, "Secondary finalizer");
|
||||
sft.start();
|
||||
try {
|
||||
sft.join();
|
||||
} catch (InterruptedException x) {
|
||||
/* Ignore */
|
||||
}
|
||||
return null;
|
||||
ThreadGroup tg = Thread.currentThread().getThreadGroup();
|
||||
for (ThreadGroup tgn = tg;
|
||||
tgn != null;
|
||||
tg = tgn, tgn = tg.getParent());
|
||||
Thread sft = new Thread(tg, proc, "Secondary finalizer");
|
||||
sft.start();
|
||||
try {
|
||||
sft.join();
|
||||
} catch (InterruptedException x) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
return null;
|
||||
}});
|
||||
}
|
||||
|
||||
@ -146,6 +146,7 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
|
||||
forkSecondaryFinalizer(new Runnable() {
|
||||
private volatile boolean running;
|
||||
public void run() {
|
||||
// in case of recursive call to run()
|
||||
if (running)
|
||||
return;
|
||||
final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
|
||||
@ -168,6 +169,7 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
|
||||
forkSecondaryFinalizer(new Runnable() {
|
||||
private volatile boolean running;
|
||||
public void run() {
|
||||
// in case of recursive call to run()
|
||||
if (running)
|
||||
return;
|
||||
final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
|
||||
@ -189,6 +191,7 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
|
||||
super(g, "Finalizer");
|
||||
}
|
||||
public void run() {
|
||||
// in case of recursive call to run()
|
||||
if (running)
|
||||
return;
|
||||
|
||||
|
@ -446,6 +446,7 @@ public abstract class SocketImpl implements SocketOptions {
|
||||
|
||||
serverSocketOptions.add(StandardSocketOptions.SO_RCVBUF);
|
||||
serverSocketOptions.add(StandardSocketOptions.SO_REUSEADDR);
|
||||
serverSocketOptions.add(StandardSocketOptions.IP_TOS);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -303,7 +303,7 @@ public final class Files {
|
||||
* is a {@link java.nio.channels.FileChannel}.
|
||||
*
|
||||
* <p> <b>Usage Examples:</b>
|
||||
* <pre>
|
||||
* <pre>{@code
|
||||
* Path path = ...
|
||||
*
|
||||
* // open file for reading
|
||||
@ -314,9 +314,10 @@ public final class Files {
|
||||
* WritableByteChannel wbc = Files.newByteChannel(path, EnumSet.of(CREATE,APPEND));
|
||||
*
|
||||
* // create file with initial permissions, opening it for both reading and writing
|
||||
* {@code FileAttribute<Set<PosixFilePermission>> perms = ...}
|
||||
* SeekableByteChannel sbc = Files.newByteChannel(path, EnumSet.of(CREATE_NEW,READ,WRITE), perms);
|
||||
* </pre>
|
||||
* FileAttribute<Set<PosixFilePermission>> perms = ...
|
||||
* SeekableByteChannel sbc =
|
||||
* Files.newByteChannel(path, EnumSet.of(CREATE_NEW,READ,WRITE), perms);
|
||||
* }</pre>
|
||||
*
|
||||
* @param path
|
||||
* the path to the file to open or create
|
||||
@ -1702,7 +1703,8 @@ public final class Files {
|
||||
* Alternatively, suppose we want to read file's POSIX attributes without
|
||||
* following symbolic links:
|
||||
* <pre>
|
||||
* PosixFileAttributes attrs = Files.readAttributes(path, PosixFileAttributes.class, NOFOLLOW_LINKS);
|
||||
* PosixFileAttributes attrs =
|
||||
* Files.readAttributes(path, PosixFileAttributes.class, NOFOLLOW_LINKS);
|
||||
* </pre>
|
||||
*
|
||||
* @param <A>
|
||||
@ -2840,6 +2842,8 @@ public final class Files {
|
||||
* @return a new buffered writer, with default buffer size, to write text
|
||||
* to the file
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if {@code options} contains an invalid combination of options
|
||||
* @throws IOException
|
||||
* if an I/O error occurs opening or creating the file
|
||||
* @throws UnsupportedOperationException
|
||||
@ -2880,6 +2884,8 @@ public final class Files {
|
||||
* @return a new buffered writer, with default buffer size, to write text
|
||||
* to the file
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if {@code options} contains an invalid combination of options
|
||||
* @throws IOException
|
||||
* if an I/O error occurs opening or creating the file
|
||||
* @throws UnsupportedOperationException
|
||||
@ -2891,7 +2897,9 @@ public final class Files {
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
public static BufferedWriter newBufferedWriter(Path path, OpenOption... options) throws IOException {
|
||||
public static BufferedWriter newBufferedWriter(Path path, OpenOption... options)
|
||||
throws IOException
|
||||
{
|
||||
return newBufferedWriter(path, StandardCharsets.UTF_8, options);
|
||||
}
|
||||
|
||||
@ -3273,6 +3281,8 @@ public final class Files {
|
||||
*
|
||||
* @return the path
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if {@code options} contains an invalid combination of options
|
||||
* @throws IOException
|
||||
* if an I/O error occurs writing to or creating the file
|
||||
* @throws UnsupportedOperationException
|
||||
@ -3330,6 +3340,8 @@ public final class Files {
|
||||
*
|
||||
* @return the path
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if {@code options} contains an invalid combination of options
|
||||
* @throws IOException
|
||||
* if an I/O error occurs writing to or creating the file, or the
|
||||
* text cannot be encoded using the specified charset
|
||||
@ -3376,6 +3388,8 @@ public final class Files {
|
||||
*
|
||||
* @return the path
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if {@code options} contains an invalid combination of options
|
||||
* @throws IOException
|
||||
* if an I/O error occurs writing to or creating the file, or the
|
||||
* text cannot be encoded as {@code UTF-8}
|
||||
@ -3452,7 +3466,7 @@ public final class Files {
|
||||
final Iterator<Path> delegate = ds.iterator();
|
||||
|
||||
// Re-wrap DirectoryIteratorException to UncheckedIOException
|
||||
Iterator<Path> it = new Iterator<Path>() {
|
||||
Iterator<Path> iterator = new Iterator<Path>() {
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
try {
|
||||
@ -3471,7 +3485,9 @@ public final class Files {
|
||||
}
|
||||
};
|
||||
|
||||
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, Spliterator.DISTINCT), false)
|
||||
Spliterator<Path> spliterator =
|
||||
Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT);
|
||||
return StreamSupport.stream(spliterator, false)
|
||||
.onClose(asUncheckedRunnable(ds));
|
||||
} catch (Error|RuntimeException e) {
|
||||
try {
|
||||
@ -3572,7 +3588,9 @@ public final class Files {
|
||||
{
|
||||
FileTreeIterator iterator = new FileTreeIterator(start, maxDepth, options);
|
||||
try {
|
||||
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), false)
|
||||
Spliterator<FileTreeWalker.Event> spliterator =
|
||||
Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT);
|
||||
return StreamSupport.stream(spliterator, false)
|
||||
.onClose(iterator::close)
|
||||
.map(entry -> entry.file());
|
||||
} catch (Error|RuntimeException e) {
|
||||
@ -3685,7 +3703,9 @@ public final class Files {
|
||||
{
|
||||
FileTreeIterator iterator = new FileTreeIterator(start, maxDepth, options);
|
||||
try {
|
||||
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), false)
|
||||
Spliterator<FileTreeWalker.Event> spliterator =
|
||||
Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT);
|
||||
return StreamSupport.stream(spliterator, false)
|
||||
.onClose(iterator::close)
|
||||
.filter(entry -> matcher.test(entry.file(), entry.attributes()))
|
||||
.map(entry -> entry.file());
|
||||
|
@ -86,8 +86,8 @@
|
||||
* <p> Unless otherwise noted, passing a {@code null} argument to a constructor
|
||||
* or method of any class or interface in this package will cause a {@link
|
||||
* java.lang.NullPointerException NullPointerException} to be thrown. Additionally,
|
||||
* invoking a method with a collection containing a {@code null} element will
|
||||
* cause a {@code NullPointerException}, unless otherwise specified. </p>
|
||||
* invoking a method with an array or collection containing a {@code null} element
|
||||
* will cause a {@code NullPointerException}, unless otherwise specified. </p>
|
||||
*
|
||||
* <p> Unless otherwise noted, methods that attempt to access the file system
|
||||
* will throw {@link java.nio.file.ClosedFileSystemException} when invoked on
|
||||
|
@ -276,6 +276,7 @@ public class Sockets {
|
||||
set = new HashSet<>();
|
||||
set.add(StandardSocketOptions.SO_RCVBUF);
|
||||
set.add(StandardSocketOptions.SO_REUSEADDR);
|
||||
set.add(StandardSocketOptions.IP_TOS);
|
||||
set = Collections.unmodifiableSet(set);
|
||||
options.put(ServerSocket.class, set);
|
||||
|
||||
|
@ -1608,7 +1608,7 @@ public final class Main {
|
||||
private static String getCompatibleSigAlgName(String keyAlgName)
|
||||
throws Exception {
|
||||
if ("DSA".equalsIgnoreCase(keyAlgName)) {
|
||||
return "SHA1WithDSA";
|
||||
return "SHA256WithDSA";
|
||||
} else if ("RSA".equalsIgnoreCase(keyAlgName)) {
|
||||
return "SHA256WithRSA";
|
||||
} else if ("EC".equalsIgnoreCase(keyAlgName)) {
|
||||
@ -1628,10 +1628,8 @@ public final class Main {
|
||||
if (keysize == -1) {
|
||||
if ("EC".equalsIgnoreCase(keyAlgName)) {
|
||||
keysize = 256;
|
||||
} else if ("RSA".equalsIgnoreCase(keyAlgName)) {
|
||||
keysize = 2048;
|
||||
} else {
|
||||
keysize = 1024;
|
||||
keysize = 2048; // RSA and DSA
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,28 +205,4 @@ public class JmxProperties {
|
||||
*/
|
||||
public static final Logger MISC_LOGGER =
|
||||
Logger.getLogger(MISC_LOGGER_NAME);
|
||||
|
||||
/**
|
||||
* Logger name for SNMP.
|
||||
*/
|
||||
public static final String SNMP_LOGGER_NAME =
|
||||
"javax.management.snmp";
|
||||
|
||||
/**
|
||||
* Logger for SNMP.
|
||||
*/
|
||||
public static final Logger SNMP_LOGGER =
|
||||
Logger.getLogger(SNMP_LOGGER_NAME);
|
||||
|
||||
/**
|
||||
* Logger name for SNMP Adaptor.
|
||||
*/
|
||||
public static final String SNMP_ADAPTOR_LOGGER_NAME =
|
||||
"javax.management.snmp.daemon";
|
||||
|
||||
/**
|
||||
* Logger for SNMP Adaptor.
|
||||
*/
|
||||
public static final Logger SNMP_ADAPTOR_LOGGER =
|
||||
Logger.getLogger(SNMP_ADAPTOR_LOGGER_NAME);
|
||||
}
|
||||
|
@ -2358,7 +2358,7 @@ class SignatureFile {
|
||||
if (sigalg == null) {
|
||||
|
||||
if (keyAlgorithm.equalsIgnoreCase("DSA"))
|
||||
signatureAlgorithm = "SHA1withDSA";
|
||||
signatureAlgorithm = "SHA256withDSA";
|
||||
else if (keyAlgorithm.equalsIgnoreCase("RSA"))
|
||||
signatureAlgorithm = "SHA256withRSA";
|
||||
else if (keyAlgorithm.equalsIgnoreCase("EC"))
|
||||
|
@ -138,9 +138,6 @@ com/sun/management/GarbageCollectorMXBean/GarbageCollectionNotificationTest.java
|
||||
# 8058492
|
||||
java/lang/management/ThreadMXBean/FindDeadlocks.java generic-all
|
||||
|
||||
# 8058506
|
||||
java/lang/management/ThreadMXBean/ThreadMXBeanStateTest.java generic-all
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_jmx
|
||||
@ -285,6 +282,9 @@ com/sun/jdi/JdbReadTwiceTest.sh generic-all
|
||||
# 8058616
|
||||
com/sun/jdi/RedefinePop.sh generic-all
|
||||
|
||||
# 8061114
|
||||
com/sun/jdi/Redefine-g.sh generic-all
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_util
|
||||
@ -318,4 +318,7 @@ sun/tools/jps/TestJpsJarRelative.java generic-all
|
||||
# 8057732
|
||||
sun/jvmstat/monitor/MonitoredVm/MonitorVmStartTerminate.java generic-all
|
||||
|
||||
# 8060736
|
||||
sun/jvmstat/monitor/MonitoredVm/CR6672135.java generic-all
|
||||
|
||||
############################################################################
|
||||
|
249
jdk/test/java/lang/ClassLoader/GetSystemPackage.java
Normal file
249
jdk/test/java/lang/ClassLoader/GetSystemPackage.java
Normal file
@ -0,0 +1,249 @@
|
||||
/*
|
||||
* Copyright (c) 2014 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 8060130
|
||||
* @library /lib/testlibrary
|
||||
* @build package2.Class2 GetSystemPackage jdk.testlibrary.*
|
||||
* @summary Test if getSystemPackage() return consistent values for cases
|
||||
* where a manifest is provided or not and ensure only jars on
|
||||
* bootclasspath gets resolved via Package.getSystemPackage
|
||||
* @run main GetSystemPackage
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.jar.Manifest;
|
||||
import jdk.testlibrary.ProcessTools;
|
||||
|
||||
public class GetSystemPackage {
|
||||
|
||||
static final String testClassesDir = System.getProperty("test.classes", ".");
|
||||
static final File tmpFolder = new File(testClassesDir);
|
||||
static final String manifestTitle = "Special JAR";
|
||||
|
||||
public static void main(String ... args) throws Exception {
|
||||
if (args.length == 0) {
|
||||
buildJarsAndInitiateSystemPackageTest();
|
||||
return;
|
||||
}
|
||||
switch (args[0]) {
|
||||
case "system-manifest":
|
||||
verifyPackage(true, true);
|
||||
break;
|
||||
case "system-no-manifest":
|
||||
verifyPackage(false, true);
|
||||
break;
|
||||
case "non-system-manifest":
|
||||
verifyPackage(true, false);
|
||||
break;
|
||||
case "non-system-no-manifest":
|
||||
default:
|
||||
verifyPackage(false, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildJarsAndInitiateSystemPackageTest()
|
||||
throws Exception
|
||||
{
|
||||
Manifest m = new Manifest();
|
||||
// not setting MANIFEST_VERSION prevents META-INF/MANIFEST.MF from
|
||||
// getting written
|
||||
m.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
|
||||
m.getMainAttributes().put(Attributes.Name.SPECIFICATION_TITLE,
|
||||
manifestTitle);
|
||||
|
||||
buildJar("manifest.jar", m);
|
||||
buildJar("no-manifest.jar", null);
|
||||
|
||||
runSubProcess("System package with manifest improperly resolved.",
|
||||
"-Xbootclasspath/p:" + testClassesDir + "/manifest.jar",
|
||||
"GetSystemPackage", "system-manifest");
|
||||
|
||||
runSubProcess("System package from directory improperly resolved.",
|
||||
"-Xbootclasspath/p:" + testClassesDir, "GetSystemPackage",
|
||||
"system-no-manifest");
|
||||
|
||||
runSubProcess("System package with no manifest improperly resolved",
|
||||
"-Xbootclasspath/p:" + testClassesDir + "/no-manifest.jar",
|
||||
"GetSystemPackage", "system-no-manifest");
|
||||
|
||||
runSubProcess("Classpath package with manifest improperly resolved",
|
||||
"-cp", testClassesDir + "/manifest.jar", "GetSystemPackage",
|
||||
"non-system-manifest");
|
||||
|
||||
runSubProcess("Classpath package with no manifest improperly resolved",
|
||||
"-cp", testClassesDir + "/no-manifest.jar", "GetSystemPackage",
|
||||
"non-system-no-manifest");
|
||||
|
||||
}
|
||||
|
||||
private static void buildJar(String name, Manifest man) throws Exception {
|
||||
JarBuilder jar = new JarBuilder(tmpFolder, name, man);
|
||||
jar.addClassFile("package2/Class2.class",
|
||||
testClassesDir + "/package2/Class2.class");
|
||||
jar.addClassFile("GetSystemPackage.class",
|
||||
testClassesDir + "/GetSystemPackage.class");
|
||||
jar.addClassFile("GetSystemPackageClassLoader.class",
|
||||
testClassesDir + "/GetSystemPackageClassLoader.class");
|
||||
jar.build();
|
||||
}
|
||||
|
||||
private static void runSubProcess(String messageOnError, String ... args)
|
||||
throws Exception
|
||||
{
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
|
||||
int res = pb.directory(tmpFolder).inheritIO().start().waitFor();
|
||||
if (res != 0) {
|
||||
throw new RuntimeException(messageOnError);
|
||||
}
|
||||
}
|
||||
|
||||
private static void verifyPackage(boolean hasManifest,
|
||||
boolean isSystemPackage) throws Exception
|
||||
{
|
||||
Class c = Class.forName("package2.Class2");
|
||||
Package pkg = c.getPackage();
|
||||
if (pkg == null || pkg != Package.getPackage("package2") ||
|
||||
!"package2".equals(pkg.getName())) {
|
||||
fail("package2 not found via Package.getPackage()");
|
||||
}
|
||||
|
||||
String specificationTitle = pkg.getSpecificationTitle();
|
||||
if (!"package2".equals(pkg.getName())) {
|
||||
fail("Invalid package for Class2");
|
||||
}
|
||||
|
||||
if (hasManifest && (specificationTitle == null
|
||||
|| !manifestTitle.equals(specificationTitle))) {
|
||||
fail("Invalid manifest for package " + pkg.getName());
|
||||
}
|
||||
if (!hasManifest && specificationTitle != null) {
|
||||
fail("Invalid manifest for package " + pkg.getName() + ": was " +
|
||||
specificationTitle + " expected: null");
|
||||
}
|
||||
|
||||
// force the use of a classloader with no parent, then retrieve the
|
||||
// package in a way that bypasses the classloader pkg maps
|
||||
GetSystemPackageClassLoader classLoader =
|
||||
new GetSystemPackageClassLoader();
|
||||
Package systemPkg = classLoader.getSystemPackage("package2");
|
||||
|
||||
if (findPackage("java.lang") == null) {
|
||||
fail("java.lang not found via Package.getPackages()");
|
||||
}
|
||||
Package foundPackage = findPackage("package2");
|
||||
if (isSystemPackage) {
|
||||
if (systemPkg == null) {
|
||||
fail("System package could not be found via getSystemPackage");
|
||||
}
|
||||
if (foundPackage != systemPkg || systemPkg != pkg) {
|
||||
fail("Inconsistent package found via Package.getPackages()");
|
||||
}
|
||||
} else {
|
||||
if (systemPkg != null) {
|
||||
fail("Non-system package could be found via getSystemPackage");
|
||||
}
|
||||
if (foundPackage == null) {
|
||||
fail("Non-system package not found via Package.getPackages()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Package findPackage(String name) {
|
||||
Package[] packages = Package.getPackages();
|
||||
for (Package p : packages) {
|
||||
System.out.println(p);
|
||||
if (p.getName().equals(name)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void fail(String message) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This classloader bypasses the system classloader to give as direct access
|
||||
* to Package.getSystemPackage() as possible
|
||||
*/
|
||||
class GetSystemPackageClassLoader extends ClassLoader {
|
||||
|
||||
public GetSystemPackageClassLoader() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
public Package getSystemPackage(String name) {
|
||||
return super.getPackage(name);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper class for building jar files
|
||||
*/
|
||||
class JarBuilder {
|
||||
|
||||
private JarOutputStream os;
|
||||
|
||||
public JarBuilder(File tmpFolder, String jarName, Manifest manifest)
|
||||
throws FileNotFoundException, IOException
|
||||
{
|
||||
File jarFile = new File(tmpFolder, jarName);
|
||||
if (manifest != null) {
|
||||
this.os = new JarOutputStream(new FileOutputStream(jarFile),
|
||||
manifest);
|
||||
} else {
|
||||
this.os = new JarOutputStream(new FileOutputStream(jarFile));
|
||||
}
|
||||
}
|
||||
|
||||
public void addClassFile(String pathFromRoot, String file)
|
||||
throws IOException
|
||||
{
|
||||
byte[] buf = new byte[1024];
|
||||
try (FileInputStream in = new FileInputStream(file)) {
|
||||
JarEntry entry = new JarEntry(pathFromRoot);
|
||||
os.putNextEntry(entry);
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
os.write(buf, 0, len);
|
||||
}
|
||||
os.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
public void build() throws IOException {
|
||||
os.close();
|
||||
}
|
||||
}
|
41
jdk/test/java/lang/System/finalization/FinInterrupt.java
Normal file
41
jdk/test/java/lang/System/finalization/FinInterrupt.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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 4354680
|
||||
* @summary runFinalization() should not clear or ignore interrupt bit
|
||||
* @run main FinInterrupt
|
||||
*/
|
||||
|
||||
public class FinInterrupt {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Thread.currentThread().interrupt();
|
||||
System.runFinalization();
|
||||
if (Thread.interrupted()) {
|
||||
System.out.println("Passed: interrupt bit was still set.");
|
||||
} else {
|
||||
throw new AssertionError("interrupt bit was cleared");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2014 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,8 @@ import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import jdk.testlibrary.LockFreeLogManager;
|
||||
|
||||
/**
|
||||
* ThreadStateController allows a thread to request this thread to transition
|
||||
* to a specific thread state. The {@linkplain #transitionTo request} is
|
||||
@ -94,8 +96,12 @@ public class ThreadStateController extends Thread {
|
||||
private static final int S_TERMINATE = 8;
|
||||
|
||||
// for debugging
|
||||
private AtomicInteger iterations = new AtomicInteger();
|
||||
private AtomicInteger interrupted = new AtomicInteger();
|
||||
private final AtomicInteger iterations = new AtomicInteger();
|
||||
private final AtomicInteger interrupted = new AtomicInteger();
|
||||
|
||||
private final LockFreeLogManager logManager = new LockFreeLogManager();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// this thread has started
|
||||
while (!done) {
|
||||
@ -119,13 +125,13 @@ public class ThreadStateController extends Thread {
|
||||
break;
|
||||
}
|
||||
case S_BLOCKED: {
|
||||
System.out.format("%d: %s is going to block (interations %d)%n",
|
||||
getId(), getName(), iterations.get());
|
||||
log("%d: %s is going to block (iterations %d)%n",
|
||||
getId(), getName(), iterations.get());
|
||||
stateChange(nextState);
|
||||
// going to block on lock
|
||||
synchronized (lock) {
|
||||
System.out.format("%d: %s acquired the lock (interations %d)%n",
|
||||
getId(), getName(), iterations.get());
|
||||
log("%d: %s acquired the lock (iterations %d)%n",
|
||||
getId(), getName(), iterations.get());
|
||||
try {
|
||||
// this thread has escaped the BLOCKED state
|
||||
// release the lock and a short wait before continue
|
||||
@ -139,13 +145,13 @@ public class ThreadStateController extends Thread {
|
||||
}
|
||||
case S_WAITING: {
|
||||
synchronized (lock) {
|
||||
System.out.format("%d: %s is going to waiting (interations %d interrupted %d)%n",
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
log("%d: %s is going to waiting (iterations %d interrupted %d)%n",
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
try {
|
||||
stateChange(nextState);
|
||||
lock.wait();
|
||||
System.out.format("%d: %s wakes up from waiting (interations %d interrupted %d)%n",
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
log("%d: %s wakes up from waiting (iterations %d interrupted %d)%n",
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
interrupted.incrementAndGet();
|
||||
@ -155,13 +161,13 @@ public class ThreadStateController extends Thread {
|
||||
}
|
||||
case S_TIMED_WAITING: {
|
||||
synchronized (lock) {
|
||||
System.out.format("%d: %s is going to timed waiting (interations %d interrupted %d)%n",
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
log("%d: %s is going to timed waiting (iterations %d interrupted %d)%n",
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
try {
|
||||
stateChange(nextState);
|
||||
lock.wait(10000);
|
||||
System.out.format("%d: %s wakes up from timed waiting (interations %d interrupted %d)%n",
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
log("%d: %s wakes up from timed waiting (iterations %d interrupted %d)%n",
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
interrupted.incrementAndGet();
|
||||
@ -170,23 +176,23 @@ public class ThreadStateController extends Thread {
|
||||
break;
|
||||
}
|
||||
case S_PARKED: {
|
||||
System.out.format("%d: %s is going to park (interations %d)%n",
|
||||
getId(), getName(), iterations.get());
|
||||
log("%d: %s is going to park (iterations %d)%n",
|
||||
getId(), getName(), iterations.get());
|
||||
stateChange(nextState);
|
||||
LockSupport.park();
|
||||
break;
|
||||
}
|
||||
case S_TIMED_PARKED: {
|
||||
System.out.format("%d: %s is going to timed park (interations %d)%n",
|
||||
getId(), getName(), iterations.get());
|
||||
log("%d: %s is going to timed park (iterations %d)%n",
|
||||
getId(), getName(), iterations.get());
|
||||
long deadline = System.currentTimeMillis() + 10000*1000;
|
||||
stateChange(nextState);
|
||||
LockSupport.parkUntil(deadline);
|
||||
break;
|
||||
}
|
||||
case S_SLEEPING: {
|
||||
System.out.format("%d: %s is going to sleep (interations %d interrupted %d)%n",
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
log("%d: %s is going to sleep (iterations %d interrupted %d)%n",
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
try {
|
||||
stateChange(nextState);
|
||||
Thread.sleep(1000000);
|
||||
@ -219,8 +225,8 @@ public class ThreadStateController extends Thread {
|
||||
if (newState == nextState) {
|
||||
state = nextState;
|
||||
phaser.arrive();
|
||||
System.out.format("%d: state change: %s %s%n",
|
||||
getId(), toStateName(nextState), phaserToString(phaser));
|
||||
log("%d: state change: %s %s%n",
|
||||
getId(), toStateName(nextState), phaserToString(phaser));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -270,12 +276,12 @@ public class ThreadStateController extends Thread {
|
||||
|
||||
private void nextState(int s) throws InterruptedException {
|
||||
final long id = Thread.currentThread().getId();
|
||||
System.out.format("%d: wait until the thread transitions to %s %s%n",
|
||||
id, toStateName(s), phaserToString(phaser));
|
||||
log("%d: wait until the thread transitions to %s %s%n",
|
||||
id, toStateName(s), phaserToString(phaser));
|
||||
this.newState = s;
|
||||
int phase = phaser.arrive();
|
||||
System.out.format("%d: awaiting party arrive %s %s%n",
|
||||
id, toStateName(s), phaserToString(phaser));
|
||||
log("%d: awaiting party arrive %s %s%n",
|
||||
id, toStateName(s), phaserToString(phaser));
|
||||
for (;;) {
|
||||
// when this thread has changed its state before it waits or parks
|
||||
// on a lock, a potential race might happen if it misses the notify
|
||||
@ -301,20 +307,22 @@ public class ThreadStateController extends Thread {
|
||||
}
|
||||
try {
|
||||
phaser.awaitAdvanceInterruptibly(phase, 100, TimeUnit.MILLISECONDS);
|
||||
System.out.format("%d: arrived at %s %s%n",
|
||||
id, toStateName(s), phaserToString(phaser));
|
||||
log("%d: arrived at %s %s%n",
|
||||
id, toStateName(s), phaserToString(phaser));
|
||||
return;
|
||||
} catch (TimeoutException ex) {
|
||||
// this thread hasn't arrived at this phase
|
||||
System.out.format("%d: Timeout: %s%n", id, phaser);
|
||||
log("%d: Timeout: %s%n", id, phaser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String phaserToString(Phaser p) {
|
||||
return "[phase = " + p.getPhase() +
|
||||
" parties = " + p.getRegisteredParties() +
|
||||
" arrived = " + p.getArrivedParties() + "]";
|
||||
}
|
||||
|
||||
private String toStateName(int state) {
|
||||
switch (state) {
|
||||
case S_RUNNABLE:
|
||||
@ -337,4 +345,20 @@ public class ThreadStateController extends Thread {
|
||||
return "unknown " + state;
|
||||
}
|
||||
}
|
||||
|
||||
private void log(String msg, Object ... params) {
|
||||
logManager.log(msg, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the controller to complete the test run and returns the
|
||||
* generated log
|
||||
* @return The controller log
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public String getLog() throws InterruptedException {
|
||||
this.join();
|
||||
|
||||
return logManager.toString();
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ import static java.lang.Thread.State.*;
|
||||
* Thread.getState().
|
||||
*
|
||||
* @author Mandy Chung
|
||||
* @library /lib/testlibrary
|
||||
* @build jdk.testlibrary.*
|
||||
* @build ThreadStateTest ThreadStateController
|
||||
* @run main/othervm -Xmixed ThreadStateTest
|
||||
*/
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2014, 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,6 +31,8 @@
|
||||
* @author Mandy Chung
|
||||
*
|
||||
* @library ../../Thread
|
||||
* @library /lib/testlibrary
|
||||
* @build jdk.testlibrary.*
|
||||
* @build ThreadMXBeanStateTest ThreadStateController
|
||||
* @run main ThreadMXBeanStateTest
|
||||
*/
|
||||
@ -44,15 +46,17 @@ public class ThreadMXBeanStateTest {
|
||||
private static final ThreadMXBean tm = ManagementFactory.getThreadMXBean();
|
||||
|
||||
static class Lock {
|
||||
private String name;
|
||||
private final String name;
|
||||
Lock(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
private static Lock globalLock = new Lock("my lock");
|
||||
|
||||
private static final Lock globalLock = new Lock("my lock");
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
// Force thread state initialization now before the test
|
||||
@ -109,7 +113,7 @@ public class ThreadMXBeanStateTest {
|
||||
thread.checkThreadState(TERMINATED);
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
System.out.println(thread.getLog());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("TEST FAILED: Unexpected exception.");
|
||||
|
@ -35,6 +35,7 @@ import java.sql.SQLPermission;
|
||||
import java.util.Enumeration;
|
||||
import java.util.PropertyPermission;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.logging.LoggingPermission;
|
||||
|
||||
/*
|
||||
* Simple Policy class that supports the required Permissions to validate the
|
||||
@ -57,7 +58,8 @@ public class TestPolicy extends Policy {
|
||||
* Policy used by the JDBC tests Possible values are: all (ALLPermissions),
|
||||
* setLog (SQLPemission("setLog"), deregisterDriver
|
||||
* (SQLPermission("deregisterDriver") (SQLPermission("deregisterDriver"),
|
||||
* and setSyncFactory(SQLPermission(setSyncFactory),
|
||||
* setSyncFactory(SQLPermission(setSyncFactory), and also
|
||||
* LoggerPermission("control", null) when setting a Level
|
||||
*
|
||||
* @param policy Permissions to set
|
||||
*/
|
||||
@ -79,6 +81,11 @@ public class TestPolicy extends Policy {
|
||||
setMinimalPermissions();
|
||||
permissions.add(new SQLPermission("setSyncFactory"));
|
||||
break;
|
||||
case "setSyncFactoryLogger":
|
||||
setMinimalPermissions();
|
||||
permissions.add(new SQLPermission("setSyncFactory"));
|
||||
permissions.add(new LoggingPermission("control", null));
|
||||
break;
|
||||
default:
|
||||
setMinimalPermissions();
|
||||
}
|
||||
|
@ -68,10 +68,9 @@ public class InitialContextTest {
|
||||
Path dst = tmp.resolve("Test.java");
|
||||
Files.copy(src, dst);
|
||||
|
||||
javac(tmp, dst);
|
||||
|
||||
Path build = Files.createDirectory(tmp.resolve("build"));
|
||||
Files.copy(tmp.resolve("Test.class"), build.resolve("Test.class"));
|
||||
|
||||
javac(build, dst);
|
||||
|
||||
Map<String, String> props
|
||||
= singletonMap(Context.INITIAL_CONTEXT_FACTORY, factoryClassFqn);
|
||||
@ -107,13 +106,13 @@ public class InitialContextTest {
|
||||
Path dst1 = createFactoryFrom(templatesHome().resolve("factory.template"),
|
||||
factoryClassFqn, tmp);
|
||||
|
||||
javac(tmp, dst);
|
||||
Path build = Files.createDirectory(tmp.resolve("build"));
|
||||
|
||||
javac(build, dst);
|
||||
Path explodedJar = Files.createDirectory(tmp.resolve("exploded-jar"));
|
||||
javac(explodedJar, dst1);
|
||||
jar(tmp.resolve("test.jar"), explodedJar);
|
||||
|
||||
Path build = Files.createDirectory(tmp.resolve("build"));
|
||||
Files.copy(tmp.resolve("Test.class"), build.resolve("Test.class"));
|
||||
Files.copy(tmp.resolve("test.jar"), build.resolve("test.jar"));
|
||||
|
||||
Map<String, String> props
|
||||
@ -191,7 +190,9 @@ public class InitialContextTest {
|
||||
Path dst1 = createFactoryFrom(templatesHome().resolve("broken_factory.template"),
|
||||
factoryClassFqn, tmp);
|
||||
|
||||
javac(tmp, dst);
|
||||
Path build = Files.createDirectory(tmp.resolve("build"));
|
||||
|
||||
javac(build, dst);
|
||||
|
||||
Path explodedJar = Files.createDirectory(tmp.resolve("exploded-jar"));
|
||||
Path services = Files.createDirectories(explodedJar.resolve("META-INF")
|
||||
@ -208,15 +209,12 @@ public class InitialContextTest {
|
||||
javac(explodedJar, dst1);
|
||||
jar(tmp.resolve("test.jar"), explodedJar);
|
||||
|
||||
Path build = Files.createDirectory(tmp.resolve("build"));
|
||||
Files.copy(tmp.resolve("Test.class"), build.resolve("Test.class"));
|
||||
Files.copy(tmp.resolve("test.jar"), build.resolve("test.jar"));
|
||||
|
||||
Map<String, String> props = new HashMap<>();
|
||||
props.put("java.ext.dirs", build.toString());
|
||||
props.put(Context.INITIAL_CONTEXT_FACTORY, factoryClassFqn);
|
||||
Map<String, String> props
|
||||
= singletonMap(Context.INITIAL_CONTEXT_FACTORY, factoryClassFqn);
|
||||
|
||||
Result r = java(props, singleton(build), "Test");
|
||||
Result r = java(props, asList(build.resolve("test.jar"), build), "Test");
|
||||
|
||||
if (r.exitValue == 0 || !verifyOutput(r.output, factoryClassFqn))
|
||||
throw new RuntimeException(r.output);
|
||||
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
package test.rowset.spi;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.rowset.spi.SyncFactoryException;
|
||||
import static org.testng.Assert.*;
|
||||
import org.testng.annotations.Test;
|
||||
import util.BaseTest;
|
||||
|
||||
public class SyncFactoryExceptionTests extends BaseTest {
|
||||
|
||||
/*
|
||||
* Create SyncFactoryException with no-arg constructor
|
||||
*/
|
||||
@Test
|
||||
public void test01() {
|
||||
SyncFactoryException ex = new SyncFactoryException();
|
||||
assertTrue(ex.getMessage() == null
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SyncFactoryException with message
|
||||
*/
|
||||
@Test
|
||||
public void test02() {
|
||||
SyncFactoryException ex = new SyncFactoryException(reason);
|
||||
assertTrue(ex.getMessage().equals(reason)
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the ordering of the returned Exceptions is correct using
|
||||
* for-each loop
|
||||
*/
|
||||
@Test
|
||||
public void test03() {
|
||||
SyncFactoryException ex = new SyncFactoryException("Exception 1");
|
||||
ex.initCause(t1);
|
||||
SyncFactoryException ex1 = new SyncFactoryException("Exception 2");
|
||||
SyncFactoryException ex2 = new SyncFactoryException("Exception 3");
|
||||
ex2.initCause(t2);
|
||||
ex.setNextException(ex1);
|
||||
ex.setNextException(ex2);
|
||||
int num = 0;
|
||||
for (Throwable e : ex) {
|
||||
assertTrue(msgs[num++].equals(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the ordering of the returned Exceptions is correct using
|
||||
* traditional while loop
|
||||
*/
|
||||
@Test
|
||||
public void test04() {
|
||||
SQLException ex = new SyncFactoryException("Exception 1");
|
||||
ex.initCause(t1);
|
||||
SyncFactoryException ex1 = new SyncFactoryException("Exception 2");
|
||||
SyncFactoryException ex2 = new SyncFactoryException("Exception 3");
|
||||
ex2.initCause(t2);
|
||||
ex.setNextException(ex1);
|
||||
ex.setNextException(ex2);
|
||||
int num = 0;
|
||||
while (ex != null) {
|
||||
assertTrue(msgs[num++].equals(ex.getMessage()));
|
||||
Throwable c = ex.getCause();
|
||||
while (c != null) {
|
||||
assertTrue(msgs[num++].equals(c.getMessage()));
|
||||
c = c.getCause();
|
||||
}
|
||||
ex = ex.getNextException();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize a SyncFactoryException and make sure you can read it back properly
|
||||
*/
|
||||
@Test
|
||||
public void test05() throws Exception {
|
||||
SyncFactoryException e = new SyncFactoryException(reason);
|
||||
SyncFactoryException ex1 = createSerializedException(e);
|
||||
assertTrue(ex1.getMessage().equals(reason)
|
||||
&& ex1.getSQLState() == null
|
||||
&& ex1.getCause() == null
|
||||
&& ex1.getErrorCode() == 0);
|
||||
}
|
||||
}
|
@ -27,13 +27,13 @@ import java.security.Policy;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.sql.rowset.spi.SyncFactory;
|
||||
import javax.sql.rowset.spi.SyncFactoryException;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import util.BaseTest;
|
||||
import util.StubContext;
|
||||
import util.TestPolicy;
|
||||
|
||||
public class SyncFactoryPermissionsTests extends BaseTest {
|
||||
@ -41,6 +41,7 @@ public class SyncFactoryPermissionsTests extends BaseTest {
|
||||
Context ctx;
|
||||
private static Policy policy;
|
||||
private static SecurityManager sm;
|
||||
private final Logger alogger = Logger.getLogger(this.getClass().getName());
|
||||
|
||||
/*
|
||||
* Install a SeeurityManager along with a base Policy to allow testNG to run
|
||||
@ -67,13 +68,7 @@ public class SyncFactoryPermissionsTests extends BaseTest {
|
||||
public SyncFactoryPermissionsTests() {
|
||||
policy = Policy.getPolicy();
|
||||
sm = System.getSecurityManager();
|
||||
|
||||
try {
|
||||
ctx = new InitialContext();
|
||||
} catch (NamingException ex) {
|
||||
Logger.getLogger(SyncFactoryPermissionsTests.class.getName()).
|
||||
log(Level.SEVERE, null, ex);
|
||||
}
|
||||
ctx = new StubContext();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -86,13 +81,21 @@ public class SyncFactoryPermissionsTests extends BaseTest {
|
||||
SyncFactory.setJNDIContext(ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that a SyncFactoryException is thrown if the Logger is null
|
||||
*/
|
||||
@Test(expectedExceptions = SyncFactoryException.class)
|
||||
public void test00() throws SyncFactoryException {
|
||||
Logger l = SyncFactory.getLogger();
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setJNDIContext succeeds if SQLPermission("setSyncFactory")
|
||||
* has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test1() throws Exception {
|
||||
Policy.setPolicy(new TestPolicy("setSyncFactory"));
|
||||
public void test01() throws Exception {
|
||||
setPolicy(new TestPolicy("setSyncFactory"));
|
||||
SyncFactory.setJNDIContext(ctx);
|
||||
}
|
||||
|
||||
@ -100,8 +103,77 @@ public class SyncFactoryPermissionsTests extends BaseTest {
|
||||
* Validate that setJNDIContext succeeds if AllPermissions has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test2() throws Exception {
|
||||
public void test02() throws Exception {
|
||||
setPolicy(new TestPolicy("all"));
|
||||
SyncFactory.setJNDIContext(ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that AccessControlException is thrown if
|
||||
* SQLPermission("setSyncFactory") has not been granted
|
||||
*/
|
||||
@Test(expectedExceptions = AccessControlException.class)
|
||||
public void test03() throws Exception {
|
||||
setPolicy(new TestPolicy());
|
||||
SyncFactory.setLogger(alogger);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setLogger succeeds if SQLPermission("setSyncFactory")
|
||||
* has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test04() throws Exception {
|
||||
setPolicy(new TestPolicy("setSyncFactory"));
|
||||
SyncFactory.setLogger(alogger);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setLogger succeeds if AllPermissions has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test05() throws Exception {
|
||||
setPolicy(new TestPolicy("all"));
|
||||
SyncFactory.setLogger(alogger);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that AccessControlException is thrown if
|
||||
* SQLPermission("setSyncFactory") has not been granted
|
||||
*/
|
||||
@Test(expectedExceptions = AccessControlException.class)
|
||||
public void test06() throws Exception {
|
||||
setPolicy(new TestPolicy());
|
||||
SyncFactory.setLogger(alogger, Level.INFO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that AccessControlException is thrown if
|
||||
* SQLPermission("setSyncFactory") and LoggingPermission("control", null)
|
||||
* have not been granted
|
||||
*/
|
||||
@Test(expectedExceptions = AccessControlException.class)
|
||||
public void test07() throws Exception {
|
||||
setPolicy(new TestPolicy("setSyncFactory"));
|
||||
SyncFactory.setLogger(alogger, Level.INFO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setLogger succeeds if SQLPermission("setSyncFactory")
|
||||
* has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test08() throws Exception {
|
||||
setPolicy(new TestPolicy("setSyncFactoryLogger"));
|
||||
SyncFactory.setLogger(alogger, Level.INFO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setLogger succeeds if AllPermissions has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test09() throws Exception {
|
||||
setPolicy(new TestPolicy("all"));
|
||||
SyncFactory.setLogger(alogger, Level.INFO);
|
||||
}
|
||||
}
|
||||
|
220
jdk/test/javax/sql/testng/test/rowset/spi/SyncFactoryTests.java
Normal file
220
jdk/test/javax/sql/testng/test/rowset/spi/SyncFactoryTests.java
Normal file
@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
package test.rowset.spi;
|
||||
|
||||
import com.sun.rowset.providers.RIOptimisticProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.naming.Context;
|
||||
import javax.sql.rowset.spi.SyncFactory;
|
||||
import javax.sql.rowset.spi.SyncFactoryException;
|
||||
import javax.sql.rowset.spi.SyncProvider;
|
||||
import static org.testng.Assert.*;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import util.PropertyStubProvider;
|
||||
import util.StubSyncProvider;
|
||||
import util.StubContext;
|
||||
|
||||
//com.sun.jndi.ldap.LdapCtxFactory
|
||||
public class SyncFactoryTests {
|
||||
private static String origFactory;
|
||||
|
||||
private final String stubProvider = "util.StubSyncProvider";
|
||||
private final String propertyStubProvider = "util.PropertyStubProvider";
|
||||
private final Logger alogger = Logger.getLogger(this.getClass().getName());
|
||||
// Initial providers including those set via a property
|
||||
List<String> initialProviders;
|
||||
// All providers including those specifically registered
|
||||
List<String> allProviders;
|
||||
private Context ctx= null;
|
||||
|
||||
public SyncFactoryTests() {
|
||||
|
||||
// Add a provider via a property
|
||||
System.setProperty("rowset.provider.classname", propertyStubProvider);
|
||||
initialProviders = Arrays.asList(
|
||||
"com.sun.rowset.providers.RIOptimisticProvider",
|
||||
"com.sun.rowset.providers.RIXMLProvider",
|
||||
propertyStubProvider);
|
||||
allProviders = new ArrayList<>();
|
||||
allProviders.addAll(initialProviders);
|
||||
allProviders.add(stubProvider);
|
||||
ctx = new StubContext();
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void setUpMethod() throws Exception {
|
||||
// Make sure the provider provider that is registered is removed
|
||||
// before each run
|
||||
SyncFactory.unregisterProvider(stubProvider);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate a non-null factory is returned
|
||||
*/
|
||||
@Test
|
||||
public void test() throws SyncFactoryException {
|
||||
SyncFactory syncFactory = SyncFactory.getSyncFactory();
|
||||
assertTrue(syncFactory != null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that the correct SyncProvider is returned for the specified
|
||||
* providerID for the provider registered via a property
|
||||
*/
|
||||
@Test
|
||||
public void test00() throws SyncFactoryException {
|
||||
SyncProvider p = SyncFactory.getInstance(propertyStubProvider);
|
||||
assertTrue(p instanceof PropertyStubProvider);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that the correct SyncProvider is returned for the specified
|
||||
* providerID
|
||||
*/
|
||||
@Test
|
||||
public void test01() throws SyncFactoryException {
|
||||
SyncFactory.registerProvider(stubProvider);
|
||||
SyncProvider p = SyncFactory.getInstance(stubProvider);
|
||||
assertTrue(p instanceof StubSyncProvider);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that the Default SyncProvider is returned if an empty String is
|
||||
* passed or if an invalid providerID is specified
|
||||
*/
|
||||
@Test
|
||||
public void test02() throws SyncFactoryException {
|
||||
SyncProvider p = SyncFactory.getInstance("");
|
||||
assertTrue(p instanceof RIOptimisticProvider);
|
||||
// Attempt to get an invalid provider and get the default provider
|
||||
p = SyncFactory.getInstance("util.InvalidSyncProvider");
|
||||
assertTrue(p instanceof RIOptimisticProvider);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that a SyncFactoryException is thrown if the ProviderID is null
|
||||
*/
|
||||
@Test(expectedExceptions = SyncFactoryException.class)
|
||||
public void test03() throws SyncFactoryException {
|
||||
SyncProvider p = SyncFactory.getInstance(null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that a SyncFactoryException is thrown if the Logger is null
|
||||
*/
|
||||
@Test(expectedExceptions = SyncFactoryException.class,enabled=true)
|
||||
public void test04() throws SyncFactoryException {
|
||||
Logger l = SyncFactory.getLogger();
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the correct logger is returned by getLogger
|
||||
*/
|
||||
@Test
|
||||
public void test05() throws SyncFactoryException {
|
||||
SyncFactory.setLogger(alogger);
|
||||
Logger l = SyncFactory.getLogger();
|
||||
assertTrue(l.equals(alogger));
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the correct logger is returned by getLogger
|
||||
*/
|
||||
@Test
|
||||
public void test06() throws SyncFactoryException {
|
||||
SyncFactory.setLogger(alogger, Level.INFO);
|
||||
Logger l = SyncFactory.getLogger();
|
||||
assertTrue(l.equals(alogger));
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that a driver that is registered is returned by
|
||||
* getRegisteredProviders and if it is unregistered, that it is
|
||||
* not returned by getRegisteredProviders
|
||||
*/
|
||||
@Test
|
||||
public void test07() throws SyncFactoryException {
|
||||
|
||||
// Validate that only the default providers and any specified via
|
||||
// a System property are available
|
||||
validateProviders(initialProviders);
|
||||
|
||||
// Register a provider and make sure it is avaiable
|
||||
SyncFactory.registerProvider(stubProvider);
|
||||
validateProviders(allProviders);
|
||||
|
||||
// Check that if a provider is unregistered, it does not show as
|
||||
// registered
|
||||
SyncFactory.unregisterProvider(stubProvider);
|
||||
validateProviders(initialProviders);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setJNDIContext throws a SyncFactoryException if the
|
||||
* context is null
|
||||
*/
|
||||
@Test(expectedExceptions = SyncFactoryException.class, enabled=true)
|
||||
public void test08() throws Exception {
|
||||
SyncFactory.setJNDIContext(null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setJNDIContext succeeds
|
||||
*/
|
||||
@Test(enabled=true)
|
||||
public void test09() throws Exception {
|
||||
SyncFactory.setJNDIContext(ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility method to validate the expected providers are regsitered
|
||||
*/
|
||||
private void validateProviders(List<String> expectedProviders)
|
||||
throws SyncFactoryException {
|
||||
List<String> results = new ArrayList<>();
|
||||
Enumeration<SyncProvider> providers = SyncFactory.getRegisteredProviders();
|
||||
|
||||
while (providers.hasMoreElements()) {
|
||||
SyncProvider p = providers.nextElement();
|
||||
results.add(p.getProviderID());
|
||||
}
|
||||
assertTrue(expectedProviders.containsAll(results)
|
||||
&& results.size() == expectedProviders.size());
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility method to dump out SyncProvider info for a registered provider
|
||||
*/
|
||||
private void showImpl(SyncProvider impl) {
|
||||
System.out.println("Provider implementation:"
|
||||
+ "\nVendor: " + impl.getVendor()
|
||||
+ "\nVersion: " + impl.getVersion()
|
||||
+ "\nProviderID: " + impl.getProviderID());
|
||||
}
|
||||
}
|
@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
package test.rowset.spi;
|
||||
|
||||
import com.sun.rowset.internal.SyncResolverImpl;
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.rowset.spi.SyncProviderException;
|
||||
import static org.testng.Assert.*;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import util.BaseTest;
|
||||
import util.StubSyncResolver;
|
||||
|
||||
public class SyncProviderExceptionTests extends BaseTest {
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
System.out.println(System.getProperty("java.naming.factory.initial"));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() throws Exception {
|
||||
}
|
||||
/*
|
||||
* Create SyncProviderException with no-arg constructor
|
||||
*/
|
||||
@Test
|
||||
public void test() {
|
||||
SyncProviderException ex = new SyncProviderException();
|
||||
assertTrue(ex.getMessage() == null
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0
|
||||
&& ex.getSyncResolver() instanceof SyncResolverImpl);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SyncProviderException with no-arg constructor and
|
||||
* call setSyncResolver to indicate the SyncResolver to use
|
||||
*/
|
||||
@Test
|
||||
public void test01() {
|
||||
SyncProviderException ex = new SyncProviderException();
|
||||
ex.setSyncResolver(new StubSyncResolver());
|
||||
assertTrue(ex.getMessage() == null
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0
|
||||
&& ex.getSyncResolver() instanceof StubSyncResolver);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SyncProviderException with message
|
||||
*/
|
||||
@Test
|
||||
public void test02() {
|
||||
SyncProviderException ex = new SyncProviderException(reason);
|
||||
assertTrue(ex.getMessage().equals(reason)
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0
|
||||
&& ex.getSyncResolver() instanceof SyncResolverImpl);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SyncProviderException with message and
|
||||
* call setSyncResolver to indicate the SyncResolver to use
|
||||
*/
|
||||
@Test
|
||||
public void test03() {
|
||||
SyncProviderException ex = new SyncProviderException(reason);
|
||||
ex.setSyncResolver(new StubSyncResolver());
|
||||
|
||||
assertTrue(ex.getMessage().equals(reason)
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0
|
||||
&& ex.getSyncResolver() instanceof StubSyncResolver);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SyncProviderException with and specify the SyncResolver to use
|
||||
*/
|
||||
@Test
|
||||
public void test04() {
|
||||
SyncProviderException ex = new SyncProviderException(new StubSyncResolver());
|
||||
assertTrue(ex.getMessage() == null
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0
|
||||
&& ex.getSyncResolver() instanceof StubSyncResolver);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the ordering of the returned Exceptions is correct using
|
||||
* for-each loop
|
||||
*/
|
||||
@Test
|
||||
public void test05() {
|
||||
SyncProviderException ex = new SyncProviderException("Exception 1");
|
||||
ex.initCause(t1);
|
||||
SyncProviderException ex1 = new SyncProviderException("Exception 2");
|
||||
SyncProviderException ex2 = new SyncProviderException("Exception 3");
|
||||
ex2.initCause(t2);
|
||||
ex.setNextException(ex1);
|
||||
ex.setNextException(ex2);
|
||||
int num = 0;
|
||||
for (Throwable e : ex) {
|
||||
assertTrue(msgs[num++].equals(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the ordering of the returned Exceptions is correct using
|
||||
* traditional while loop
|
||||
*/
|
||||
@Test
|
||||
public void test06() {
|
||||
SQLException ex = new SyncProviderException("Exception 1");
|
||||
ex.initCause(t1);
|
||||
SyncProviderException ex1 = new SyncProviderException("Exception 2");
|
||||
SyncProviderException ex2 = new SyncProviderException("Exception 3");
|
||||
ex2.initCause(t2);
|
||||
ex.setNextException(ex1);
|
||||
ex.setNextException(ex2);
|
||||
int num = 0;
|
||||
while (ex != null) {
|
||||
assertTrue(msgs[num++].equals(ex.getMessage()));
|
||||
Throwable c = ex.getCause();
|
||||
while (c != null) {
|
||||
assertTrue(msgs[num++].equals(c.getMessage()));
|
||||
c = c.getCause();
|
||||
}
|
||||
ex = ex.getNextException();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize a SyncProviderException and make sure you can read it back properly
|
||||
*/
|
||||
@Test
|
||||
public void test07() throws Exception {
|
||||
SyncProviderException e = new SyncProviderException(reason);
|
||||
SyncProviderException ex1 = createSerializedException(e);
|
||||
assertTrue(ex1.getMessage().equals(reason)
|
||||
&& ex1.getSQLState() == null
|
||||
&& ex1.getCause() == null
|
||||
&& ex1.getErrorCode() == 0
|
||||
&& ex1.getSyncResolver() instanceof SyncResolverImpl, ex1.getSyncResolver().getClass().getName());
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize a SyncProviderException and make sure you can read it back properly
|
||||
*/
|
||||
@Test
|
||||
public void test08() throws Exception {
|
||||
SyncProviderException e = new SyncProviderException(reason);
|
||||
e.setSyncResolver(new StubSyncResolver());
|
||||
|
||||
SyncProviderException ex1 = createSerializedException(e);
|
||||
assertTrue(ex1.getMessage().equals(reason)
|
||||
&& ex1.getSQLState() == null
|
||||
&& ex1.getCause() == null
|
||||
&& ex1.getErrorCode() == 0
|
||||
&& ex1.getSyncResolver() instanceof StubSyncResolver);
|
||||
}
|
||||
}
|
27
jdk/test/javax/sql/testng/util/PropertyStubProvider.java
Normal file
27
jdk/test/javax/sql/testng/util/PropertyStubProvider.java
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
package util;
|
||||
|
||||
public class PropertyStubProvider extends StubSyncProvider {
|
||||
|
||||
}
|
220
jdk/test/javax/sql/testng/util/StubContext.java
Normal file
220
jdk/test/javax/sql/testng/util/StubContext.java
Normal file
@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
package util;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class StubContext implements Context {
|
||||
|
||||
@Override
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookup(String name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind(Name name) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind(String name) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
|
||||
return new NamingEnumerationStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
|
||||
return new NamingEnumerationStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
|
||||
return new NamingEnumerationStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
|
||||
return new NamingEnumerationStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameParser getNameParser(Name name) throws NamingException {
|
||||
return new NameParserStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameParser getNameParser(String name) throws NamingException {
|
||||
return new NameParserStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String composeName(String name, String prefix) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object addToEnvironment(String propName, Object propVal) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object removeFromEnvironment(String propName) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hashtable<?, ?> getEnvironment() throws NamingException {
|
||||
return new Hashtable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameInNamespace() throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
class NamingEnumerationStub implements NamingEnumeration {
|
||||
|
||||
@Override
|
||||
public Object next() throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMore() throws NamingException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMoreElements() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object nextElement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class NameParserStub implements NameParser {
|
||||
|
||||
@Override
|
||||
public Name parse(String name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
92
jdk/test/javax/sql/testng/util/StubSyncProvider.java
Normal file
92
jdk/test/javax/sql/testng/util/StubSyncProvider.java
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
package util;
|
||||
|
||||
import javax.sql.RowSetReader;
|
||||
import javax.sql.RowSetWriter;
|
||||
import javax.sql.rowset.spi.SyncProvider;
|
||||
import javax.sql.rowset.spi.SyncProviderException;
|
||||
|
||||
public class StubSyncProvider extends SyncProvider {
|
||||
|
||||
/**
|
||||
* The unique provider identifier.
|
||||
*/
|
||||
private String providerID = "util.StubSyncProvider";
|
||||
|
||||
/**
|
||||
* The vendor name of this SyncProvider implementation
|
||||
*/
|
||||
private String vendorName = "Oracle Corporation";
|
||||
|
||||
/**
|
||||
* The version number of this SyncProvider implementation
|
||||
*/
|
||||
private String versionNumber = "1.0";
|
||||
|
||||
@Override
|
||||
public String getProviderID() {
|
||||
return providerID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowSetReader getRowSetReader() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowSetWriter getRowSetWriter() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProviderGrade() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDataSourceLock(int datasource_lock) throws SyncProviderException {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDataSourceLock() throws SyncProviderException {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int supportsUpdatableView() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return versionNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVendor() {
|
||||
return vendorName;
|
||||
}
|
||||
|
||||
}
|
1616
jdk/test/javax/sql/testng/util/StubSyncResolver.java
Normal file
1616
jdk/test/javax/sql/testng/util/StubSyncResolver.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,116 @@
|
||||
package parse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import org.testng.annotations.Test;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.ext.DefaultHandler2;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* JDK-6770436: Entity callback order differs between Java1.5 and Java1.6
|
||||
* https://bugs.openjdk.java.net/browse/JDK-6770436
|
||||
*
|
||||
*/
|
||||
|
||||
public class EntityCharacterEventOrder {
|
||||
|
||||
protected final static String xmlEncoding = "ISO-8859-15";
|
||||
protected static Charset xmlEncodingCharset = null;
|
||||
|
||||
String _xml;
|
||||
static {
|
||||
xmlEncodingCharset = Charset.forName(xmlEncoding);
|
||||
}
|
||||
/**
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(JDK6770436Test.class);
|
||||
}
|
||||
*/
|
||||
@Test
|
||||
public void entityCallbackOrderJava() throws SAXException, IOException {
|
||||
final String input = "<element> & some more text</element>";
|
||||
|
||||
final MockContentHandler handler = new MockContentHandler();
|
||||
final XMLReader xmlReader = XMLReaderFactory.createXMLReader();
|
||||
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
|
||||
|
||||
xmlReader.parse(new InputSource(new StringReader(input)));
|
||||
|
||||
final List<String> events = handler.getEvents();
|
||||
printEvents(events);
|
||||
assertCallbackOrder(events); //regression from JDK5
|
||||
}
|
||||
|
||||
private void assertCallbackOrder(final List<String> events) {
|
||||
assertEquals("startDocument", events.get(0));
|
||||
assertEquals("startElement 'element'", events.get(1));
|
||||
assertEquals("characters ' '", events.get(2));
|
||||
assertEquals("startEntity 'amp'", events.get(3));
|
||||
assertEquals("characters '&'", events.get(4));
|
||||
assertEquals("endEntity 'amp'", events.get(5));
|
||||
assertEquals("characters ' some more text'", events.get(6));
|
||||
assertEquals("endElement 'element'", events.get(7));
|
||||
assertEquals("endDocument", events.get(8));
|
||||
}
|
||||
|
||||
private void printEvents(final List<String> events) {
|
||||
events.stream().forEach((e) -> {
|
||||
System.out.println(e);
|
||||
});
|
||||
}
|
||||
|
||||
private class MockContentHandler extends DefaultHandler2 {
|
||||
|
||||
private List<String> events;
|
||||
|
||||
public List<String> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDocument() throws SAXException {
|
||||
events = new ArrayList<String>();
|
||||
events.add("startDocument");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
events.add("characters '" + new String(ch, start, length) + "'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException {
|
||||
events.add("startElement '" + name + "'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String name) throws SAXException {
|
||||
events.add("endElement '" + name + "'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endDocument() throws SAXException {
|
||||
events.add("endDocument");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startEntity(String name) throws SAXException {
|
||||
events.add("startEntity '" + name + "'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endEntity(String name) throws SAXException {
|
||||
events.add("endEntity '" + name + "'");
|
||||
}
|
||||
}
|
||||
}
|
48
jdk/test/jdk/net/Sockets/SupportedOptions.java
Normal file
48
jdk/test/jdk/net/Sockets/SupportedOptions.java
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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 8062744
|
||||
* @run main SupportedOptions
|
||||
*/
|
||||
|
||||
import java.net.*;
|
||||
import java.io.IOException;
|
||||
import jdk.net.*;
|
||||
|
||||
public class SupportedOptions {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (!Sockets.supportedOptions(ServerSocket.class)
|
||||
.contains(StandardSocketOptions.IP_TOS)) {
|
||||
throw new RuntimeException("Test failed");
|
||||
}
|
||||
// Now set the option
|
||||
ServerSocket ss = new ServerSocket();
|
||||
if (!ss.supportedOptions().contains(StandardSocketOptions.IP_TOS)) {
|
||||
throw new RuntimeException("Test failed");
|
||||
}
|
||||
Sockets.setOption(ss, java.net.StandardSocketOptions.IP_TOS, 128);
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
|
||||
package jdk.testlibrary;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Formatter;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* A log manager designed specifically to allow collecting ordered log messages
|
||||
* in a multi-threaded environment without involving any kind of locking.
|
||||
* <p>
|
||||
* It is particularly useful in situations when one needs to assert various
|
||||
* details about the tested thread state or the locks it hold while also wanting
|
||||
* to produce diagnostic log messages.
|
||||
* <p>
|
||||
* The log manager does not provide any guarantees about the completness of the
|
||||
* logs written from different threads - it is up to the caller to make sure
|
||||
* {@code toString()} method is called only when all the activity has ceased
|
||||
* and the per-thread logs contain all the necessary data.
|
||||
*
|
||||
* @author Jaroslav Bachorik
|
||||
**/
|
||||
public class LockFreeLogManager {
|
||||
private final AtomicInteger logCntr = new AtomicInteger(0);
|
||||
private final Collection<Map<Integer, String>> allRecords = new ConcurrentLinkedQueue<>();
|
||||
private final ThreadLocal<Map<Integer, String>> records = new ThreadLocal<Map<Integer, String>>() {
|
||||
@Override
|
||||
protected Map<Integer, String> initialValue() {
|
||||
Map<Integer, String> m = new ConcurrentHashMap<>();
|
||||
allRecords.add(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Log a message
|
||||
* @param format Message format
|
||||
* @param params Message parameters
|
||||
*/
|
||||
public void log(String format, Object ... params) {
|
||||
int id = logCntr.getAndIncrement();
|
||||
try (Formatter formatter = new Formatter()) {
|
||||
records.get().put(id, formatter.format(format, params).toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will generate an aggregated log of chronologically ordered messages.
|
||||
* <p>
|
||||
* Make sure that you call this method only when all the related threads
|
||||
* have finished; otherwise you might get incomplete data.
|
||||
*
|
||||
* @return An aggregated log of chronologically ordered messages
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return allRecords.stream()
|
||||
.flatMap(m->m.entrySet().stream())
|
||||
.sorted((l, r)->l.getKey().compareTo(r.getKey()))
|
||||
.map(e->e.getValue())
|
||||
.collect(Collectors.joining());
|
||||
}
|
||||
}
|
106
jdk/test/sun/security/tools/jarsigner/DefaultSigalg.java
Normal file
106
jdk/test/sun/security/tools/jarsigner/DefaultSigalg.java
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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 8057810
|
||||
* @summary New defaults for DSA keys in jarsigner and keytool
|
||||
*/
|
||||
|
||||
import sun.security.pkcs.PKCS7;
|
||||
import sun.security.util.KeyUtil;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.KeyStore;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
public class DefaultSigalg {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// Three test cases
|
||||
String[] keyalgs = {"DSA", "RSA", "EC"};
|
||||
// Expected default keytool sigalg
|
||||
String[] sigalgs = {"SHA256withDSA", "SHA256withRSA", "SHA256withECDSA"};
|
||||
// Expected keysizes
|
||||
int[] keysizes = {2048, 2048, 256};
|
||||
// Expected jarsigner digest alg used in signature
|
||||
String[] digestalgs = {"SHA-256", "SHA-256", "SHA-256"};
|
||||
|
||||
// Create a jar file
|
||||
sun.tools.jar.Main m =
|
||||
new sun.tools.jar.Main(System.out, System.err, "jar");
|
||||
Files.write(Paths.get("x"), new byte[10]);
|
||||
if (!m.run("cvf a.jar x".split(" "))) {
|
||||
throw new Exception("jar creation failed");
|
||||
}
|
||||
|
||||
// Generate keypairs and sign the jar
|
||||
Files.deleteIfExists(Paths.get("jks"));
|
||||
for (String keyalg: keyalgs) {
|
||||
sun.security.tools.keytool.Main.main(
|
||||
("-keystore jks -storepass changeit -keypass changeit " +
|
||||
"-dname CN=A -alias " + keyalg + " -genkeypair " +
|
||||
"-keyalg " + keyalg).split(" "));
|
||||
sun.security.tools.jarsigner.Main.main(
|
||||
("-keystore jks -storepass changeit a.jar " + keyalg).split(" "));
|
||||
}
|
||||
|
||||
// Check result
|
||||
KeyStore ks = KeyStore.getInstance("JKS");
|
||||
try (FileInputStream jks = new FileInputStream("jks");
|
||||
JarFile jf = new JarFile("a.jar")) {
|
||||
ks.load(jks, null);
|
||||
for (int i = 0; i<keyalgs.length; i++) {
|
||||
String keyalg = keyalgs[i];
|
||||
// keytool
|
||||
X509Certificate c = (X509Certificate) ks.getCertificate(keyalg);
|
||||
String sigalg = c.getSigAlgName();
|
||||
if (!sigalg.equals(sigalgs[i])) {
|
||||
throw new Exception(
|
||||
"keytool sigalg for " + keyalg + " is " + sigalg);
|
||||
}
|
||||
int keysize = KeyUtil.getKeySize(c.getPublicKey());
|
||||
if (keysize != keysizes[i]) {
|
||||
throw new Exception(
|
||||
"keytool keysize for " + keyalg + " is " + keysize);
|
||||
}
|
||||
// jarsigner
|
||||
String bk = "META-INF/" + keyalg + "." + keyalg;
|
||||
try (InputStream is = jf.getInputStream(jf.getEntry(bk))) {
|
||||
String digestalg = new PKCS7(is).getSignerInfos()[0]
|
||||
.getDigestAlgorithmId().toString();
|
||||
if (!digestalg.equals(digestalgs[i])) {
|
||||
throw new Exception(
|
||||
"jarsigner digest of sig for " + keyalg
|
||||
+ " is " + digestalg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -170,6 +170,13 @@ public class KeyToolTest {
|
||||
*/
|
||||
void testOK(String input, String cmd) throws Exception {
|
||||
try {
|
||||
// Workaround for "8057810: Make SHA256withDSA the default
|
||||
// jarsigner and keytool algorithm for DSA keys". Unfortunately
|
||||
// SunPKCS11-NSS does not support SHA256withDSA yet.
|
||||
if (cmd.contains("p11-nss.txt") && cmd.contains("-genkey")
|
||||
&& !cmd.contains("-keyalg")) {
|
||||
cmd += " -sigalg SHA1withDSA -keysize 1024";
|
||||
}
|
||||
test(input, cmd);
|
||||
} catch(Exception e) {
|
||||
afterFail(input, cmd, "OK");
|
||||
@ -245,6 +252,9 @@ public class KeyToolTest {
|
||||
* Helper method, print some output after a test does not do as expected
|
||||
*/
|
||||
void afterFail(String input, String cmd, String should) {
|
||||
if (cmd.contains("p11-nss.txt")) {
|
||||
cmd = "-J-Dnss.lib=" + System.getProperty("nss.lib") + " " + cmd;
|
||||
}
|
||||
System.err.println("\nTest fails for the command ---\n" +
|
||||
"keytool " + cmd + "\nOr its debug version ---\n" +
|
||||
"keytool -debug " + cmd);
|
||||
@ -799,7 +809,7 @@ public class KeyToolTest {
|
||||
remove("x.jks.p1.cert");
|
||||
remove("csr1");
|
||||
// PrivateKeyEntry can do certreq
|
||||
testOK("", "-keystore x.jks -storepass changeit -keypass changeit -genkeypair -dname CN=olala");
|
||||
testOK("", "-keystore x.jks -storepass changeit -keypass changeit -genkeypair -dname CN=olala -keysize 1024");
|
||||
testOK("", "-keystore x.jks -storepass changeit -certreq -file csr1 -alias mykey");
|
||||
testOK("", "-keystore x.jks -storepass changeit -certreq -file csr1");
|
||||
testOK("", "-keystore x.jks -storepass changeit -certreq -file csr1 -sigalg SHA1withDSA");
|
||||
|
@ -118,13 +118,4 @@ echo | ${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -Dnss \
|
||||
KeyToolTest
|
||||
status=$?
|
||||
|
||||
rm -f p11-nss.txt
|
||||
rm -f cert8.db
|
||||
rm -f key3.db
|
||||
rm -f secmod.db
|
||||
|
||||
rm HumanInputStream*.class
|
||||
rm KeyToolTest*.class
|
||||
rm TestException.class
|
||||
|
||||
exit $status
|
||||
|
@ -62,9 +62,5 @@ ${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . -XDigno
|
||||
echo | ${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -Dfile KeyToolTest
|
||||
status=$?
|
||||
|
||||
rm HumanInputStream*.class
|
||||
rm KeyToolTest*.class
|
||||
rm TestException.class
|
||||
|
||||
exit $status
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user