mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-24 04:54:40 +02:00
Merge
This commit is contained in:
commit
016976afd1
111 changed files with 2781 additions and 968 deletions
91
jdk/test/java/net/Inet4Address/PingThis.java
Normal file
91
jdk/test/java/net/Inet4Address/PingThis.java
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (c) 2012 IBM Corporation
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 7163874
|
||||
* @summary InetAddress.isReachable is returning false
|
||||
* for InetAdress 0.0.0.0 and ::0
|
||||
* @run main PingThis
|
||||
* @run main/othervm -Djava.net.preferIPv4Stack=true PingThis
|
||||
*/
|
||||
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class PingThis {
|
||||
private static boolean hasIPv6() throws Exception {
|
||||
List<NetworkInterface> nics = Collections.list(NetworkInterface
|
||||
.getNetworkInterfaces());
|
||||
for (NetworkInterface nic : nics) {
|
||||
List<InetAddress> addrs = Collections.list(nic.getInetAddresses());
|
||||
for (InetAddress addr : addrs) {
|
||||
if (addr instanceof Inet6Address)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean preferIPv4Stack = "true".equals(System
|
||||
.getProperty("java.net.preferIPv4Stack"));
|
||||
List<String> addrs = new ArrayList<String>();
|
||||
InetAddress inetAddress = null;
|
||||
|
||||
addrs.add("0.0.0.0");
|
||||
if (!preferIPv4Stack) {
|
||||
if (hasIPv6()) {
|
||||
addrs.add("::0");
|
||||
}
|
||||
}
|
||||
|
||||
for (String addr : addrs) {
|
||||
inetAddress = InetAddress.getByName(addr);
|
||||
System.out.println("The target ip is "
|
||||
+ inetAddress.getHostAddress());
|
||||
boolean isReachable = inetAddress.isReachable(3000);
|
||||
System.out.println("the target is reachable: " + isReachable);
|
||||
if (isReachable) {
|
||||
System.out.println("Test passed ");
|
||||
} else {
|
||||
System.out.println("Test failed ");
|
||||
throw new Exception("address " + inetAddress.getHostAddress()
|
||||
+ " can not be reachable!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -88,6 +88,11 @@ public class Truncate {
|
|||
}
|
||||
};
|
||||
Thread t = new Thread(r);
|
||||
t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
try { t.join(); } catch (InterruptedException ignore) { }
|
||||
}
|
||||
|
|
|
@ -53,12 +53,9 @@ public class CheckUsage {
|
|||
rmidVM.start();
|
||||
|
||||
// wait for registry exit
|
||||
int rmidVMExitStatus = rmidVM.getVM().waitFor();
|
||||
System.err.println("rmid exited with status: " +
|
||||
rmidVM.getVM().waitFor());
|
||||
try {
|
||||
Thread.sleep(7000);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
rmidVMExitStatus);
|
||||
|
||||
String usage = new String(berr.toByteArray());
|
||||
|
||||
|
|
|
@ -63,19 +63,30 @@ public class ActivationLibrary {
|
|||
*/
|
||||
public static void deactivate(Remote remote,
|
||||
ActivationID id) {
|
||||
for (int i = 0; i < 5; i ++) {
|
||||
// We do as much as 50 deactivation trials, each separated by
|
||||
// at least 100 milliseconds sleep time (max sleep time of 5 secs).
|
||||
final long deactivateSleepTime = 100;
|
||||
for (int i = 0; i < 50; i ++) {
|
||||
try {
|
||||
if (Activatable.inactive(id) == true) {
|
||||
mesg("inactive successful");
|
||||
return;
|
||||
} else {
|
||||
Thread.sleep(1000);
|
||||
mesg("inactive trial failed. Sleeping " +
|
||||
deactivateSleepTime +
|
||||
" milliseconds before next trial");
|
||||
Thread.sleep(deactivateSleepTime);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
continue;
|
||||
Thread.currentThread().interrupt();
|
||||
mesg("Thread interrupted while trying to deactivate activatable. Exiting deactivation");
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
// forcibly unexport the object
|
||||
mesg("Unexpected exception. Have to forcibly unexport the object." +
|
||||
" Exception was :");
|
||||
e.printStackTrace();
|
||||
Activatable.unexportObject(remote, true);
|
||||
} catch (NoSuchObjectException ex) {
|
||||
}
|
||||
|
@ -99,37 +110,61 @@ public class ActivationLibrary {
|
|||
* activation system.
|
||||
*/
|
||||
public static boolean rmidRunning(int port) {
|
||||
int allowedNotReady = 10;
|
||||
int allowedNotReady = 50;
|
||||
int connectionRefusedExceptions = 0;
|
||||
|
||||
for (int i = 0; i < 15 ; i++) {
|
||||
/* We wait as much as a total of 7.5 secs trying to see Rmid running.
|
||||
* We do this by pausing steps of 100 milliseconds (so up to 75 steps),
|
||||
* right after trying to lookup and find RMID running in the other vm.
|
||||
*/
|
||||
final long rmidWaitingStepTime = 100;
|
||||
for (int i = 0; i <= 74; i++) {
|
||||
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
LocateRegistry.getRegistry(port).lookup(SYSTEM_NAME);
|
||||
mesg("Activation System available after " +
|
||||
(i * rmidWaitingStepTime) + " milliseconds");
|
||||
return true;
|
||||
|
||||
} catch (java.rmi.ConnectException e) {
|
||||
// ignore connect exceptions until we decide rmid is not up
|
||||
mesg("Remote connection refused after " +
|
||||
(i * rmidWaitingStepTime) + " milliseconds");
|
||||
|
||||
// ignore connect exceptions until we decide rmid is not up
|
||||
if ((connectionRefusedExceptions ++) >= allowedNotReady) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (NotBoundException e) {
|
||||
} catch (java.rmi.NoSuchObjectException nsoe) {
|
||||
/* Activation System still unavailable.
|
||||
* Ignore this since we are just waiting for its availibility.
|
||||
* Just signal unavailibility.
|
||||
*/
|
||||
mesg("Activation System still unavailable after more than " +
|
||||
(i * rmidWaitingStepTime) + " milliseconds");
|
||||
|
||||
} catch (NotBoundException e) {
|
||||
return false;
|
||||
|
||||
} catch (Exception e) {
|
||||
// print out other types of exceptions as an FYI.
|
||||
// test should not fail as rmid is likely to be in an
|
||||
// undetermined state at this point.
|
||||
|
||||
/* print out other types of exceptions as an FYI.
|
||||
* test should not fail as rmid is likely to be in an
|
||||
* undetermined state at this point.
|
||||
*/
|
||||
mesg("caught an exception trying to" +
|
||||
" start rmid, last exception was: " +
|
||||
e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Waiting for another 100 milliseconds.
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
mesg("Thread interrupted while checking if Activation System is running. Exiting check");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ import java.util.StringTokenizer;
|
|||
*/
|
||||
public class JavaVM {
|
||||
|
||||
// need to
|
||||
protected Process vm = null;
|
||||
|
||||
private String classname = "";
|
||||
|
@ -46,6 +45,10 @@ public class JavaVM {
|
|||
private OutputStream errorStream = System.err;
|
||||
private String policyFileName = null;
|
||||
|
||||
// This is used to shorten waiting time at startup.
|
||||
private volatile boolean started = false;
|
||||
private boolean forcesOutput = true; // default behavior
|
||||
|
||||
private static void mesg(Object mesg) {
|
||||
System.err.println("JAVAVM: " + mesg.toString());
|
||||
}
|
||||
|
@ -79,6 +82,25 @@ public class JavaVM {
|
|||
this.errorStream = err;
|
||||
}
|
||||
|
||||
/* This constructor will instantiate a JavaVM object for which caller
|
||||
* can ask for forcing initial version output on child vm process
|
||||
* (if forcesVersionOutput is true), or letting the started vm behave freely
|
||||
* (when forcesVersionOutput is false).
|
||||
*/
|
||||
public JavaVM(String classname,
|
||||
String options, String args,
|
||||
OutputStream out, OutputStream err,
|
||||
boolean forcesVersionOutput) {
|
||||
this(classname, options, args, out, err);
|
||||
this.forcesOutput = forcesVersionOutput;
|
||||
}
|
||||
|
||||
|
||||
public void setStarted() {
|
||||
started = true;
|
||||
}
|
||||
|
||||
// Prepends passed opts array to current options
|
||||
public void addOptions(String[] opts) {
|
||||
String newOpts = "";
|
||||
for (int i = 0 ; i < opts.length ; i ++) {
|
||||
|
@ -87,6 +109,8 @@ public class JavaVM {
|
|||
newOpts += " ";
|
||||
options = newOpts + options;
|
||||
}
|
||||
|
||||
// Prepends passed arguments array to current args
|
||||
public void addArguments(String[] arguments) {
|
||||
String newArgs = "";
|
||||
for (int i = 0 ; i < arguments.length ; i ++) {
|
||||
|
@ -127,6 +151,18 @@ public class JavaVM {
|
|||
|
||||
addOptions(new String[] { getCodeCoverageOptions() });
|
||||
|
||||
/*
|
||||
* If forcesOutput is true :
|
||||
* We force the new starting vm to output something so that we can know
|
||||
* when it is effectively started by redirecting standard output through
|
||||
* the next StreamPipe call (the vm is considered started when a first
|
||||
* output has been streamed out).
|
||||
* We do this by prepnding a "-showversion" option in the command line.
|
||||
*/
|
||||
if (forcesOutput) {
|
||||
addOptions(new String[] {"-showversion"});
|
||||
}
|
||||
|
||||
StringTokenizer optionsTokenizer = new StringTokenizer(options);
|
||||
StringTokenizer argsTokenizer = new StringTokenizer(args);
|
||||
int optionsCount = optionsTokenizer.countTokens();
|
||||
|
@ -150,15 +186,43 @@ public class JavaVM {
|
|||
vm = Runtime.getRuntime().exec(javaCommand);
|
||||
|
||||
/* output from the execed process may optionally be captured. */
|
||||
StreamPipe.plugTogether(vm.getInputStream(), this.outputStream);
|
||||
StreamPipe.plugTogether(vm.getErrorStream(), this.errorStream);
|
||||
StreamPipe.plugTogether(this, vm.getInputStream(), this.outputStream);
|
||||
StreamPipe.plugTogether(this, vm.getErrorStream(), this.errorStream);
|
||||
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
if (forcesOutput) {
|
||||
// Wait distant vm to start, by using waiting time slices of 100 ms.
|
||||
// Wait at most for 2secs, after it considers the vm to be started.
|
||||
final long vmStartSleepTime = 100;
|
||||
final int maxTrials = 20;
|
||||
int numTrials = 0;
|
||||
while (!started && numTrials < maxTrials) {
|
||||
numTrials++;
|
||||
Thread.sleep(vmStartSleepTime);
|
||||
}
|
||||
|
||||
mesg("finished starting vm.");
|
||||
// Outputs running status of distant vm
|
||||
String message =
|
||||
"after " + (numTrials * vmStartSleepTime) + " milliseconds";
|
||||
if (started) {
|
||||
mesg("distant vm process running, " + message);
|
||||
}
|
||||
else {
|
||||
mesg("unknown running status of distant vm process, " + message);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Since we have no way to know if the distant vm is started,
|
||||
// we just consider the vm to be started after a 2secs waiting time.
|
||||
Thread.sleep(2000);
|
||||
mesg("distant vm considered to be started after a waiting time of 2 secs");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
mesg("Thread interrupted while checking if distant vm is started. Giving up check.");
|
||||
mesg("Distant vm state unknown");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
|
|
|
@ -218,20 +218,30 @@ public class RMID extends JavaVM {
|
|||
} catch (NumberFormatException ignore) {}
|
||||
waitTime = waitTime * slopFactor;
|
||||
|
||||
// give rmid time to come up
|
||||
// We check several times (as many as provides passed waitTime) to
|
||||
// see if Rmid is currently running. Waiting steps last 100 msecs.
|
||||
final long rmidStartSleepTime = 100;
|
||||
do {
|
||||
// Sleeping for another rmidStartSleepTime time slice.
|
||||
try {
|
||||
Thread.sleep(Math.min(waitTime, 10000));
|
||||
Thread.sleep(Math.min(waitTime, rmidStartSleepTime));
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
mesg("Thread interrupted while checking for start of Activation System. Giving up check.");
|
||||
mesg("Activation System state unknown");
|
||||
return;
|
||||
}
|
||||
waitTime -= 10000;
|
||||
waitTime -= rmidStartSleepTime;
|
||||
|
||||
// is rmid present?
|
||||
// Checking if rmid is present
|
||||
if (ActivationLibrary.rmidRunning(port)) {
|
||||
mesg("finished starting rmid.");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
mesg("rmid still not started");
|
||||
}
|
||||
|
||||
} while (waitTime > 0);
|
||||
TestLibrary.bomb("start rmid failed... giving up", null);
|
||||
}
|
||||
|
@ -264,6 +274,8 @@ public class RMID extends JavaVM {
|
|||
port +
|
||||
"/java.rmi.activation.ActivationSystem");
|
||||
mesg("obtained a reference to the activation system");
|
||||
} catch (RemoteException re) {
|
||||
mesg("could not contact registry while trying to shutdown activation system");
|
||||
} catch (java.net.MalformedURLException mue) {
|
||||
}
|
||||
|
||||
|
@ -272,19 +284,14 @@ public class RMID extends JavaVM {
|
|||
}
|
||||
system.shutdown();
|
||||
|
||||
} catch (RemoteException re) {
|
||||
mesg("shutting down the activation daemon failed");
|
||||
} catch (Exception e) {
|
||||
mesg("caught exception trying to shutdown rmid");
|
||||
mesg(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
// wait for the shutdown to happen
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
mesg("testlibrary finished shutting down rmid");
|
||||
}
|
||||
|
||||
|
@ -301,18 +308,47 @@ public class RMID extends JavaVM {
|
|||
|
||||
if (vm != null) {
|
||||
try {
|
||||
// destroy rmid if it is still running...
|
||||
try {
|
||||
vm.exitValue();
|
||||
mesg("rmid exited on shutdown request");
|
||||
} catch (IllegalThreadStateException illegal) {
|
||||
mesg("Had to destroy RMID's process " +
|
||||
"using Process.destroy()");
|
||||
/* Waiting for distant RMID process to shutdown.
|
||||
* Waiting is bounded at a hardcoded max of 60 secs (1 min).
|
||||
* Waiting by steps of 200 msecs, thus at most 300 such attempts
|
||||
* for termination of distant RMID process. If process is not
|
||||
* known to be terminated properly after that time,
|
||||
* we give up for a gracefull termination, and thus go for
|
||||
* forcibly destroying the process.
|
||||
*/
|
||||
boolean vmEnded = false;
|
||||
int waitingTrials = 0;
|
||||
final int maxTrials = 300;
|
||||
final long vmProcessEndWaitInterval = 200;
|
||||
int vmExitValue;
|
||||
do {
|
||||
try {
|
||||
Thread.sleep(vmProcessEndWaitInterval);
|
||||
waitingTrials++;
|
||||
vmExitValue = vm.exitValue();
|
||||
mesg("rmid exited on shutdown request");
|
||||
vmEnded = true;
|
||||
} catch (IllegalThreadStateException illegal) {
|
||||
mesg("RMID's process still not terminated after more than " +
|
||||
(waitingTrials * vmProcessEndWaitInterval) + " milliseconds");
|
||||
}
|
||||
}
|
||||
while (!vmEnded &&
|
||||
(waitingTrials < maxTrials));
|
||||
|
||||
if (waitingTrials >= maxTrials) {
|
||||
mesg("RMID's process still not terminated after more than " +
|
||||
(waitingTrials * vmProcessEndWaitInterval) + " milliseconds." +
|
||||
"Givinp up gracefull termination...");
|
||||
mesg("destroying RMID's process using Process.destroy()");
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
mesg("Thread interrupted while checking for termination of distant rmid vm. Giving up check.");
|
||||
} catch (Exception e) {
|
||||
mesg("caught exception trying to destroy rmid: " +
|
||||
mesg("caught unexpected exception trying to destroy rmid: " +
|
||||
e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -35,46 +35,89 @@ public class StreamPipe extends Thread {
|
|||
private InputStream in;
|
||||
private OutputStream out;
|
||||
private String preamble;
|
||||
private JavaVM javaVM;
|
||||
private static Object lock = new Object();
|
||||
private static int count = 0;
|
||||
|
||||
public StreamPipe(InputStream in, OutputStream out, String name) {
|
||||
|
||||
/* StreamPipe constructor : should only be called by plugTogether() method !!
|
||||
* If passed vm is not null :
|
||||
* - This is StreamPipe usage when streams to pipe come from a given
|
||||
* vm (JavaVM) process (the vm process must be started with a prefixed
|
||||
* "-showversion" option to be able to determine as soon as possible when
|
||||
* the vm process is started through the redirection of the streams).
|
||||
* There must be a close connection between the StreamPipe instance and
|
||||
* the JavaVM object on which a start() call has been done.
|
||||
* run() method will flag distant JavaVM as started.
|
||||
* If passed vm is null :
|
||||
* - We don't have control on the process which we want to redirect the passed
|
||||
* streams.
|
||||
* run() method will ignore distant process.
|
||||
*/
|
||||
private StreamPipe(JavaVM vm, InputStream in, OutputStream out, String name) {
|
||||
super(name);
|
||||
this.in = in;
|
||||
this.out = out;
|
||||
this.preamble = "# ";
|
||||
this.javaVM = vm;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(in), 1);
|
||||
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(out));
|
||||
byte[] buf = new byte[256];
|
||||
boolean bol = true; // beginning-of-line
|
||||
int count;
|
||||
|
||||
try {
|
||||
String line;
|
||||
while ((line = r.readLine()) != null) {
|
||||
w.write(preamble);
|
||||
w.write(line);
|
||||
w.newLine();
|
||||
w.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("*** IOException in StreamPipe.run:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void plugTogether(InputStream in, OutputStream out) {
|
||||
// Install redirection of passed InputStream and OutputStream from passed JavaVM
|
||||
// to this vm standard output and input streams.
|
||||
public static void plugTogether(JavaVM vm, InputStream in, OutputStream out) {
|
||||
String name = null;
|
||||
|
||||
synchronized (lock) {
|
||||
name = "TestLibrary: StreamPipe-" + (count ++ );
|
||||
}
|
||||
|
||||
Thread pipe = new StreamPipe(in, out, name);
|
||||
Thread pipe = new StreamPipe(vm, in, out, name);
|
||||
pipe.setDaemon(true);
|
||||
pipe.start();
|
||||
}
|
||||
|
||||
/* Redirects the InputStream and OutputStream passed by caller to this
|
||||
* vm standard output and input streams.
|
||||
* (we just have to use fully parametered plugTogether() call with a null
|
||||
* JavaVM input to do this).
|
||||
*/
|
||||
public static void plugTogether(InputStream in, OutputStream out) {
|
||||
plugTogether(null, in, out);
|
||||
}
|
||||
|
||||
// Starts redirection of streams.
|
||||
public void run() {
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(in), 1);
|
||||
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(out));
|
||||
byte[] buf = new byte[256];
|
||||
|
||||
try {
|
||||
String line;
|
||||
|
||||
/* This is to check that the distant vm has started,
|
||||
* if such a vm has been provided at construction :
|
||||
* - As soon as we can read something from r BufferedReader,
|
||||
* that means the distant vm is already started.
|
||||
* Thus we signal associated JavaVM object that it is now started.
|
||||
*/
|
||||
if (((line = r.readLine()) != null) &&
|
||||
(javaVM != null)) {
|
||||
javaVM.setStarted();
|
||||
}
|
||||
|
||||
// Redirects r on w.
|
||||
while (line != null) {
|
||||
w.write(preamble);
|
||||
w.write(line);
|
||||
w.newLine();
|
||||
w.flush();
|
||||
line = r.readLine();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("*** IOException in StreamPipe.run:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,6 +58,12 @@ public class UUIDTest {
|
|||
List list = new LinkedList();
|
||||
for (int i=0; i<100; i++) {
|
||||
UUID u1 = UUID.randomUUID();
|
||||
if (4 != u1.version()) {
|
||||
throw new Exception("bad version");
|
||||
}
|
||||
if (2 != u1.variant()) {
|
||||
throw new Exception("bad variant");
|
||||
}
|
||||
if (list.contains(u1))
|
||||
throw new Exception("random UUID collision very unlikely");
|
||||
list.add(u1);
|
||||
|
@ -70,10 +76,16 @@ public class UUIDTest {
|
|||
List list = new LinkedList();
|
||||
for (int i=0; i<100; i++) {
|
||||
byteSource.nextBytes(someBytes);
|
||||
UUID test = UUID.nameUUIDFromBytes(someBytes);
|
||||
if (list.contains(test))
|
||||
UUID u1 = UUID.nameUUIDFromBytes(someBytes);
|
||||
if (3 != u1.version()) {
|
||||
throw new Exception("bad version");
|
||||
}
|
||||
if (2 != u1.variant()) {
|
||||
throw new Exception("bad variant");
|
||||
}
|
||||
if (list.contains(u1))
|
||||
throw new Exception("byte UUID collision very unlikely");
|
||||
list.add(test);
|
||||
list.add(u1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
189
jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java
Normal file
189
jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java
Normal file
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7103570
|
||||
* @author David Holmes
|
||||
* @run main/othervm AtomicUpdaters
|
||||
* @run main/othervm AtomicUpdaters UseSM
|
||||
* @summary Checks the (in)ability to create field updaters for differently
|
||||
* accessible fields in different locations with/without a security
|
||||
* manager
|
||||
*/
|
||||
import java.util.concurrent.atomic.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.security.AccessControlException;
|
||||
|
||||
public class AtomicUpdaters {
|
||||
enum TYPE { INT, LONG, REF }
|
||||
|
||||
static class Config {
|
||||
final Class<?> clazz;
|
||||
final String field;
|
||||
final String access;
|
||||
final boolean reflectOk;
|
||||
final boolean updaterOk;
|
||||
final String desc;
|
||||
final TYPE type;
|
||||
|
||||
Config(Class<?> clazz, String field, String access,
|
||||
boolean reflectOk, boolean updaterOk, String desc, TYPE type) {
|
||||
this.clazz = clazz;
|
||||
this.field = field;
|
||||
this.access = access;
|
||||
this.reflectOk = reflectOk;
|
||||
this.updaterOk = updaterOk;
|
||||
this.desc = desc;
|
||||
this.type =type;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return desc + ": " + access + " " + clazz.getName() + "." + field;
|
||||
}
|
||||
}
|
||||
|
||||
static Config[] tests;
|
||||
|
||||
static void initTests(boolean hasSM) {
|
||||
tests = new Config[] {
|
||||
new Config(AtomicUpdaters.class, "pub_int", "public", true, true, "public int field of current class", TYPE.INT),
|
||||
new Config(AtomicUpdaters.class, "priv_int", "private", true, true, "private int field of current class", TYPE.INT),
|
||||
new Config(AtomicUpdaters.class, "pub_long", "public", true, true, "public long field of current class", TYPE.LONG),
|
||||
new Config(AtomicUpdaters.class, "priv_long", "private", true, true, "private long field of current class", TYPE.LONG),
|
||||
new Config(AtomicUpdaters.class, "pub_ref", "public", true, true, "public ref field of current class", TYPE.REF),
|
||||
new Config(AtomicUpdaters.class, "priv_ref", "private", true, true, "private ref field of current class", TYPE.REF),
|
||||
|
||||
// Would like to test a public volatile in a class in another
|
||||
// package - but of course there aren't any
|
||||
new Config(java.util.concurrent.atomic.AtomicInteger.class, "value", "private", hasSM ? false : true, false, "private int field of class in different package", TYPE.INT),
|
||||
new Config(java.util.concurrent.atomic.AtomicLong.class, "value", "private", hasSM ? false : true, false, "private long field of class in different package", TYPE.LONG),
|
||||
new Config(java.util.concurrent.atomic.AtomicReference.class, "value", "private", hasSM ? false : true, false, "private reference field of class in different package", TYPE.REF),
|
||||
};
|
||||
}
|
||||
|
||||
public volatile int pub_int;
|
||||
private volatile int priv_int;
|
||||
public volatile long pub_long;
|
||||
private volatile long priv_long;
|
||||
public volatile Object pub_ref;
|
||||
private volatile Object priv_ref;
|
||||
|
||||
|
||||
// This should be set dynamically at runtime using a System property, but
|
||||
// ironically we get a SecurityException if we try to do that with a
|
||||
// SecurityManager installed
|
||||
static boolean verbose;
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
boolean hasSM = false;
|
||||
for (String arg : args) {
|
||||
if ("-v".equals(arg)) {
|
||||
verbose = true;
|
||||
}
|
||||
else if ("UseSM".equals(arg)) {
|
||||
SecurityManager m = System.getSecurityManager();
|
||||
if (m != null)
|
||||
throw new RuntimeException("No security manager should initially be installed");
|
||||
System.setSecurityManager(new java.lang.SecurityManager());
|
||||
hasSM = true;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unexpected option: " + arg);
|
||||
}
|
||||
}
|
||||
initTests(hasSM);
|
||||
|
||||
int failures = 0;
|
||||
|
||||
System.out.printf("Testing with%s a SecurityManager present\n", hasSM ? "" : "out");
|
||||
for (Config c : tests) {
|
||||
System.out.println("Testing: " + c);
|
||||
Error reflectionFailure = null;
|
||||
Error updaterFailure = null;
|
||||
Class<?> clazz = c.clazz;
|
||||
// See if we can reflectively access the field
|
||||
System.out.println(" - testing getDeclaredField");
|
||||
try {
|
||||
Field f = clazz.getDeclaredField(c.field);
|
||||
if (!c.reflectOk)
|
||||
reflectionFailure = new Error("Unexpected reflective access: " + c);
|
||||
}
|
||||
catch (AccessControlException e) {
|
||||
if (c.reflectOk)
|
||||
reflectionFailure = new Error("Unexpected reflective access failure: " + c, e);
|
||||
else if (verbose) {
|
||||
System.out.println("Got expected reflection exception: " + e);
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
|
||||
if (reflectionFailure != null) {
|
||||
reflectionFailure.printStackTrace(System.out);
|
||||
}
|
||||
|
||||
// see if we can create an atomic updater for the field
|
||||
Object u = null;
|
||||
try {
|
||||
switch (c.type) {
|
||||
case INT:
|
||||
System.out.println(" - testing AtomicIntegerFieldUpdater");
|
||||
u = AtomicIntegerFieldUpdater.newUpdater(clazz, c.field);
|
||||
break;
|
||||
case LONG:
|
||||
System.out.println(" - testing AtomicLongFieldUpdater");
|
||||
u = AtomicLongFieldUpdater.newUpdater(clazz, c.field);
|
||||
break;
|
||||
case REF:
|
||||
System.out.println(" - testing AtomicReferenceFieldUpdater");
|
||||
u = AtomicReferenceFieldUpdater.newUpdater(clazz, Object.class, c.field);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!c.updaterOk)
|
||||
updaterFailure = new Error("Unexpected updater access: " + c);
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (c.updaterOk)
|
||||
updaterFailure = new Error("Unexpected updater access failure: " + c, e);
|
||||
else if (verbose) {
|
||||
System.out.println("Got expected updater exception: " + e);
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
|
||||
if (updaterFailure != null) {
|
||||
updaterFailure.printStackTrace(System.out);
|
||||
}
|
||||
|
||||
if (updaterFailure != null || reflectionFailure != null) {
|
||||
failures++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (failures > 0) {
|
||||
throw new Error("Some tests failed - see previous stacktraces");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,23 +22,77 @@
|
|||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 7160242
|
||||
* @bug 7160242 7165118
|
||||
* @summary Check if NullPointerException is thrown if the key passed
|
||||
* to remove() is null.
|
||||
*/
|
||||
|
||||
import java.util.prefs.Preferences;
|
||||
import java.util.prefs.AbstractPreferences;
|
||||
import java.util.prefs.BackingStoreException;
|
||||
|
||||
public class RemoveNullKeyCheck {
|
||||
|
||||
private static boolean failed = false;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
Preferences node = Preferences.userRoot().node("N1");
|
||||
node.remove(null);
|
||||
throw new RuntimeException("Expected NullPointerException " +
|
||||
"not thrown");
|
||||
} catch (NullPointerException npe) {
|
||||
System.out.println("NullPointerException thrown");
|
||||
}
|
||||
checkPreferencesRemove();
|
||||
checkAbstractPreferencesRemove();
|
||||
if (failed) {
|
||||
throw new RuntimeException("Expected NullPointerException " +
|
||||
"not thrown");
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkPreferencesRemove() {
|
||||
try {
|
||||
Preferences node = Preferences.userRoot().node("N1");
|
||||
node.remove(null);
|
||||
failed = true;
|
||||
} catch (NullPointerException npe) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAbstractPreferencesRemove() {
|
||||
|
||||
Preferences abstrPrefs = new AbstractPreferences(null, "") {
|
||||
@Override
|
||||
protected void putSpi(String key, String value) {
|
||||
}
|
||||
@Override
|
||||
protected String getSpi(String key) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected void removeSpi(String key) {
|
||||
}
|
||||
@Override
|
||||
protected void removeNodeSpi() throws BackingStoreException {
|
||||
}
|
||||
@Override
|
||||
protected String[] keysSpi() throws BackingStoreException {
|
||||
return new String[0];
|
||||
}
|
||||
@Override
|
||||
protected String[] childrenNamesSpi() throws BackingStoreException {
|
||||
return new String[0];
|
||||
}
|
||||
@Override
|
||||
protected AbstractPreferences childSpi(String name) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected void syncSpi() throws BackingStoreException {
|
||||
}
|
||||
@Override
|
||||
protected void flushSpi() throws BackingStoreException {
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
abstrPrefs.remove(null);
|
||||
failed = true;
|
||||
} catch(NullPointerException npe) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
* 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
|
||||
* 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
|
||||
* 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
|
||||
* 7067045
|
||||
* 7067045 7014640
|
||||
*/
|
||||
|
||||
import java.util.regex.*;
|
||||
|
@ -141,6 +141,8 @@ public class RegExTest {
|
|||
unicodePropertiesTest();
|
||||
unicodeHexNotationTest();
|
||||
unicodeClassesTest();
|
||||
horizontalAndVerticalWSTest();
|
||||
linebreakTest();
|
||||
if (failure) {
|
||||
throw new
|
||||
RuntimeException("RegExTest failed, 1st failure: " +
|
||||
|
@ -857,13 +859,18 @@ public class RegExTest {
|
|||
// in replacement string
|
||||
try {
|
||||
"\uac00".replaceAll("\uac00", "$");
|
||||
failCount++;
|
||||
} catch (IllegalArgumentException iie) {
|
||||
} catch (Exception e) {
|
||||
failCount++;
|
||||
}
|
||||
try {
|
||||
"\uac00".replaceAll("\uac00", "\\");
|
||||
failCount++;
|
||||
} catch (IllegalArgumentException iie) {
|
||||
} catch (Exception e) {
|
||||
failCount++;
|
||||
}
|
||||
|
||||
report("Literal replacement");
|
||||
}
|
||||
|
||||
|
@ -3838,4 +3845,77 @@ public class RegExTest {
|
|||
failCount++;
|
||||
report("unicodePredefinedClasses");
|
||||
}
|
||||
|
||||
private static void horizontalAndVerticalWSTest() throws Exception {
|
||||
String hws = new String (new char[] {
|
||||
0x09, 0x20, 0xa0, 0x1680, 0x180e,
|
||||
0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005,
|
||||
0x2006, 0x2007, 0x2008, 0x2009, 0x200a,
|
||||
0x202f, 0x205f, 0x3000 });
|
||||
String vws = new String (new char[] {
|
||||
0x0a, 0x0b, 0x0c, 0x0d, 0x85, 0x2028, 0x2029 });
|
||||
if (!Pattern.compile("\\h+").matcher(hws).matches() ||
|
||||
!Pattern.compile("[\\h]+").matcher(hws).matches())
|
||||
failCount++;
|
||||
if (Pattern.compile("\\H").matcher(hws).find() ||
|
||||
Pattern.compile("[\\H]").matcher(hws).find())
|
||||
failCount++;
|
||||
if (!Pattern.compile("\\v+").matcher(vws).matches() ||
|
||||
!Pattern.compile("[\\v]+").matcher(vws).matches())
|
||||
failCount++;
|
||||
if (Pattern.compile("\\V").matcher(vws).find() ||
|
||||
Pattern.compile("[\\V]").matcher(vws).find())
|
||||
failCount++;
|
||||
String prefix = "abcd";
|
||||
String suffix = "efgh";
|
||||
String ng = "A";
|
||||
for (int i = 0; i < hws.length(); i++) {
|
||||
String c = String.valueOf(hws.charAt(i));
|
||||
Matcher m = Pattern.compile("\\h").matcher(prefix + c + suffix);
|
||||
if (!m.find() || !c.equals(m.group()))
|
||||
failCount++;
|
||||
m = Pattern.compile("[\\h]").matcher(prefix + c + suffix);
|
||||
if (!m.find() || !c.equals(m.group()))
|
||||
failCount++;
|
||||
|
||||
m = Pattern.compile("\\H").matcher(hws.substring(0, i) + ng + hws.substring(i));
|
||||
if (!m.find() || !ng.equals(m.group()))
|
||||
failCount++;
|
||||
m = Pattern.compile("[\\H]").matcher(hws.substring(0, i) + ng + hws.substring(i));
|
||||
if (!m.find() || !ng.equals(m.group()))
|
||||
failCount++;
|
||||
}
|
||||
for (int i = 0; i < vws.length(); i++) {
|
||||
String c = String.valueOf(vws.charAt(i));
|
||||
Matcher m = Pattern.compile("\\v").matcher(prefix + c + suffix);
|
||||
if (!m.find() || !c.equals(m.group()))
|
||||
failCount++;
|
||||
m = Pattern.compile("[\\v]").matcher(prefix + c + suffix);
|
||||
if (!m.find() || !c.equals(m.group()))
|
||||
failCount++;
|
||||
|
||||
m = Pattern.compile("\\V").matcher(vws.substring(0, i) + ng + vws.substring(i));
|
||||
if (!m.find() || !ng.equals(m.group()))
|
||||
failCount++;
|
||||
m = Pattern.compile("[\\V]").matcher(vws.substring(0, i) + ng + vws.substring(i));
|
||||
if (!m.find() || !ng.equals(m.group()))
|
||||
failCount++;
|
||||
}
|
||||
// \v in range is interpreted as 0x0B. This is the undocumented behavior
|
||||
if (!Pattern.compile("[\\v-\\v]").matcher(String.valueOf((char)0x0B)).matches())
|
||||
failCount++;
|
||||
report("horizontalAndVerticalWSTest");
|
||||
}
|
||||
|
||||
private static void linebreakTest() throws Exception {
|
||||
String linebreaks = new String (new char[] {
|
||||
0x0A, 0x0B, 0x0C, 0x0D, 0x85, 0x2028, 0x2029 });
|
||||
String crnl = "\r\n";
|
||||
if (!Pattern.compile("\\R+").matcher(linebreaks).matches() ||
|
||||
!Pattern.compile("\\R").matcher(crnl).matches() ||
|
||||
Pattern.compile("\\R\\R").matcher(crnl).matches())
|
||||
failCount++;
|
||||
report("linebreakTest");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue