Index: src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java =================================================================== --- src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java (revision 498563) +++ src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java (working copy) @@ -45,7 +45,7 @@ */ private List keyList = new ArrayList(); - private class BlockingLock { + private static class BlockingLock { } private final Object blockingLock = new BlockingLock(); Index: src/main/java/java/nio/channels/spi/SelectorProvider.java =================================================================== --- src/main/java/java/nio/channels/spi/SelectorProvider.java (revision 498563) +++ src/main/java/java/nio/channels/spi/SelectorProvider.java (working copy) @@ -136,6 +136,13 @@ (enumeration.nextElement()).openStream())); } catch (Exception e) { continue; + } finally { + if(br != null) { + try { + br.close(); + } catch (IOException e) { + } + } } try { // only the first class is loaded ,as spec says, not the same as @@ -152,6 +159,11 @@ } } catch (Exception e) { throw new Error(e); + } finally { + try { + br.close(); + } catch (IOException e) { + } } } return null; Index: src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java =================================================================== --- src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java (revision 498563) +++ src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java (working copy) @@ -87,11 +87,11 @@ boolean isBound = false; // lock for read and receive - private class ReadLock {} + private static class ReadLock {} private final Object readLock = new ReadLock(); // lock for write and send - private class WriteLock {} + private static class WriteLock {} private final Object writeLock = new WriteLock(); // used to store the trafficClass value which is simply returned Index: src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java =================================================================== --- src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java (revision 498563) +++ src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java (working copy) @@ -65,7 +65,7 @@ // The object that will track all outstanding locks on this channel. private final LockManager lockManager = new LockManager(); - private class RepositioningLock {} + private static class RepositioningLock {} private final Object repositioningLock = new RepositioningLock(); private final Object stream; Index: src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java =================================================================== --- src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java (revision 498563) +++ src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java (working copy) @@ -43,19 +43,6 @@ public class ServerSocketChannelImpl extends ServerSocketChannel implements FileDescriptorHandler { - // ---------------------------------------------------- - // Class variables - // ---------------------------------------------------- - - // status un-init, not initialized. - private static final int SERVER_STATUS_UNINIT = -1; - - // status after open and before closed. - private static final int SERVER_STATUS_OPEN = 0; - - // status closed. - private static final int SERVER_STATUS_CLOSED = 1; - // ------------------------------------------------------------------- // Instance variables // ------------------------------------------------------------------- @@ -68,8 +55,6 @@ private final SocketImpl impl; - int status = SERVER_STATUS_UNINIT; - // whether the socket is bound boolean isBound = false; @@ -74,7 +59,7 @@ boolean isBound = false; // lock for accept - private class AcceptLock {} + private static class AcceptLock {} private final Object acceptLock = new AcceptLock(); // ---------------------------------------------------- @@ -86,7 +71,6 @@ */ public ServerSocketChannelImpl(SelectorProvider sp) throws IOException { super(sp); - status = SERVER_STATUS_OPEN; fd = new FileDescriptor(); Platform.getNetworkSystem().createServerStreamSocket(fd, NetUtil.preferIPv4Stack()); @@ -97,7 +81,6 @@ // for native call private ServerSocketChannelImpl() throws IOException { super(SelectorProvider.provider()); - status = SERVER_STATUS_OPEN; fd = new FileDescriptor(); impl = SocketImplProvider.getServerSocketImpl(fd); socket = new ServerSocketAdapter(impl, this); @@ -189,7 +172,6 @@ * @see java.nio.channels.spi.AbstractSelectableChannel#implCloseSelectableChannel() */ synchronized protected void implCloseSelectableChannel() throws IOException { - status = SERVER_STATUS_CLOSED; if (!socket.isClosed()) { socket.close(); } @@ -313,7 +295,6 @@ } else { super.close(); } - channelImpl.status = SERVER_STATUS_CLOSED; } } } Index: src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java =================================================================== --- src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java (revision 498563) +++ src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java (working copy) @@ -124,10 +124,10 @@ boolean isBound = false; // lock for read and write - private class ReadLock {} + private static class ReadLock {} private final Object readLock = new ReadLock(); - private class WriteLock {} + private static class WriteLock {} private final Object writeLock = new WriteLock(); // this content is a point used to set in connect_withtimeout() in pending @@ -283,15 +283,17 @@ finished = (CONNECT_SUCCESS == result); isBound = finished; } catch (IOException e) { - if (e instanceof ConnectException && !isBlocking()) { - status = SOCKET_STATUS_PENDING; - } else { - if (isOpen()){ - close(); - finished = true; - } - throw e; - } + synchronized(this) { + if (e instanceof ConnectException && !isBlocking()) { + status = SOCKET_STATUS_PENDING; + } else { + if (isOpen()){ + close(); + finished = true; + } + throw e; + } + } } finally { if (isBlocking()) { end(finished); @@ -720,10 +722,10 @@ * @see java.net.Socket#bind(java.net.SocketAddress) */ public void bind(SocketAddress localAddr) throws IOException { - if (channel.isConnected()) { + if (channel.isConnected()) { throw new AlreadyConnectedException(); } - if (SocketChannelImpl.SOCKET_STATUS_PENDING == channel.status) { + if (channel.isConnectionPending()) { throw new ConnectionPendingException(); } super.bind(localAddr);