提交 0945958e 编写于 作者: S sherman

Merge

...@@ -69,14 +69,16 @@ public final class Client extends NTLM { ...@@ -69,14 +69,16 @@ public final class Client extends NTLM {
* This method does not make any modification to this parameter, it neither * This method does not make any modification to this parameter, it neither
* needs to access the content of this parameter after this method call, * needs to access the content of this parameter after this method call,
* so you are free to modify or nullify this parameter after this call. * so you are free to modify or nullify this parameter after this call.
* @throws NullPointerException if {@code username} or {@code password} is null. * @throws NTLMException if {@code username} or {@code password} is null,
* @throws NTLMException if {@code version} is illegal * or {@code version} is illegal.
*
*/ */
public Client(String version, String hostname, String username, public Client(String version, String hostname, String username,
String domain, char[] password) throws NTLMException { String domain, char[] password) throws NTLMException {
super(version); super(version);
if ((username == null || password == null)) { if ((username == null || password == null)) {
throw new NullPointerException("username/password cannot be null"); throw new NTLMException(NTLMException.PROTOCOL,
"username/password cannot be null");
} }
this.hostname = hostname; this.hostname = hostname;
this.username = username; this.username = username;
...@@ -117,13 +119,13 @@ public final class Client extends NTLM { ...@@ -117,13 +119,13 @@ public final class Client extends NTLM {
* @param nonce random 8-byte array to be used in message generation, * @param nonce random 8-byte array to be used in message generation,
* must not be null except for original NTLM v1 * must not be null except for original NTLM v1
* @return the message generated * @return the message generated
* @throws NullPointerException if {@code type2} or {@code nonce} is null * @throws NTLMException if the incoming message is invalid, or
* for NTLM v1. * {@code nonce} is null for NTLM v1.
* @throws NTLMException if the incoming message is invalid
*/ */
public byte[] type3(byte[] type2, byte[] nonce) throws NTLMException { public byte[] type3(byte[] type2, byte[] nonce) throws NTLMException {
if (type2 == null || (v != Version.NTLM && nonce == null)) { if (type2 == null || (v != Version.NTLM && nonce == null)) {
throw new NullPointerException("type2 and nonce cannot be null"); throw new NTLMException(NTLMException.PROTOCOL,
"type2 and nonce cannot be null");
} }
debug("NTLM Client: Type 2 received\n"); debug("NTLM Client: Type 2 received\n");
debug(type2); debug(type2);
......
...@@ -65,6 +65,11 @@ public final class NTLMException extends GeneralSecurityException { ...@@ -65,6 +65,11 @@ public final class NTLMException extends GeneralSecurityException {
*/ */
public final static int BAD_VERSION = 5; public final static int BAD_VERSION = 5;
/**
* Protocol errors.
*/
public final static int PROTOCOL = 6;
private int errorCode; private int errorCode;
/** /**
......
...@@ -62,12 +62,13 @@ public abstract class Server extends NTLM { ...@@ -62,12 +62,13 @@ public abstract class Server extends NTLM {
* is selected, authentication succeeds if one of LM (or LMv2) or * is selected, authentication succeeds if one of LM (or LMv2) or
* NTLM (or NTLMv2) is verified. * NTLM (or NTLMv2) is verified.
* @param domain the domain, must not be null * @param domain the domain, must not be null
* @throws NullPointerException if {@code domain} is null. * @throws NTLMException if {@code domain} is null.
*/ */
public Server(String version, String domain) throws NTLMException { public Server(String version, String domain) throws NTLMException {
super(version); super(version);
if (domain == null) { if (domain == null) {
throw new NullPointerException("domain cannot be null"); throw new NTLMException(NTLMException.PROTOCOL,
"domain cannot be null");
} }
this.allVersion = (version == null); this.allVersion = (version == null);
this.domain = domain; this.domain = domain;
...@@ -80,12 +81,13 @@ public abstract class Server extends NTLM { ...@@ -80,12 +81,13 @@ public abstract class Server extends NTLM {
* @param nonce the random 8-byte array to be used in message generation, * @param nonce the random 8-byte array to be used in message generation,
* must not be null * must not be null
* @return the message generated * @return the message generated
* @throws NullPointerException if type1 or nonce is null * @throws NTLMException if the incoming message is invalid, or
* @throws NTLMException if the incoming message is invalid * {@code nonce} is null.
*/ */
public byte[] type2(byte[] type1, byte[] nonce) { public byte[] type2(byte[] type1, byte[] nonce) throws NTLMException {
if (nonce == null) { if (nonce == null) {
throw new NullPointerException("nonce cannot be null"); throw new NTLMException(NTLMException.PROTOCOL,
"nonce cannot be null");
} }
debug("NTLM Server: Type 1 received\n"); debug("NTLM Server: Type 1 received\n");
if (type1 != null) debug(type1); if (type1 != null) debug(type1);
...@@ -105,13 +107,14 @@ public abstract class Server extends NTLM { ...@@ -105,13 +107,14 @@ public abstract class Server extends NTLM {
* @param type3 the incoming Type3 message from client, must not be null * @param type3 the incoming Type3 message from client, must not be null
* @param nonce the same nonce provided in {@link #type2}, must not be null * @param nonce the same nonce provided in {@link #type2}, must not be null
* @return username and hostname of the client in a byte array * @return username and hostname of the client in a byte array
* @throws NullPointerException if {@code type3} or {@code nonce} is null * @throws NTLMException if the incoming message is invalid, or
* @throws NTLMException if the incoming message is invalid * {@code nonce} is null.
*/ */
public String[] verify(byte[] type3, byte[] nonce) public String[] verify(byte[] type3, byte[] nonce)
throws NTLMException { throws NTLMException {
if (type3 == null || nonce == null) { if (type3 == null || nonce == null) {
throw new NullPointerException("type1 or nonce cannot be null"); throw new NTLMException(NTLMException.PROTOCOL,
"type1 or nonce cannot be null");
} }
debug("NTLM Server: Type 3 received\n"); debug("NTLM Server: Type 3 received\n");
if (type3 != null) debug(type3); if (type3 != null) debug(type3);
......
...@@ -70,6 +70,12 @@ SaslServerFactory{ ...@@ -70,6 +70,12 @@ SaslServerFactory{
if (mechs[i].equals("NTLM") && if (mechs[i].equals("NTLM") &&
PolicyUtils.checkPolicy(mechPolicies[0], props)) { PolicyUtils.checkPolicy(mechPolicies[0], props)) {
if (cbh == null) {
throw new SaslException(
"Callback handler with support for " +
"RealmCallback, NameCallback, and PasswordCallback " +
"required");
}
return new NTLMClient(mechs[i], authorizationId, return new NTLMClient(mechs[i], authorizationId,
protocol, serverName, props, cbh); protocol, serverName, props, cbh);
} }
...@@ -98,9 +104,9 @@ SaslServerFactory{ ...@@ -98,9 +104,9 @@ SaslServerFactory{
} }
if (cbh == null) { if (cbh == null) {
throw new SaslException( throw new SaslException(
"Callback handler with support for AuthorizeCallback, "+ "Callback handler with support for " +
"RealmCallback, NameCallback, and PasswordCallback " + "RealmCallback, NameCallback, and PasswordCallback " +
"required"); "required");
} }
return new NTLMServer(mech, protocol, serverName, props, cbh); return new NTLMServer(mech, protocol, serverName, props, cbh);
} }
......
...@@ -107,7 +107,7 @@ final class NTLMClient implements SaslClient { ...@@ -107,7 +107,7 @@ final class NTLMClient implements SaslClient {
* @param protocol non-null for Sasl, useless for NTLM * @param protocol non-null for Sasl, useless for NTLM
* @param serverName non-null for Sasl, but can be null for NTLM * @param serverName non-null for Sasl, but can be null for NTLM
* @param props can be null * @param props can be null
* @param cbh can be null for Sasl, but will throw NPE for NTLM * @param cbh can be null for Sasl, already null-checked in factory
* @throws SaslException * @throws SaslException
*/ */
NTLMClient(String mech, String authzid, String protocol, String serverName, NTLMClient(String mech, String authzid, String protocol, String serverName,
...@@ -166,7 +166,7 @@ final class NTLMClient implements SaslClient { ...@@ -166,7 +166,7 @@ final class NTLMClient implements SaslClient {
pcb.getPassword()); pcb.getPassword());
} catch (NTLMException ne) { } catch (NTLMException ne) {
throw new SaslException( throw new SaslException(
"NTLM: Invalid version string: " + version, ne); "NTLM: client creation failure", ne);
} }
} }
...@@ -183,17 +183,20 @@ final class NTLMClient implements SaslClient { ...@@ -183,17 +183,20 @@ final class NTLMClient implements SaslClient {
@Override @Override
public byte[] unwrap(byte[] incoming, int offset, int len) public byte[] unwrap(byte[] incoming, int offset, int len)
throws SaslException { throws SaslException {
throw new UnsupportedOperationException("Not supported."); throw new IllegalStateException("Not supported.");
} }
@Override @Override
public byte[] wrap(byte[] outgoing, int offset, int len) public byte[] wrap(byte[] outgoing, int offset, int len)
throws SaslException { throws SaslException {
throw new UnsupportedOperationException("Not supported."); throw new IllegalStateException("Not supported.");
} }
@Override @Override
public Object getNegotiatedProperty(String propName) { public Object getNegotiatedProperty(String propName) {
if (!isComplete()) {
throw new IllegalStateException("authentication not complete");
}
switch (propName) { switch (propName) {
case Sasl.QOP: case Sasl.QOP:
return "auth"; return "auth";
......
...@@ -106,7 +106,7 @@ final class NTLMServer implements SaslServer { ...@@ -106,7 +106,7 @@ final class NTLMServer implements SaslServer {
* @param serverName not null for Sasl, can be null in NTLM. If non-null, * @param serverName not null for Sasl, can be null in NTLM. If non-null,
* might be used as domain if not provided in props * might be used as domain if not provided in props
* @param props can be null * @param props can be null
* @param cbh can be null for Sasl, but will throw NPE in auth for NTLM * @param cbh can be null for Sasl, already null-checked in factory
* @throws SaslException * @throws SaslException
*/ */
NTLMServer(String mech, String protocol, String serverName, NTLMServer(String mech, String protocol, String serverName,
...@@ -132,7 +132,7 @@ final class NTLMServer implements SaslServer { ...@@ -132,7 +132,7 @@ final class NTLMServer implements SaslServer {
domain = serverName; domain = serverName;
} }
if (domain == null) { if (domain == null) {
throw new NullPointerException("Domain must be provided as" throw new SaslException("Domain must be provided as"
+ " the serverName argument or in props"); + " the serverName argument or in props");
} }
...@@ -159,7 +159,7 @@ final class NTLMServer implements SaslServer { ...@@ -159,7 +159,7 @@ final class NTLMServer implements SaslServer {
}; };
} catch (NTLMException ne) { } catch (NTLMException ne) {
throw new SaslException( throw new SaslException(
"NTLM: Invalid version string: " + version, ne); "NTLM: server creation failure", ne);
} }
nonce = new byte[8]; nonce = new byte[8];
} }
...@@ -182,8 +182,8 @@ final class NTLMServer implements SaslServer { ...@@ -182,8 +182,8 @@ final class NTLMServer implements SaslServer {
hostname = out[1]; hostname = out[1];
return null; return null;
} }
} catch (GeneralSecurityException ex) { } catch (NTLMException ex) {
throw new SaslException("", ex); throw new SaslException("NTLM: generate response failure", ex);
} }
} }
...@@ -194,23 +194,29 @@ final class NTLMServer implements SaslServer { ...@@ -194,23 +194,29 @@ final class NTLMServer implements SaslServer {
@Override @Override
public String getAuthorizationID() { public String getAuthorizationID() {
if (!isComplete()) {
throw new IllegalStateException("authentication not complete");
}
return authzId; return authzId;
} }
@Override @Override
public byte[] unwrap(byte[] incoming, int offset, int len) public byte[] unwrap(byte[] incoming, int offset, int len)
throws SaslException { throws SaslException {
throw new UnsupportedOperationException("Not supported yet."); throw new IllegalStateException("Not supported yet.");
} }
@Override @Override
public byte[] wrap(byte[] outgoing, int offset, int len) public byte[] wrap(byte[] outgoing, int offset, int len)
throws SaslException { throws SaslException {
throw new UnsupportedOperationException("Not supported yet."); throw new IllegalStateException("Not supported yet.");
} }
@Override @Override
public Object getNegotiatedProperty(String propName) { public Object getNegotiatedProperty(String propName) {
if (!isComplete()) {
throw new IllegalStateException("authentication not complete");
}
switch (propName) { switch (propName) {
case Sasl.QOP: case Sasl.QOP:
return "auth"; return "auth";
......
...@@ -101,10 +101,7 @@ class SunConnection { ...@@ -101,10 +101,7 @@ class SunConnection {
return new URL(registerURL); return new URL(registerURL);
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
// should never reach here // should never reach here
InternalError x = throw new InternalError(ex.getMessage(), ex);
new InternalError(ex.getMessage());
x.initCause(ex);
throw x;
} }
} }
...@@ -171,9 +168,7 @@ class SunConnection { ...@@ -171,9 +168,7 @@ class SunConnection {
try { try {
BrowserSupport.browse(url.toURI()); BrowserSupport.browse(url.toURI());
} catch (URISyntaxException ex) { } catch (URISyntaxException ex) {
InternalError x = new InternalError("Error in registering: " + ex.getMessage()); throw new InternalError("Error in registering: " + ex.getMessage(), ex);
x.initCause(ex);
throw x;
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
if (Util.isVerbose()) { if (Util.isVerbose()) {
ex.printStackTrace(); ex.printStackTrace();
...@@ -232,9 +227,7 @@ class SunConnection { ...@@ -232,9 +227,7 @@ class SunConnection {
return (returnCode == HttpURLConnection.HTTP_OK); return (returnCode == HttpURLConnection.HTTP_OK);
} catch (MalformedURLException me) { } catch (MalformedURLException me) {
// should never reach here // should never reach here
InternalError x = new InternalError("Error in registering: " + me.getMessage()); throw new InternalError("Error in registering: " + me.getMessage(), me);
x.initCause(me);
throw x;
} catch (Exception ioe) { } catch (Exception ioe) {
// SocketTimeoutException, IOException or UnknownHostException // SocketTimeoutException, IOException or UnknownHostException
if (Util.isVerbose()) { if (Util.isVerbose()) {
...@@ -262,10 +255,9 @@ class SunConnection { ...@@ -262,10 +255,9 @@ class SunConnection {
BrowserSupport.browse(registerPage.toURI()); BrowserSupport.browse(registerPage.toURI());
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
// should never reach here // should never reach here
InternalError x = throw new InternalError(
new InternalError("Error in launching " + registerPage + ": " + ex.getMessage()); "Error in launching " + registerPage + ": " + ex.getMessage()
x.initCause(ex); , ex);
throw x;
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
if (Util.isVerbose()) { if (Util.isVerbose()) {
ex.printStackTrace(); ex.printStackTrace();
......
...@@ -514,9 +514,12 @@ public class BufferedReader extends Reader { ...@@ -514,9 +514,12 @@ public class BufferedReader extends Reader {
synchronized (lock) { synchronized (lock) {
if (in == null) if (in == null)
return; return;
in.close(); try {
in = null; in.close();
cb = null; } finally {
in = null;
cb = null;
}
} }
} }
} }
...@@ -255,15 +255,15 @@ public class BufferedWriter extends Writer { ...@@ -255,15 +255,15 @@ public class BufferedWriter extends Writer {
} }
} }
@SuppressWarnings("try")
public void close() throws IOException { public void close() throws IOException {
synchronized (lock) { synchronized (lock) {
if (out == null) { if (out == null) {
return; return;
} }
try { try (Writer w = out) {
flushBuffer(); flushBuffer();
} finally { } finally {
out.close();
out = null; out = null;
cb = null; cb = null;
} }
......
...@@ -42,6 +42,12 @@ public interface Closeable extends AutoCloseable { ...@@ -42,6 +42,12 @@ public interface Closeable extends AutoCloseable {
* with it. If the stream is already closed then invoking this * with it. If the stream is already closed then invoking this
* method has no effect. * method has no effect.
* *
* <p> As noted in {@link AutoCloseable#close()}, cases where the
* close may fail require careful attention. It is strongly advised
* to relinquish the underlying resources and to internally
* <em>mark</em> the {@code Closeable} as closed, prior to throwing
* the {@code IOException}.
*
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
public void close() throws IOException; public void close() throws IOException;
......
...@@ -152,11 +152,10 @@ class FilterOutputStream extends OutputStream { ...@@ -152,11 +152,10 @@ class FilterOutputStream extends OutputStream {
* @see java.io.FilterOutputStream#flush() * @see java.io.FilterOutputStream#flush()
* @see java.io.FilterOutputStream#out * @see java.io.FilterOutputStream#out
*/ */
@SuppressWarnings("try")
public void close() throws IOException { public void close() throws IOException {
try { try (OutputStream ostream = out) {
flush(); flush();
} catch (IOException ignored) {
} }
out.close();
} }
} }
...@@ -43,6 +43,15 @@ public interface AutoCloseable { ...@@ -43,6 +43,15 @@ public interface AutoCloseable {
* throw more specific exceptions, or to throw no exception at all * throw more specific exceptions, or to throw no exception at all
* if the close operation cannot fail. * if the close operation cannot fail.
* *
* <p> Cases where the close operation may fail require careful
* attention by implementers. It is strongly advised to relinquish
* the underlying resources and to internally <em>mark</em> the
* resource as closed, prior to throwing the exception. The {@code
* close} method is unlikely to be invoked more than once and so
* this ensures that the resources are released in a timely manner.
* Furthermore it reduces problems that could arise when the resource
* wraps, or is wrapped, by another resource.
*
* <p><em>Implementers of this interface are also strongly advised * <p><em>Implementers of this interface are also strongly advised
* to not have the {@code close} method throw {@link * to not have the {@code close} method throw {@link
* InterruptedException}.</em> * InterruptedException}.</em>
......
/* /*
* Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,8 +32,7 @@ package java.lang; ...@@ -32,8 +32,7 @@ package java.lang;
* @author unascribed * @author unascribed
* @since JDK1.0 * @since JDK1.0
*/ */
public public class InternalError extends VirtualMachineError {
class InternalError extends VirtualMachineError {
private static final long serialVersionUID = -9062593416125562365L; private static final long serialVersionUID = -9062593416125562365L;
/** /**
...@@ -47,9 +46,45 @@ class InternalError extends VirtualMachineError { ...@@ -47,9 +46,45 @@ class InternalError extends VirtualMachineError {
* Constructs an <code>InternalError</code> with the specified * Constructs an <code>InternalError</code> with the specified
* detail message. * detail message.
* *
* @param s the detail message. * @param message the detail message.
*/ */
public InternalError(String s) { public InternalError(String message) {
super(s); super(message);
} }
/**
* Constructs an {@code InternalError} with the specified detail
* message and cause. <p>Note that the detail message associated
* with {@code cause} is <i>not</i> automatically incorporated in
* this error's detail message.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.8
*/
public InternalError(String message, Throwable cause) {
super(message, cause);
}
/**
* Constructs an {@code InternalError} with the specified cause
* and a detail message of {@code (cause==null ? null :
* cause.toString())} (which typically contains the class and
* detail message of {@code cause}).
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.8
*/
public InternalError(Throwable cause) {
super(cause);
}
} }
...@@ -632,6 +632,7 @@ public final class System { ...@@ -632,6 +632,7 @@ public final class System {
* *
* <p>On UNIX systems, it returns {@code "\n"}; on Microsoft * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
* Windows systems it returns {@code "\r\n"}. * Windows systems it returns {@code "\r\n"}.
* @since 1.7
*/ */
public static String lineSeparator() { public static String lineSeparator() {
return lineSeparator; return lineSeparator;
......
/* /*
* Copyright (c) 1995, 1997, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU General Public License version 2 only, asP
* published by the Free Software Foundation. Oracle designates this * published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided * particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code. * by Oracle in the LICENSE file that accompanied this code.
...@@ -33,8 +33,9 @@ package java.lang; ...@@ -33,8 +33,9 @@ package java.lang;
* @author Frank Yellin * @author Frank Yellin
* @since JDK1.0 * @since JDK1.0
*/ */
abstract public abstract public class VirtualMachineError extends Error {
class VirtualMachineError extends Error { private static final long serialVersionUID = 4161983926571568670L;
/** /**
* Constructs a <code>VirtualMachineError</code> with no detail message. * Constructs a <code>VirtualMachineError</code> with no detail message.
*/ */
...@@ -46,9 +47,43 @@ class VirtualMachineError extends Error { ...@@ -46,9 +47,43 @@ class VirtualMachineError extends Error {
* Constructs a <code>VirtualMachineError</code> with the specified * Constructs a <code>VirtualMachineError</code> with the specified
* detail message. * detail message.
* *
* @param s the detail message. * @param message the detail message.
*/
public VirtualMachineError(String message) {
super(message);
}
/**
* Constructs a {@code VirtualMachineError} with the specified
* detail message and cause. <p>Note that the detail message
* associated with {@code cause} is <i>not</i> automatically
* incorporated in this error's detail message.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.8
*/
public VirtualMachineError(String message, Throwable cause) {
super(message, cause);
}
/**
* Constructs an a {@code VirtualMachineError} with the specified
* cause and a detail message of {@code (cause==null ? null :
* cause.toString())} (which typically contains the class and
* detail message of {@code cause}).
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.8
*/ */
public VirtualMachineError(String s) { public VirtualMachineError(Throwable cause) {
super(s); super(cause);
} }
} }
...@@ -748,10 +748,14 @@ public final class HttpCookie implements Cloneable { ...@@ -748,10 +748,14 @@ public final class HttpCookie implements Cloneable {
&& (embeddedDotInDomain == -1 || embeddedDotInDomain == domain.length() - 1)) && (embeddedDotInDomain == -1 || embeddedDotInDomain == domain.length() - 1))
return false; return false;
// if the host name contains no dot and the domain name is .local // if the host name contains no dot and the domain name
// is .local or host.local
int firstDotInHost = host.indexOf('.'); int firstDotInHost = host.indexOf('.');
if (firstDotInHost == -1 && isLocalDomain) if (firstDotInHost == -1 &&
(isLocalDomain ||
domain.equalsIgnoreCase(host + ".local"))) {
return true; return true;
}
int domainLength = domain.length(); int domainLength = domain.length();
int lengthDiff = host.length() - domainLength; int lengthDiff = host.length() - domainLength;
......
/* /*
* Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -44,7 +44,7 @@ package java.util; ...@@ -44,7 +44,7 @@ package java.util;
* notifications on separate threads, or may guarantee that their * notifications on separate threads, or may guarantee that their
* subclass follows this order, as they choose. * subclass follows this order, as they choose.
* <p> * <p>
* Note that this notification mechanism is has nothing to do with threads * Note that this notification mechanism has nothing to do with threads
* and is completely separate from the <tt>wait</tt> and <tt>notify</tt> * and is completely separate from the <tt>wait</tt> and <tt>notify</tt>
* mechanism of class <tt>Object</tt>. * mechanism of class <tt>Object</tt>.
* <p> * <p>
......
...@@ -256,11 +256,9 @@ public abstract class Preferences { ...@@ -256,11 +256,9 @@ public abstract class Preferences {
.getContextClassLoader()) .getContextClassLoader())
.newInstance(); .newInstance();
} catch (Exception e) { } catch (Exception e) {
InternalError error = new InternalError( throw new InternalError(
"Can't instantiate Preferences factory " "Can't instantiate Preferences factory "
+ factoryName); + factoryName, e);
error.initCause(e);
throw error;
} }
} }
} }
...@@ -299,11 +297,9 @@ public abstract class Preferences { ...@@ -299,11 +297,9 @@ public abstract class Preferences {
return (PreferencesFactory) return (PreferencesFactory)
Class.forName(platformFactory, false, null).newInstance(); Class.forName(platformFactory, false, null).newInstance();
} catch (Exception e) { } catch (Exception e) {
InternalError error = new InternalError( throw new InternalError(
"Can't instantiate platform default Preferences factory " "Can't instantiate platform default Preferences factory "
+ platformFactory); + platformFactory, e);
error.initCause(e);
throw error;
} }
} }
......
...@@ -758,6 +758,11 @@ public class RepaintManager ...@@ -758,6 +758,11 @@ public class RepaintManager
for(i=0 ; i < count ; i++) { for(i=0 ; i < count ; i++) {
dirtyComponent = roots.get(i); dirtyComponent = roots.get(i);
rect = tmpDirtyComponents.get(dirtyComponent); rect = tmpDirtyComponents.get(dirtyComponent);
// Sometimes when RepaintManager is changed during the painting
// we may get null here, see #6995769 for details
if (rect == null) {
continue;
}
localBoundsH = dirtyComponent.getHeight(); localBoundsH = dirtyComponent.getHeight();
localBoundsW = dirtyComponent.getWidth(); localBoundsW = dirtyComponent.getWidth();
......
...@@ -2167,7 +2167,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel ...@@ -2167,7 +2167,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel
/** /**
* Returns a {@code LayoutStyle} implementing the Java look and feel * Returns a {@code LayoutStyle} implementing the Java look and feel
* design guidelines as specified at * design guidelines as specified at
* <a href="http://java.sun.com/products/jlf/ed2/book/HIG.Visual2.html">http://java.sun.com/products/jlf/ed2/book/HIG.Visual2.html</a>. * <a href="http://www.oracle.com/technetwork/java/hig-136467.html">http://www.oracle.com/technetwork/java/hig-136467.html</a>.
* *
* @return LayoutStyle implementing the Java look and feel design * @return LayoutStyle implementing the Java look and feel design
* guidelines * guidelines
......
...@@ -78,20 +78,11 @@ public final class FontManagerFactory { ...@@ -78,20 +78,11 @@ public final class FontManagerFactory {
ClassLoader cl = ClassLoader.getSystemClassLoader(); ClassLoader cl = ClassLoader.getSystemClassLoader();
Class fmClass = Class.forName(fmClassName, true, cl); Class fmClass = Class.forName(fmClassName, true, cl);
instance = (FontManager) fmClass.newInstance(); instance = (FontManager) fmClass.newInstance();
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException |
InternalError err = new InternalError(); InstantiationException |
err.initCause(ex); IllegalAccessException ex) {
throw err; throw new InternalError(ex);
} catch (InstantiationException ex) {
InternalError err = new InternalError();
err.initCause(ex);
throw err;
} catch (IllegalAccessException ex) {
InternalError err = new InternalError();
err.initCause(ex);
throw err;
} }
return null; return null;
} }
......
...@@ -171,7 +171,8 @@ public class ManagementFactoryHelper { ...@@ -171,7 +171,8 @@ public class ManagementFactoryHelper {
ObjectName result = objname; ObjectName result = objname;
if (result == null) { if (result == null) {
synchronized (this) { synchronized (this) {
if (objname == null) { result = objname;
if (result == null) {
result = Util.newObjectName(LOGGING_MXBEAN_NAME); result = Util.newObjectName(LOGGING_MXBEAN_NAME);
objname = result; objname = result;
} }
...@@ -228,7 +229,8 @@ public class ManagementFactoryHelper { ...@@ -228,7 +229,8 @@ public class ManagementFactoryHelper {
ObjectName result = objname; ObjectName result = objname;
if (result == null) { if (result == null) {
synchronized (this) { synchronized (this) {
if (objname == null) { result = objname;
if (result == null) {
result = Util.newObjectName(BUFFER_POOL_MXBEAN_NAME + result = Util.newObjectName(BUFFER_POOL_MXBEAN_NAME +
",name=" + pool.getName()); ",name=" + pool.getName());
objname = result; objname = result;
......
...@@ -717,7 +717,7 @@ public class URLClassPath { ...@@ -717,7 +717,7 @@ public class URLClassPath {
try { try {
ensureOpen(); ensureOpen();
} catch (IOException e) { } catch (IOException e) {
throw (InternalError) new InternalError().initCause(e); throw new InternalError(e);
} }
return index; return index;
} }
...@@ -812,7 +812,7 @@ public class URLClassPath { ...@@ -812,7 +812,7 @@ public class URLClassPath {
try { try {
ensureOpen(); ensureOpen();
} catch (IOException e) { } catch (IOException e) {
throw (InternalError) new InternalError().initCause(e); throw new InternalError(e);
} }
final JarEntry entry = jar.getJarEntry(name); final JarEntry entry = jar.getJarEntry(name);
if (entry != null) if (entry != null)
...@@ -900,7 +900,7 @@ public class URLClassPath { ...@@ -900,7 +900,7 @@ public class URLClassPath {
try { try {
newLoader.ensureOpen(); newLoader.ensureOpen();
} catch (IOException e) { } catch (IOException e) {
throw (InternalError) new InternalError().initCause(e); throw new InternalError(e);
} }
final JarEntry entry = newLoader.jar.getJarEntry(name); final JarEntry entry = newLoader.jar.getJarEntry(name);
if (entry != null) { if (entry != null) {
......
...@@ -401,10 +401,8 @@ class MethodAccessorGenerator extends AccessorGenerator { ...@@ -401,10 +401,8 @@ class MethodAccessorGenerator extends AccessorGenerator {
0, 0,
bytes.length, bytes.length,
declaringClass.getClassLoader()).newInstance(); declaringClass.getClassLoader()).newInstance();
} catch (InstantiationException | } catch (InstantiationException | IllegalAccessException e) {
IllegalAccessException e) { throw new InternalError(e);
throw (InternalError)
new InternalError().initCause(e);
} }
} }
}); });
......
/* /*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -40,6 +40,7 @@ import java.security.PrivilegedAction; ...@@ -40,6 +40,7 @@ import java.security.PrivilegedAction;
* @since 1.5 * @since 1.5
*/ */
class AnnotationInvocationHandler implements InvocationHandler, Serializable { class AnnotationInvocationHandler implements InvocationHandler, Serializable {
private static final long serialVersionUID = 6182022883658399397L;
private final Class<? extends Annotation> type; private final Class<? extends Annotation> type;
private final Map<String, Object> memberValues; private final Map<String, Object> memberValues;
......
/* /*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -34,6 +34,7 @@ import java.lang.reflect.Method; ...@@ -34,6 +34,7 @@ import java.lang.reflect.Method;
* @since 1.5 * @since 1.5
*/ */
class AnnotationTypeMismatchExceptionProxy extends ExceptionProxy { class AnnotationTypeMismatchExceptionProxy extends ExceptionProxy {
private static final long serialVersionUID = 7844069490309503934L;
private Method member; private Method member;
private String foundType; private String foundType;
......
/* /*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,6 +32,7 @@ package sun.reflect.annotation; ...@@ -32,6 +32,7 @@ package sun.reflect.annotation;
* @since 1.5 * @since 1.5
*/ */
public class EnumConstantNotPresentExceptionProxy extends ExceptionProxy { public class EnumConstantNotPresentExceptionProxy extends ExceptionProxy {
private static final long serialVersionUID = -604662101303187330L;
Class<? extends Enum<?>> enumType; Class<? extends Enum<?>> enumType;
String constName; String constName;
......
/* /*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,6 +33,7 @@ import java.lang.annotation.*; ...@@ -33,6 +33,7 @@ import java.lang.annotation.*;
* @since 1.5 * @since 1.5
*/ */
public class TypeNotPresentExceptionProxy extends ExceptionProxy { public class TypeNotPresentExceptionProxy extends ExceptionProxy {
private static final long serialVersionUID = 5565925172427947573L;
String typeName; String typeName;
Throwable cause; Throwable cause;
......
/* /*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,17 +25,15 @@ ...@@ -25,17 +25,15 @@
package sun.reflect.generics.parser; package sun.reflect.generics.parser;
import java.lang.reflect.GenericSignatureFormatError; import java.lang.reflect.GenericSignatureFormatError;
import java.util.*; import java.util.*;
import sun.reflect.generics.tree.*; import sun.reflect.generics.tree.*;
/** /**
* Parser for type signatures, as defined in the Java Virtual * Parser for type signatures, as defined in the Java Virtual
// Machine Specification (JVMS) chapter 4. * Machine Specification (JVMS) chapter 4.
* Converts the signatures into an abstract syntax tree (AST) representation. * Converts the signatures into an abstract syntax tree (AST) representation.
// See the package sun.reflect.generics.tree for details of the AST. * See the package sun.reflect.generics.tree for details of the AST.
*/ */
public class SignatureParser { public class SignatureParser {
// The input is conceptually a character stream (though currently it's // The input is conceptually a character stream (though currently it's
...@@ -58,8 +56,8 @@ public class SignatureParser { ...@@ -58,8 +56,8 @@ public class SignatureParser {
// if (current != x {error("expected an x"); // if (current != x {error("expected an x");
// //
// where x is some character constant. // where x is some character constant.
// The assertion inidcates, that, as currently written, // The assertion indicates, that, as currently written,
// the code should nver reach this point unless the input is an // the code should never reach this point unless the input is an
// x. On the other hand, the test is there to check the legality // x. On the other hand, the test is there to check the legality
// of the input wrt to a given production. It may be that at a later // of the input wrt to a given production. It may be that at a later
// time the code might be called directly, and if the input is // time the code might be called directly, and if the input is
...@@ -68,7 +66,7 @@ public class SignatureParser { ...@@ -68,7 +66,7 @@ public class SignatureParser {
private char[] input; // the input signature private char[] input; // the input signature
private int index = 0; // index into the input private int index = 0; // index into the input
// used to mark end of input // used to mark end of input
private static final char EOI = ':'; private static final char EOI = ':';
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
...@@ -104,6 +102,11 @@ public class SignatureParser { ...@@ -104,6 +102,11 @@ public class SignatureParser {
index++; index++;
} }
// For debugging, prints current character to the end of the input.
private String remainder() {
return new String(input, index, input.length-index);
}
// Match c against a "set" of characters // Match c against a "set" of characters
private boolean matches(char c, char... set) { private boolean matches(char c, char... set) {
for (char e : set) { for (char e : set) {
...@@ -117,8 +120,17 @@ public class SignatureParser { ...@@ -117,8 +120,17 @@ public class SignatureParser {
// Currently throws a GenericSignatureFormatError. // Currently throws a GenericSignatureFormatError.
private Error error(String errorMsg) { private Error error(String errorMsg) {
if (DEBUG) System.out.println("Parse error:" + errorMsg); return new GenericSignatureFormatError("Signature Parse error: " + errorMsg +
return new GenericSignatureFormatError(); "\n\tRemaining input: " + remainder());
}
/**
* Verify the parse has made forward progress; throw an exception
* if no progress.
*/
private void progress(int startingPosition) {
if (index <= startingPosition)
throw error("Failure to make progress!");
} }
/** /**
...@@ -163,6 +175,7 @@ public class SignatureParser { ...@@ -163,6 +175,7 @@ public class SignatureParser {
/** /**
* Parses a type signature * Parses a type signature
* and produces an abstract syntax tree representing it. * and produces an abstract syntax tree representing it.
*
* @param s a string representing the input type signature * @param s a string representing the input type signature
* @return An abstract syntax tree for a type signature * @return An abstract syntax tree for a type signature
* corresponding to the input string * corresponding to the input string
...@@ -183,38 +196,58 @@ public class SignatureParser { ...@@ -183,38 +196,58 @@ public class SignatureParser {
// and when it completes parsing, it leaves the input at the first // and when it completes parsing, it leaves the input at the first
// character after the input parses. // character after the input parses.
// parse a class signature based on the implicit input. /*
* Note on grammar conventions: a trailing "*" matches zero or
* more occurrences, a trailing "+" matches one or more occurrences,
* "_opt" indicates an optional component.
*/
/**
* ClassSignature:
* FormalTypeParameters_opt SuperclassSignature SuperinterfaceSignature*
*/
private ClassSignature parseClassSignature() { private ClassSignature parseClassSignature() {
// parse a class signature based on the implicit input.
assert(index == 0); assert(index == 0);
return ClassSignature.make(parseZeroOrMoreFormalTypeParameters(), return ClassSignature.make(parseZeroOrMoreFormalTypeParameters(),
parseClassTypeSignature(), parseClassTypeSignature(), // Only rule for SuperclassSignature
parseSuperInterfaces()); parseSuperInterfaces());
} }
private FormalTypeParameter[] parseZeroOrMoreFormalTypeParameters(){ private FormalTypeParameter[] parseZeroOrMoreFormalTypeParameters(){
if (current() == '<') { return parseFormalTypeParameters();} if (current() == '<') {
else {return new FormalTypeParameter[0];} return parseFormalTypeParameters();
} else {
return new FormalTypeParameter[0];
}
} }
/**
* FormalTypeParameters:
* "<" FormalTypeParameter+ ">"
*/
private FormalTypeParameter[] parseFormalTypeParameters(){ private FormalTypeParameter[] parseFormalTypeParameters(){
Collection<FormalTypeParameter> ftps = List<FormalTypeParameter> ftps = new ArrayList<>(3);
new ArrayList<FormalTypeParameter>(3);
assert(current() == '<'); // should not have been called at all assert(current() == '<'); // should not have been called at all
if (current() != '<') { throw error("expected <");} if (current() != '<') { throw error("expected '<'");}
advance(); advance();
ftps.add(parseFormalTypeParameter()); ftps.add(parseFormalTypeParameter());
while (current() != '>') { while (current() != '>') {
int startingPosition = index;
ftps.add(parseFormalTypeParameter()); ftps.add(parseFormalTypeParameter());
progress(startingPosition);
} }
advance(); advance();
FormalTypeParameter[] ftpa = new FormalTypeParameter[ftps.size()]; return ftps.toArray(new FormalTypeParameter[ftps.size()]);
return ftps.toArray(ftpa);
} }
/**
* FormalTypeParameter:
* Identifier ClassBound InterfaceBound*
*/
private FormalTypeParameter parseFormalTypeParameter(){ private FormalTypeParameter parseFormalTypeParameter(){
String id = parseIdentifier(); String id = parseIdentifier();
FieldTypeSignature[] bs = parseZeroOrMoreBounds(); FieldTypeSignature[] bs = parseBounds();
return FormalTypeParameter.make(id, bs); return FormalTypeParameter.make(id, bs);
} }
...@@ -229,7 +262,8 @@ public class SignatureParser { ...@@ -229,7 +262,8 @@ public class SignatureParser {
case '[': case '[':
case ':': case ':':
case '>': case '>':
case '<': return result.toString(); case '<':
return result.toString();
default:{ default:{
result.append(c); result.append(c);
advance(); advance();
...@@ -239,26 +273,42 @@ public class SignatureParser { ...@@ -239,26 +273,42 @@ public class SignatureParser {
} }
return result.toString(); return result.toString();
} }
/**
* FieldTypeSignature:
* ClassTypeSignature
* ArrayTypeSignature
* TypeVariableSignature
*/
private FieldTypeSignature parseFieldTypeSignature() { private FieldTypeSignature parseFieldTypeSignature() {
return parseFieldTypeSignature(true);
}
private FieldTypeSignature parseFieldTypeSignature(boolean allowArrays) {
switch(current()) { switch(current()) {
case 'L': case 'L':
return parseClassTypeSignature(); return parseClassTypeSignature();
case 'T': case 'T':
return parseTypeVariableSignature(); return parseTypeVariableSignature();
case '[': case '[':
return parseArrayTypeSignature(); if (allowArrays)
return parseArrayTypeSignature();
else
throw error("Array signature not allowed here.");
default: throw error("Expected Field Type Signature"); default: throw error("Expected Field Type Signature");
} }
} }
/**
* ClassTypeSignature:
* "L" PackageSpecifier_opt SimpleClassTypeSignature ClassTypeSignatureSuffix* ";"
*/
private ClassTypeSignature parseClassTypeSignature(){ private ClassTypeSignature parseClassTypeSignature(){
assert(current() == 'L'); assert(current() == 'L');
if (current() != 'L') { throw error("expected a class type");} if (current() != 'L') { throw error("expected a class type");}
advance(); advance();
List<SimpleClassTypeSignature> scts = List<SimpleClassTypeSignature> scts = new ArrayList<>(5);
new ArrayList<SimpleClassTypeSignature>(5); scts.add(parsePackageNameAndSimpleClassTypeSignature());
scts.add(parseSimpleClassTypeSignature(false));
parseClassTypeSignatureSuffix(scts); parseClassTypeSignatureSuffix(scts);
if (current() != ';') if (current() != ';')
throw error("expected ';' got '" + current() + "'"); throw error("expected ';' got '" + current() + "'");
...@@ -267,25 +317,65 @@ public class SignatureParser { ...@@ -267,25 +317,65 @@ public class SignatureParser {
return ClassTypeSignature.make(scts); return ClassTypeSignature.make(scts);
} }
private SimpleClassTypeSignature parseSimpleClassTypeSignature(boolean dollar){ /**
String id = parseIdentifier(); * PackageSpecifier:
char c = current(); * Identifier "/" PackageSpecifier*
switch (c) { */
case ';': private SimpleClassTypeSignature parsePackageNameAndSimpleClassTypeSignature() {
case '/': // Parse both any optional leading PackageSpecifier as well as
return SimpleClassTypeSignature.make(id, dollar, new TypeArgument[0]) ; // the following SimpleClassTypeSignature.
case '<': {
return SimpleClassTypeSignature.make(id, dollar, parseTypeArguments()); String id = parseIdentifier();
}
default: {throw error("expected < or ; or /");} if (current() == '/') { // package name
StringBuilder idBuild = new StringBuilder(id);
while(current() == '/') {
advance();
idBuild.append(".");
idBuild.append(parseIdentifier());
} }
id = idBuild.toString();
}
switch (current()) {
case ';':
return SimpleClassTypeSignature.make(id, false, new TypeArgument[0]); // all done!
case '<':
if (DEBUG) System.out.println("\t remainder: " + remainder());
return SimpleClassTypeSignature.make(id, false, parseTypeArguments());
default:
throw error("expected '<' or ';' but got " + current());
}
} }
/**
* SimpleClassTypeSignature:
* Identifier TypeArguments_opt
*/
private SimpleClassTypeSignature parseSimpleClassTypeSignature(boolean dollar){
String id = parseIdentifier();
char c = current();
switch (c) {
case ';':
case '.':
return SimpleClassTypeSignature.make(id, dollar, new TypeArgument[0]) ;
case '<':
return SimpleClassTypeSignature.make(id, dollar, parseTypeArguments());
default:
throw error("expected '<' or ';' or '.', got '" + c + "'.");
}
}
/**
* ClassTypeSignatureSuffix:
* "." SimpleClassTypeSignature
*/
private void parseClassTypeSignatureSuffix(List<SimpleClassTypeSignature> scts) { private void parseClassTypeSignatureSuffix(List<SimpleClassTypeSignature> scts) {
while (current() == '/' || current() == '.') { while (current() == '.') {
boolean dollar = (current() == '.');
advance(); advance();
scts.add(parseSimpleClassTypeSignature(dollar)); scts.add(parseSimpleClassTypeSignature(true));
} }
} }
...@@ -294,10 +384,14 @@ public class SignatureParser { ...@@ -294,10 +384,14 @@ public class SignatureParser {
else {return new TypeArgument[0];} else {return new TypeArgument[0];}
} }
/**
* TypeArguments:
* "<" TypeArgument+ ">"
*/
private TypeArgument[] parseTypeArguments() { private TypeArgument[] parseTypeArguments() {
Collection<TypeArgument> tas = new ArrayList<TypeArgument>(3); List<TypeArgument> tas = new ArrayList<>(3);
assert(current() == '<'); assert(current() == '<');
if (current() != '<') { throw error("expected <");} if (current() != '<') { throw error("expected '<'");}
advance(); advance();
tas.add(parseTypeArgument()); tas.add(parseTypeArgument());
while (current() != '>') { while (current() != '>') {
...@@ -305,10 +399,14 @@ public class SignatureParser { ...@@ -305,10 +399,14 @@ public class SignatureParser {
tas.add(parseTypeArgument()); tas.add(parseTypeArgument());
} }
advance(); advance();
TypeArgument[] taa = new TypeArgument[tas.size()]; return tas.toArray(new TypeArgument[tas.size()]);
return tas.toArray(taa);
} }
/**
* TypeArgument:
* WildcardIndicator_opt FieldTypeSignature
* "*"
*/
private TypeArgument parseTypeArgument() { private TypeArgument parseTypeArgument() {
FieldTypeSignature[] ub, lb; FieldTypeSignature[] ub, lb;
ub = new FieldTypeSignature[1]; ub = new FieldTypeSignature[1];
...@@ -334,18 +432,20 @@ public class SignatureParser { ...@@ -334,18 +432,20 @@ public class SignatureParser {
ub[0] = SimpleClassTypeSignature.make("java.lang.Object", false, ta); ub[0] = SimpleClassTypeSignature.make("java.lang.Object", false, ta);
return Wildcard.make(ub, lb); return Wildcard.make(ub, lb);
} }
default: return parseFieldTypeSignature(); default:
return parseFieldTypeSignature();
} }
} }
// TypeVariableSignature -> T identifier /**
* TypeVariableSignature:
private TypeVariableSignature parseTypeVariableSignature(){ * "T" Identifier ";"
*/
private TypeVariableSignature parseTypeVariableSignature() {
assert(current() == 'T'); assert(current() == 'T');
if (current() != 'T') { throw error("expected a type variable usage");} if (current() != 'T') { throw error("expected a type variable usage");}
advance(); advance();
TypeVariableSignature ts = TypeVariableSignature ts = TypeVariableSignature.make(parseIdentifier());
TypeVariableSignature.make(parseIdentifier());
if (current() != ';') { if (current() != ';') {
throw error("; expected in signature of type variable named" + throw error("; expected in signature of type variable named" +
ts.getIdentifier()); ts.getIdentifier());
...@@ -354,16 +454,21 @@ public class SignatureParser { ...@@ -354,16 +454,21 @@ public class SignatureParser {
return ts; return ts;
} }
// ArrayTypeSignature -> [ TypeSignature /**
* ArrayTypeSignature:
* "[" TypeSignature
*/
private ArrayTypeSignature parseArrayTypeSignature() { private ArrayTypeSignature parseArrayTypeSignature() {
if (current() != '[') {throw error("expected array type signature");} if (current() != '[') {throw error("expected array type signature");}
advance(); advance();
return ArrayTypeSignature.make(parseTypeSignature()); return ArrayTypeSignature.make(parseTypeSignature());
} }
// TypeSignature -> BaseType | FieldTypeSignature /**
* TypeSignature:
* FieldTypeSignature
* BaseType
*/
private TypeSignature parseTypeSignature() { private TypeSignature parseTypeSignature() {
switch (current()) { switch (current()) {
case 'B': case 'B':
...@@ -373,8 +478,11 @@ public class SignatureParser { ...@@ -373,8 +478,11 @@ public class SignatureParser {
case 'I': case 'I':
case 'J': case 'J':
case 'S': case 'S':
case 'Z':return parseBaseType(); case 'Z':
default: return parseFieldTypeSignature(); return parseBaseType();
default:
return parseFieldTypeSignature();
} }
} }
...@@ -408,12 +516,18 @@ public class SignatureParser { ...@@ -408,12 +516,18 @@ public class SignatureParser {
assert(false); assert(false);
throw error("expected primitive type"); throw error("expected primitive type");
} }
} }
} }
private FieldTypeSignature[] parseZeroOrMoreBounds() { /**
Collection<FieldTypeSignature> fts = * ClassBound:
new ArrayList<FieldTypeSignature>(3); * ":" FieldTypeSignature_opt
*
* InterfaceBound:
* ":" FieldTypeSignature
*/
private FieldTypeSignature[] parseBounds() {
List<FieldTypeSignature> fts = new ArrayList<>(3);
if (current() == ':') { if (current() == ':') {
advance(); advance();
...@@ -430,24 +544,31 @@ public class SignatureParser { ...@@ -430,24 +544,31 @@ public class SignatureParser {
advance(); advance();
fts.add(parseFieldTypeSignature()); fts.add(parseFieldTypeSignature());
} }
} } else
error("Bound expected");
FieldTypeSignature[] fta = new FieldTypeSignature[fts.size()]; return fts.toArray(new FieldTypeSignature[fts.size()]);
return fts.toArray(fta);
} }
/**
* SuperclassSignature:
* ClassTypeSignature
*/
private ClassTypeSignature[] parseSuperInterfaces() { private ClassTypeSignature[] parseSuperInterfaces() {
Collection<ClassTypeSignature> cts = List<ClassTypeSignature> cts = new ArrayList<>(5);
new ArrayList<ClassTypeSignature>(5);
while(current() == 'L') { while(current() == 'L') {
cts.add(parseClassTypeSignature()); cts.add(parseClassTypeSignature());
} }
ClassTypeSignature[] cta = new ClassTypeSignature[cts.size()]; return cts.toArray(new ClassTypeSignature[cts.size()]);
return cts.toArray(cta);
} }
// parse a method signature based on the implicit input.
/**
* MethodTypeSignature:
* FormalTypeParameters_opt "(" TypeSignature* ")" ReturnType ThrowsSignature*
*/
private MethodTypeSignature parseMethodTypeSignature() { private MethodTypeSignature parseMethodTypeSignature() {
// Parse a method signature based on the implicit input.
FieldTypeSignature[] ets; FieldTypeSignature[] ets;
assert(index == 0); assert(index == 0);
...@@ -457,19 +578,19 @@ public class SignatureParser { ...@@ -457,19 +578,19 @@ public class SignatureParser {
parseZeroOrMoreThrowsSignatures()); parseZeroOrMoreThrowsSignatures());
} }
// (TypeSignature*) // "(" TypeSignature* ")"
private TypeSignature[] parseFormalParameters() { private TypeSignature[] parseFormalParameters() {
if (current() != '(') {throw error("expected (");} if (current() != '(') {throw error("expected '('");}
advance(); advance();
TypeSignature[] pts = parseZeroOrMoreTypeSignatures(); TypeSignature[] pts = parseZeroOrMoreTypeSignatures();
if (current() != ')') {throw error("expected )");} if (current() != ')') {throw error("expected ')'");}
advance(); advance();
return pts; return pts;
} }
// TypeSignature* // TypeSignature*
private TypeSignature[] parseZeroOrMoreTypeSignatures() { private TypeSignature[] parseZeroOrMoreTypeSignatures() {
Collection<TypeSignature> ts = new ArrayList<TypeSignature>(); List<TypeSignature> ts = new ArrayList<>();
boolean stop = false; boolean stop = false;
while (!stop) { while (!stop) {
switch(current()) { switch(current()) {
...@@ -484,47 +605,46 @@ public class SignatureParser { ...@@ -484,47 +605,46 @@ public class SignatureParser {
case 'L': case 'L':
case 'T': case 'T':
case '[': { case '[': {
ts.add(parseTypeSignature()); ts.add(parseTypeSignature());
break; break;
} }
default: stop = true; default: stop = true;
} }
} }
/* while( matches(current(), return ts.toArray(new TypeSignature[ts.size()]);
'B', 'C', 'D', 'F', 'I', 'J', 'S', 'Z', 'L', 'T', '[')
) {
ts.add(parseTypeSignature());
}*/
TypeSignature[] ta = new TypeSignature[ts.size()];
return ts.toArray(ta);
} }
// ReturnType -> V | TypeSignature /**
* ReturnType:
* TypeSignature
* VoidDescriptor
*/
private ReturnType parseReturnType(){ private ReturnType parseReturnType(){
if (current() == 'V') { if (current() == 'V') {
advance(); advance();
return VoidDescriptor.make(); return VoidDescriptor.make();
} else return parseTypeSignature(); } else
return parseTypeSignature();
} }
// ThrowSignature* // ThrowSignature*
private FieldTypeSignature[] parseZeroOrMoreThrowsSignatures(){ private FieldTypeSignature[] parseZeroOrMoreThrowsSignatures(){
Collection<FieldTypeSignature> ets = List<FieldTypeSignature> ets = new ArrayList<>(3);
new ArrayList<FieldTypeSignature>(3);
while( current() == '^') { while( current() == '^') {
ets.add(parseThrowsSignature()); ets.add(parseThrowsSignature());
} }
FieldTypeSignature[] eta = new FieldTypeSignature[ets.size()]; return ets.toArray(new FieldTypeSignature[ets.size()]);
return ets.toArray(eta);
} }
// ThrowSignature -> ^ FieldTypeSignature /**
* ThrowsSignature:
* "^" ClassTypeSignature
* "^" TypeVariableSignature
*/
private FieldTypeSignature parseThrowsSignature() { private FieldTypeSignature parseThrowsSignature() {
assert(current() == '^'); assert(current() == '^');
if (current() != '^') { throw error("expected throws signature");} if (current() != '^') { throw error("expected throws signature");}
advance(); advance();
return parseFieldTypeSignature(); return parseFieldTypeSignature(false);
} }
} }
/* /*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -87,7 +87,7 @@ final class Session implements Comparable<Session> { ...@@ -87,7 +87,7 @@ final class Session implements Comparable<Session> {
} }
long id() { long id() {
if (token.isPresent(this) == false) { if (token.isPresent(this.id) == false) {
throw new ProviderException("Token has been removed"); throw new ProviderException("Token has been removed");
} }
lastAccess = System.currentTimeMillis(); lastAccess = System.currentTimeMillis();
...@@ -167,7 +167,9 @@ final class SessionRef extends PhantomReference<Session> ...@@ -167,7 +167,9 @@ final class SessionRef extends PhantomReference<Session>
void dispose() { void dispose() {
refList.remove(this); refList.remove(this);
try { try {
token.p11.C_CloseSession(id); if (token.isPresent(id)) {
token.p11.C_CloseSession(id);
}
} catch (PKCS11Exception e1) { } catch (PKCS11Exception e1) {
// ignore // ignore
} catch (ProviderException e2) { } catch (ProviderException e2) {
......
/* /*
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -217,7 +217,7 @@ class Token implements Serializable { ...@@ -217,7 +217,7 @@ class Token implements Serializable {
// return whether a token is present (i.e. token not removed) // return whether a token is present (i.e. token not removed)
// returns cached value if current, otherwise performs new check // returns cached value if current, otherwise performs new check
boolean isPresent(Session session) { boolean isPresent(long sessionID) {
if (removable == false) { if (removable == false) {
return true; return true;
} }
...@@ -238,7 +238,7 @@ class Token implements Serializable { ...@@ -238,7 +238,7 @@ class Token implements Serializable {
// the token should return an error // the token should return an error
CK_SESSION_INFO sessInfo = CK_SESSION_INFO sessInfo =
provider.p11.C_GetSessionInfo provider.p11.C_GetSessionInfo
(session.idInternal()); (sessionID);
ok = true; ok = true;
} }
} catch (PKCS11Exception e) { } catch (PKCS11Exception e) {
......
...@@ -105,7 +105,13 @@ public class X509CertPath extends CertPath { ...@@ -105,7 +105,13 @@ public class X509CertPath extends CertPath {
super("X.509"); super("X.509");
// Ensure that the List contains only X509Certificates // Ensure that the List contains only X509Certificates
for (Certificate obj : certs) { //
// Note; The certs parameter is not necessarily to be of Certificate
// for some old code. For compatibility, to make sure the exception
// is CertificateException, rather than ClassCastException, please
// don't use
// for (Certificate obj : certs)
for (Object obj : certs) {
if (obj instanceof X509Certificate == false) { if (obj instanceof X509Certificate == false) {
throw new CertificateException throw new CertificateException
("List is not all X509Certificates: " ("List is not all X509Certificates: "
......
...@@ -1401,8 +1401,7 @@ public class X500Name implements GeneralNameInterface, Principal { ...@@ -1401,8 +1401,7 @@ public class X500Name implements GeneralNameInterface, Principal {
principalConstructor = constr; principalConstructor = constr;
principalField = (Field)result[1]; principalField = (Field)result[1];
} catch (Exception e) { } catch (Exception e) {
throw (InternalError)new InternalError("Could not obtain " throw new InternalError("Could not obtain X500Principal access", e);
+ "X500Principal access").initCause(e);
} }
} }
......
...@@ -48,10 +48,12 @@ public class DefaultLayoutStyle extends LayoutStyle { ...@@ -48,10 +48,12 @@ public class DefaultLayoutStyle extends LayoutStyle {
@Override @Override
public int getPreferredGap(JComponent component1, JComponent component2, public int getPreferredGap(JComponent component1, JComponent component2,
ComponentPlacement type, int position, Container parent) { ComponentPlacement type, int position, Container parent) {
if (component1 == null || component2 == null || type == null) { if (component1 == null || component2 == null || type == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
checkPosition(position);
if (type == ComponentPlacement.INDENT && if (type == ComponentPlacement.INDENT &&
(position == SwingConstants.EAST || (position == SwingConstants.EAST ||
position == SwingConstants.WEST)) { position == SwingConstants.WEST)) {
......
...@@ -208,7 +208,7 @@ public class ProxyClient implements JConsoleContext { ...@@ -208,7 +208,7 @@ public class ProxyClient implements JConsoleContext {
serverStubClass = Class.forName(rmiServerImplStubClassName).asSubclass(Remote.class); serverStubClass = Class.forName(rmiServerImplStubClassName).asSubclass(Remote.class);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// should never reach here // should never reach here
throw (InternalError) new InternalError(e.getMessage()).initCause(e); throw new InternalError(e.getMessage(), e);
} }
rmiServerImplStubClass = serverStubClass; rmiServerImplStubClass = serverStubClass;
} }
...@@ -395,18 +395,10 @@ public class ProxyClient implements JConsoleContext { ...@@ -395,18 +395,10 @@ public class ProxyClient implements JConsoleContext {
} catch (MalformedObjectNameException e) { } catch (MalformedObjectNameException e) {
// should not reach here // should not reach here
throw new InternalError(e.getMessage()); throw new InternalError(e.getMessage());
} catch (IntrospectionException e) { } catch (IntrospectionException |
InternalError ie = new InternalError(e.getMessage()); InstanceNotFoundException |
ie.initCause(e); ReflectionException e) {
throw ie; throw new InternalError(e.getMessage(), e);
} catch (InstanceNotFoundException e) {
InternalError ie = new InternalError(e.getMessage());
ie.initCause(e);
throw ie;
} catch (ReflectionException e) {
InternalError ie = new InternalError(e.getMessage());
ie.initCause(e);
throw ie;
} }
if (hasPlatformMXBeans) { if (hasPlatformMXBeans) {
......
...@@ -166,8 +166,8 @@ class InheritedChannel { ...@@ -166,8 +166,8 @@ class InheritedChannel {
// is implemented. // is implemented.
Class paramTypes[] = { int.class }; Class paramTypes[] = { int.class };
Constructor ctr = Reflect.lookupConstructor("java.io.FileDescriptor", Constructor<?> ctr = Reflect.lookupConstructor("java.io.FileDescriptor",
paramTypes); paramTypes);
Object args[] = { new Integer(fdVal) }; Object args[] = { new Integer(fdVal) };
FileDescriptor fd = (FileDescriptor)Reflect.invoke(ctr, args); FileDescriptor fd = (FileDescriptor)Reflect.invoke(ctr, args);
......
...@@ -225,6 +225,10 @@ image/png: \ ...@@ -225,6 +225,10 @@ image/png: \
icon=png;\ icon=png;\
action=browser action=browser
image/bmp: \
description=Bitmap Image;\
file_extensions=.bmp;
text/html: \ text/html: \
description=HTML Document;\ description=HTML Document;\
file_extensions=.htm,.html;\ file_extensions=.htm,.html;\
......
...@@ -55,9 +55,7 @@ public class WindowsAsynchronousFileChannelImpl ...@@ -55,9 +55,7 @@ public class WindowsAsynchronousFileChannelImpl
try { try {
return new Iocp(null, ThreadPool.createDefault()).start(); return new Iocp(null, ThreadPool.createDefault()).start();
} catch (IOException ioe) { } catch (IOException ioe) {
InternalError e = new InternalError(); throw new InternalError(ioe);
e.initCause(ioe);
throw e;
} }
} }
} }
......
...@@ -222,6 +222,10 @@ image/png: \ ...@@ -222,6 +222,10 @@ image/png: \
icon=png;\ icon=png;\
action=browser action=browser
image/bmp: \
description=Bitmap Image;\
file_extensions=.bmp;
text/html: \ text/html: \
description=HTML Document;\ description=HTML Document;\
file_extensions=.htm,.html;\ file_extensions=.htm,.html;\
......
...@@ -198,10 +198,16 @@ java/beans/XMLEncoder/6329581/Test6329581.java generic-all ...@@ -198,10 +198,16 @@ java/beans/XMLEncoder/6329581/Test6329581.java generic-all
# requires junit # requires junit
java/lang/invoke/InvokeDynamicPrintArgs.java generic-all java/lang/invoke/InvokeDynamicPrintArgs.java generic-all
# 7079093
java/lang/instrument/ManifestTest.sh windows-all
############################################################################ ############################################################################
# jdk_management # jdk_management
# 6944188
java/lang/management/ThreadMXBean/ThreadStateTest.java generic-all
# 7067973 # 7067973
java/lang/management/MemoryMXBean/CollectionUsageThreshold.java generic-all java/lang/management/MemoryMXBean/CollectionUsageThreshold.java generic-all
...@@ -368,6 +374,12 @@ com/sun/net/httpserver/Test9a.java generic-all ...@@ -368,6 +374,12 @@ com/sun/net/httpserver/Test9a.java generic-all
# 7079145 java/net/ipv6tests/UdpTest.java hang at IPv6 only data exchange # 7079145 java/net/ipv6tests/UdpTest.java hang at IPv6 only data exchange
java/net/ipv6tests/UdpTest.java linux-all java/net/ipv6tests/UdpTest.java linux-all
# 7079012
java/net/NetworkInterface/NetParamsTest.java solaris-all
# 7081476
java/net/InetSocketAddress/B6469803.java generic-all
############################################################################ ############################################################################
# jdk_io # jdk_io
...@@ -375,6 +387,12 @@ java/net/ipv6tests/UdpTest.java linux-all ...@@ -375,6 +387,12 @@ java/net/ipv6tests/UdpTest.java linux-all
# 6962637 # 6962637
java/io/File/MaxPathLength.java windows-all java/io/File/MaxPathLength.java windows-all
# 6671616
java/io/File/BlockIsDirectory.java solaris-all
# 7076644
java/io/File/Basic.java windows-all
############################################################################ ############################################################################
# jdk_nio # jdk_nio
...@@ -382,6 +400,9 @@ java/io/File/MaxPathLength.java windows-all ...@@ -382,6 +400,9 @@ java/io/File/MaxPathLength.java windows-all
# 6963118 # 6963118
java/nio/channels/Selector/Wakeup.java windows-all java/nio/channels/Selector/Wakeup.java windows-all
# 7076700
java/nio/channels/SocketChannel/AdaptSocket.java generic-all
############################################################################ ############################################################################
# jdk_rmi # jdk_rmi
...@@ -499,6 +520,12 @@ sun/security/ssl/sanity/interop/ClientJSSEServerJSSE.java generic-all ...@@ -499,6 +520,12 @@ sun/security/ssl/sanity/interop/ClientJSSEServerJSSE.java generic-all
# 7079203 sun/security/tools/keytool/printssl.sh fails on solaris with timeout # 7079203 sun/security/tools/keytool/printssl.sh fails on solaris with timeout
sun/security/tools/keytool/printssl.sh solaris-all sun/security/tools/keytool/printssl.sh solaris-all
# 7054637
sun/security/tools/jarsigner/ec.sh solaris-all
# 7081817
sun/security/provider/certpath/X509CertPath/IllegalCertiticates.java generic-all
############################################################################ ############################################################################
# jdk_swing (not using samevm) # jdk_swing (not using samevm)
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7043847 7043860 7043882 7043938 7043959
* @summary NTML impl of SaslServer conformance errors
*/
import java.io.IOException;
import javax.security.sasl.*;
import java.util.*;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
public class Conformance {
public static void main(String[] args) throws Exception {
try {
Sasl.createSaslClient(new String[] {"NTLM"}, "abc", "ldap",
"server", new HashMap<String, Object>(), null);
} catch (SaslException se) {
System.out.println(se);
}
try {
Sasl.createSaslServer("NTLM", "ldap",
"server", new HashMap<String, Object>(), null);
} catch (SaslException se) {
System.out.println(se);
}
try {
Sasl.createSaslClient(new String[] {"NTLM"}, "abc", "ldap",
"server", null, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws
IOException, UnsupportedCallbackException { }
});
} catch (SaslException se) {
System.out.println(se);
}
try {
SaslServer saslServer =
Sasl.createSaslServer("NTLM", "ldap", "abc", null, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { }
});
System.err.println("saslServer = " + saslServer);
System.err.println("saslServer.isComplete() = " + saslServer.isComplete());
// IllegalStateException is expected here
saslServer.getNegotiatedProperty("prop");
System.err.println("No IllegalStateException");
} catch (IllegalStateException se) {
System.out.println(se);
}
try {
SaslServer saslServer =
Sasl.createSaslServer("NTLM", "ldap", "abc", null, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { }
});
System.err.println("saslServer = " + saslServer);
System.err.println("saslServer.isComplete() = " + saslServer.isComplete());
// IllegalStateException is expected here
saslServer.getAuthorizationID();
System.err.println("No IllegalStateException");
} catch (IllegalStateException se) {
System.out.println(se);
}
try {
SaslServer saslServer =
Sasl.createSaslServer("NTLM", "ldap", "abc", null, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { }
});
System.err.println("saslServer = " + saslServer);
System.err.println("saslServer.isComplete() = " + saslServer.isComplete());
// IllegalStateException is expected here
saslServer.wrap(new byte[0], 0, 0);
System.err.println("No IllegalStateException");
} catch (IllegalStateException se) {
System.out.println(se);
}
}
}
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import sun.awt.SunToolkit;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.Point;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
/**
* @test
* @bug 6263470
* @summary Tries to change font of MenuBar. Test passes if the font has changed
* fails otherwise.
* @author Vyacheslav.Baranov: area=menu
* @run main MenuBarSetFont
*/
public final class MenuBarSetFont {
private static final Frame frame = new Frame();
private static final MenuBar mb = new MenuBar();
private static volatile boolean clicked;
private static final class Listener implements ActionListener {
@Override
public void actionPerformed(final ActionEvent e) {
//Click on this button is performed
//_only_ if font of MenuBar is not changed on time
MenuBarSetFont.clicked = true;
}
}
private static void addMenu() {
mb.add(new Menu("w"));
frame.validate();
}
public static void main(final String[] args) throws Exception {
//Components initialization.
frame.setMenuBar(mb);
mb.setFont(new Font("Helvetica", Font.ITALIC, 5));
final Button button = new Button("Click Me");
button.addActionListener(new Listener());
frame.setLayout(new CardLayout());
frame.add(button, "First");
frame.setSize(400, 400);
frame.setVisible(true);
sleep();
final int fInsets = frame.getInsets().top; //Frame insets without menu.
addMenu();
final int fMenuInsets = frame.getInsets().top; //Frame insets with menu.
final int menuBarHeight = fMenuInsets - fInsets;
// There is no way to change menubar height on windows. But on windows
// we can try to split menubar in 2 rows.
for (int i = 0; i < 100 && fMenuInsets == frame.getInsets().top; ++i) {
// Fill whole menubar.
addMenu();
}
mb.remove(0);
frame.validate();
sleep();
// Test execution.
// On XToolkit, menubar font should be changed to 60.
// On WToolkit, menubar font should be changed to default and menubar
// should be splitted in 2 rows.
mb.setFont(new Font("Helvetica", Font.ITALIC, 60));
sleep();
final Robot r = new Robot();
r.setAutoDelay(200);
final Point pt = frame.getLocation();
r.mouseMove(pt.x + frame.getWidth() / 2,
pt.y + fMenuInsets + menuBarHeight / 2);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
sleep();
frame.dispose();
if (clicked) {
fail("Font was not changed");
}
}
private static void sleep() {
((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
try {
Thread.sleep(500L);
} catch (InterruptedException ignored) {
}
}
private static void fail(final String message) {
throw new RuntimeException(message);
}
}
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
/* @test /* @test
@bug 4167937 @bug 4167937
@ignore Test truncates system files when run as root, see 7042603
@summary Test code paths that use the JVM_LastErrorString procedure @summary Test code paths that use the JVM_LastErrorString procedure
*/ */
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.*;
/**
* @test
* @bug 7015589
* @summary Test that buffering streams are considered closed even when the
* close or flush from the underlying stream fails.
*/
public class FailingFlushAndClose {
static int failed;
static void fail(String msg) {
System.err.println("FAIL: " + msg);
failed++;
}
static void failWithIOE(String msg) throws IOException {
fail(msg);
throw new IOException(msg);
}
static class FailingCloseInputStream extends InputStream {
boolean closed;
@Override
public int read()throws IOException {
if (closed)
failWithIOE("input stream is closed");
return 1;
}
@Override
public void close() throws IOException {
if (!closed) {
closed = true;
throw new IOException("close failed");
}
}
}
static class FailingCloseOutputStream extends OutputStream {
boolean closed;
@Override
public void write(int b) throws IOException {
if (closed)
failWithIOE("output stream is closed");
}
@Override
public void flush() throws IOException {
if (closed)
failWithIOE("output stream is closed");
}
@Override
public void close() throws IOException {
if (!closed) {
closed = true;
throw new IOException("close failed");
}
}
}
static class FailingFlushOutputStream extends OutputStream {
boolean closed;
@Override
public void write(int b) throws IOException {
if (closed)
failWithIOE("output stream is closed");
}
@Override
public void flush() throws IOException {
if (closed) {
failWithIOE("output stream is closed");
} else {
throw new IOException("flush failed");
}
}
@Override
public void close() throws IOException {
closed = true;
}
}
static class FailingCloseReader extends Reader {
boolean closed;
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
if (closed)
failWithIOE("reader is closed");
return 1;
}
@Override
public void close() throws IOException {
if (!closed) {
closed = true;
throw new IOException("close failed");
}
}
}
static class FailingCloseWriter extends Writer {
boolean closed;
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
if (closed)
failWithIOE("writer is closed");
}
@Override
public void flush() throws IOException {
if (closed)
failWithIOE("writer is closed");
}
@Override
public void close() throws IOException {
if (!closed) {
closed = true;
throw new IOException("close failed");
}
}
}
static class FailingFlushWriter extends Writer {
boolean closed;
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
if (closed)
failWithIOE("writer is closed");
}
@Override
public void flush() throws IOException {
if (closed) {
failWithIOE("writer is closed");
} else {
throw new IOException("flush failed");
}
}
@Override
public void close() throws IOException {
if (!closed) {
closed = true;
throw new IOException("close failed");
}
}
}
static void testFailingClose(InputStream in) throws IOException {
System.out.println(in.getClass());
in.read(new byte[100]);
try {
in.close();
fail("close did not fail");
} catch (IOException expected) { }
try {
in.read(new byte[100]);
fail("read did not fail");
} catch (IOException expected) { }
}
static void testFailingClose(OutputStream out) throws IOException {
System.out.println(out.getClass());
out.write(1);
try {
out.close();
fail("close did not fail");
} catch (IOException expected) { }
try {
out.write(1);
if (!(out instanceof BufferedOutputStream))
fail("write did not fail");
} catch (IOException expected) { }
}
static void testFailingFlush(OutputStream out) throws IOException {
System.out.println(out.getClass());
out.write(1);
try {
out.flush();
fail("flush did not fail");
} catch (IOException expected) { }
if (out instanceof BufferedOutputStream) {
out.write(1);
try {
out.close();
fail("close did not fail");
} catch (IOException expected) { }
}
}
static void testFailingClose(Reader r) throws IOException {
System.out.println(r.getClass());
r.read(new char[100]);
try {
r.close();
fail("close did not fail");
} catch (IOException expected) { }
try {
r.read(new char[100]);
fail("read did not fail");
} catch (IOException expected) { }
}
static void testFailingClose(Writer w) throws IOException {
System.out.println(w.getClass());
w.write("message");
try {
w.close();
fail("close did not fail");
} catch (IOException expected) { }
try {
w.write("another message");
fail("write did not fail");
} catch (IOException expected) { }
}
static void testFailingFlush(Writer w) throws IOException {
System.out.println(w.getClass());
w.write("message");
try {
w.flush();
fail("flush did not fail");
} catch (IOException expected) { }
if (w instanceof BufferedWriter) {
// assume this message will be buffered
w.write("another message");
try {
w.close();
fail("close did not fail");
} catch (IOException expected) { }
}
}
public static void main(String[] args) throws IOException {
testFailingClose(new BufferedInputStream(new FailingCloseInputStream()));
testFailingClose(new BufferedOutputStream(new FailingCloseOutputStream()));
testFailingClose(new BufferedReader(new FailingCloseReader()));
testFailingClose(new BufferedWriter(new FailingCloseWriter()));
testFailingFlush(new BufferedOutputStream(new FailingFlushOutputStream()));
testFailingFlush(new BufferedWriter(new FailingFlushWriter()));
if (failed > 0)
throw new RuntimeException(failed + " test(s) failed - see log for details");
}
}
...@@ -1803,7 +1803,7 @@ public class Basic { ...@@ -1803,7 +1803,7 @@ public class Basic {
p.getInputStream().close(); p.getInputStream().close();
p.getErrorStream().close(); p.getErrorStream().close();
p.getOutputStream().close(); try { p.getOutputStream().close(); } catch (IOException flushFailed) { }
InputStream[] streams = { p.getInputStream(), p.getErrorStream() }; InputStream[] streams = { p.getInputStream(), p.getErrorStream() };
for (final InputStream in : streams) { for (final InputStream in : streams) {
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 7068328
* @summary Test if getObjectName handles properly when called by
* multiple threads simultaneously. Run in othervm mode to
* make sure the object name is not initialized to begin with.
* @run main/othervm GetObjectName
*/
import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.PlatformLoggingMXBean;
import java.lang.management.PlatformManagedObject;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
public class GetObjectName {
private static boolean failed = false;
public static void main(String[] args) throws Exception {
int tasks = 10000;
ExecutorService executor = Executors.newFixedThreadPool(10);
submitTasks(executor, tasks);
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
if (!failed) {
System.out.println("Test passed.");
}
}
static void submitTasks(ExecutorService executor, int count) {
for (int i=0; i < count && !failed; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
List<PlatformManagedObject> mbeans = new ArrayList<>();
mbeans.add(ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class));
mbeans.addAll(ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class));
for (PlatformManagedObject pmo : mbeans) {
// Name should not be null
if (pmo.getObjectName() == null) {
failed = true;
throw new RuntimeException("TEST FAILED: getObjectName() returns null");
}
}
}
});
}
}
}
/* /*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 5003916 6704655 6873951 * @bug 5003916 6704655 6873951 6476261
* @summary Testing parsing of signatures attributes of nested classes * @summary Testing parsing of signatures attributes of nested classes
* @author Joseph D. Darcy * @author Joseph D. Darcy
*/ */
...@@ -38,12 +38,12 @@ import static java.util.Arrays.*; ...@@ -38,12 +38,12 @@ import static java.util.Arrays.*;
"java.util.concurrent.ConcurrentHashMap$KeyIterator", "java.util.concurrent.ConcurrentHashMap$KeyIterator",
"java.util.concurrent.ConcurrentHashMap$ValueIterator", "java.util.concurrent.ConcurrentHashMap$ValueIterator",
"java.util.AbstractList$ListItr", "java.util.AbstractList$ListItr",
// "java.util.EnumMap$EntryIterator", "java.util.EnumMap$EntryIterator",
// "java.util.EnumMap$KeyIterator", "java.util.EnumMap$KeyIterator",
// "java.util.EnumMap$ValueIterator", "java.util.EnumMap$ValueIterator",
// "java.util.IdentityHashMap$EntryIterator", "java.util.IdentityHashMap$EntryIterator",
// "java.util.IdentityHashMap$KeyIterator", "java.util.IdentityHashMap$KeyIterator",
// "java.util.IdentityHashMap$ValueIterator", "java.util.IdentityHashMap$ValueIterator",
"java.util.WeakHashMap$EntryIterator", "java.util.WeakHashMap$EntryIterator",
"java.util.WeakHashMap$KeyIterator", "java.util.WeakHashMap$KeyIterator",
"java.util.WeakHashMap$ValueIterator", "java.util.WeakHashMap$ValueIterator",
...@@ -52,12 +52,12 @@ import static java.util.Arrays.*; ...@@ -52,12 +52,12 @@ import static java.util.Arrays.*;
"java.util.HashMap$ValueIterator", "java.util.HashMap$ValueIterator",
"java.util.LinkedHashMap$EntryIterator", "java.util.LinkedHashMap$EntryIterator",
"java.util.LinkedHashMap$KeyIterator", "java.util.LinkedHashMap$KeyIterator",
"java.util.LinkedHashMap$ValueIterator"}) "java.util.LinkedHashMap$ValueIterator",
"javax.swing.JComboBox$AccessibleJComboBox"})
public class Probe { public class Probe {
public static void main (String... args) throws Throwable { public static void main (String... args) throws Throwable {
Classes classesAnnotation = (Probe.class).getAnnotation(Classes.class); Classes classesAnnotation = (Probe.class).getAnnotation(Classes.class);
List<String> names = List<String> names = new ArrayList<>(asList(classesAnnotation.value()));
new ArrayList<String>(asList(classesAnnotation.value()));
int errs = 0; int errs = 0;
for(String name: names) { for(String name: names) {
......
/*
* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6476261
* @summary More testing of parsing of signatures attributes of nested classes
*/
import java.lang.reflect.*;
public class SignatureTest<T> {
class Inner1 {
class Inner11 {
}
}
public void f(SignatureTest<String>.Inner1.Inner11 x) {}
public void g(SignatureTest<String>.Inner1 x) {}
public static void main(String[] args) throws Exception {
Class clazz = SignatureTest.class;
for (Method m : clazz.getDeclaredMethods()) {
System.out.println();
System.out.println(m.toString());
System.out.println(m.toGenericString());
System.out.println(m.getGenericParameterTypes());
}
}
}
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6832374 7052898
* @summary Test bad signatures get a GenericSignatureFormatError thrown.
* @author Joseph D. Darcy
*/
import java.lang.reflect.*;
import sun.reflect.generics.parser.SignatureParser;
public class TestBadSignatures {
public static void main(String[] args) {
String[] badSignatures = {
// Missing ":" after first type bound
"<T:Lfoo/tools/nsc/symtab/Names;Lfoo/tools/nsc/symtab/Symbols;",
// Arrays improperly indicated for exception information
"<E:Ljava/lang/Exception;>(TE;[Ljava/lang/RuntimeException;)V^[TE;",
};
for(String badSig : badSignatures) {
try {
SignatureParser.make().parseMethodSig(badSig);
throw new RuntimeException("Expected GenericSignatureFormatError for " +
badSig);
} catch(GenericSignatureFormatError gsfe) {
System.out.println(gsfe.toString()); // Expected
}
}
}
}
...@@ -362,12 +362,13 @@ public class TestHttpCookie { ...@@ -362,12 +362,13 @@ public class TestHttpCookie {
eq(c1, c2, false); eq(c1, c2, false);
header("Test domainMatches()"); header("Test domainMatches()");
dm(".foo.com", "y.x.foo.com", false); dm(".foo.com", "y.x.foo.com", false);
dm(".foo.com", "x.foo.com", true); dm(".foo.com", "x.foo.com", true);
dm(".com", "whatever.com", false); dm(".com", "whatever.com", false);
dm(".com.", "whatever.com", false); dm(".com.", "whatever.com", false);
dm(".ajax.com", "ajax.com", true); dm(".ajax.com", "ajax.com", true);
dm(".local", "example.local", true); dm(".local", "example.local", true);
dm("example.local", "example", true);
// bug 6277808 // bug 6277808
testCount++; testCount++;
......
...@@ -57,11 +57,22 @@ class NetworkConfiguration { ...@@ -57,11 +57,22 @@ class NetworkConfiguration {
return ip6Interfaces.get(nif); return ip6Interfaces.get(nif);
} }
// IPv6 not supported for Windows XP/Server 2003
static boolean isIPv6Supported() {
if (System.getProperty("os.name").startsWith("Windows")) {
String ver = System.getProperty("os.version");
int major = Integer.parseInt(ver.split("\\.")[0]);
return (major >= 6);
}
return true;
}
static NetworkConfiguration probe() throws IOException { static NetworkConfiguration probe() throws IOException {
Map<NetworkInterface,List<InetAddress>> ip4Interfaces = Map<NetworkInterface,List<InetAddress>> ip4Interfaces =
new HashMap<NetworkInterface,List<InetAddress>>(); new HashMap<NetworkInterface,List<InetAddress>>();
Map<NetworkInterface,List<InetAddress>> ip6Interfaces = Map<NetworkInterface,List<InetAddress>> ip6Interfaces =
new HashMap<NetworkInterface,List<InetAddress>>(); new HashMap<NetworkInterface,List<InetAddress>>();
boolean isIPv6Supported = isIPv6Supported();
// find the interfaces that support IPv4 and IPv6 // find the interfaces that support IPv4 and IPv6
List<NetworkInterface> nifs = Collections List<NetworkInterface> nifs = Collections
...@@ -81,7 +92,7 @@ class NetworkConfiguration { ...@@ -81,7 +92,7 @@ class NetworkConfiguration {
} }
list.add(addr); list.add(addr);
ip4Interfaces.put(nif, list); ip4Interfaces.put(nif, list);
} else if (addr instanceof Inet6Address) { } else if (isIPv6Supported && (addr instanceof Inet6Address)) {
List<InetAddress> list = ip6Interfaces.get(nif); List<InetAddress> list = ip6Interfaces.get(nif);
if (list == null) { if (list == null) {
list = new LinkedList<InetAddress>(); list = new LinkedList<InetAddress>();
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
*/ */
/* @test /* @test
* @bug 6935563 * @bug 6935563 7044870
* @summary Test that Selector does not select an unconnected DatagramChannel when * @summary Test that Selector does not select an unconnected DatagramChannel when
* ICMP port unreachable received * ICMP port unreachable received
*/ */
...@@ -35,14 +35,15 @@ import java.io.IOException; ...@@ -35,14 +35,15 @@ import java.io.IOException;
public class SelectWhenRefused { public class SelectWhenRefused {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
DatagramChannel dc = DatagramChannel.open().bind(new InetSocketAddress(0)); DatagramChannel dc1 = DatagramChannel.open().bind(new InetSocketAddress(0));
int port = dc.socket().getLocalPort(); int port = dc1.socket().getLocalPort();
dc.close();
// datagram sent to this address should be refused // datagram sent to this address should be refused
SocketAddress refuser = new InetSocketAddress(InetAddress.getLocalHost(), port); SocketAddress refuser = new InetSocketAddress(InetAddress.getLocalHost(), port);
dc = DatagramChannel.open().bind(new InetSocketAddress(0)); DatagramChannel dc = DatagramChannel.open().bind(new InetSocketAddress(0));
dc1.close();
Selector sel = Selector.open(); Selector sel = Selector.open();
try { try {
dc.configureBlocking(false); dc.configureBlocking(false);
...@@ -52,6 +53,10 @@ public class SelectWhenRefused { ...@@ -52,6 +53,10 @@ public class SelectWhenRefused {
sendDatagram(dc, refuser); sendDatagram(dc, refuser);
int n = sel.select(2000); int n = sel.select(2000);
if (n > 0) { if (n > 0) {
sel.selectedKeys().clear();
// BindException will be thrown if another service is using
// our expected refuser port, cannot run just exit.
DatagramChannel.open().bind(refuser).close();
throw new RuntimeException("Unexpected wakeup"); throw new RuntimeException("Unexpected wakeup");
} }
...@@ -80,6 +85,8 @@ public class SelectWhenRefused { ...@@ -80,6 +85,8 @@ public class SelectWhenRefused {
throw new RuntimeException("Unexpected wakeup after disconnect"); throw new RuntimeException("Unexpected wakeup after disconnect");
} }
} catch(BindException e) {
// Do nothing, some other test has used this port
} finally { } finally {
sel.close(); sel.close();
dc.close(); dc.close();
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7071166
* @summary LayoutStyle.getPreferredGap() - IAE is expected but not thrown
* @author Pavel Porvatov
*/
import javax.swing.*;
import static javax.swing.SwingConstants.*;
import java.awt.*;
public class bug7071166 {
private static final int[] POSITIONS = {NORTH, EAST, SOUTH, WEST, // valid positions
NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST, 123, -456}; // invalid positions
public static void main(String[] args) throws Exception {
for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) {
UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
System.out.println("LookAndFeel: " + lookAndFeelInfo.getName());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
LayoutStyle layoutStyle = LayoutStyle.getInstance();
System.out.println("LayoutStyle: " + layoutStyle);
for (int i = 0; i < POSITIONS.length; i++) {
int position = POSITIONS[i];
try {
layoutStyle.getPreferredGap(new JButton(), new JButton(),
LayoutStyle.ComponentPlacement.RELATED, position, new Container());
if (i > 3) {
throw new RuntimeException("IllegalArgumentException is not thrown for position " +
position);
}
} catch (IllegalArgumentException e) {
if (i <= 3) {
throw new RuntimeException("IllegalArgumentException is thrown for position " +
position);
}
}
}
}
});
System.out.println("passed");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册