Buggy code:
final class EndpointImpl extends AbstractHandleableCloseable < Endpoint > implements Endpoint { private static final Logger log = Logger . getLogger ( "org.jboss.remoting.endpoint" ) ; private static final RemotingPermission REGISTER_SERVICE_PERM = new RemotingPermission ( "registerService" ) ; private static final RemotingPermission CREATE_CHANNEL_PERM = new RemotingPermission ( "createChannel" ) ; private static final RemotingPermission CONNECT_PERM = new RemotingPermission ( "connect" ) ; private static final RemotingPermission ADD_CONNECTION_PROVIDER_PERM = new RemotingPermission ( "addConnectionProvider" ) ; private static final RemotingPermission GET_CONNECTION_PROVIDER_INTERFACE_PERM = new RemotingPermission ( "getConnectionProviderInterface" ) ; private final Attachments attachments = new Attachments ( ) ; private final ConcurrentMap < String , ConnectionProvider > connectionProviders = new UnlockedReadHashMap < String , ConnectionProvider > ( ) ; private final ConcurrentMap < String , OpenListener > registeredServices = new UnlockedReadHashMap < String , OpenListener > ( ) ; private final Set < Connection > connections = Collections . synchronizedSet ( Collections . newSetFromMap ( new IdentityHashMap < Connection , Boolean > ( ) ) ) ; private static final Pattern VALID_SERVICE_PATTERN = Pattern . compile ( "[-.:a-zA-Z_0-9]+" ) ; private final String name ; @ SuppressWarnings ( "unused" ) private final OptionMap optionMap ; private final ConnectionProviderContext connectionProviderContext ; private final CloseHandler < Connection > connectionCloseHandler = new CloseHandler < Connection > ( ) { public void handleClose ( final Connection closed , final IOException exception ) { } } ; EndpointImpl ( final Executor executor , final String name , final OptionMap optionMap ) throws IOException { } private final Executor executor ; protected Executor getExecutor ( ) { } public Attachments getAttachments ( ) { } public String getName ( ) { } public ChannelPair createChannelPair ( ) { } protected void closeAction ( ) throws IOException { @ SuppressWarnings ( "serial" ) class CloseCounter extends AtomicInteger implements CloseHandler < Object > { CloseCounter ( ) { } public void handleClose ( final Object closed , final IOException exception ) { tick ( ) ; } void tick ( ) { <START_BUG> if ( ( getAndDecrement ( ) ) == 0 ) { <END_BUG> closeComplete ( ) ; } } void addTo ( HandleableCloseable < ? > target ) { getAndIncrement ( ) ; target . closeAsync ( ) ; target . addCloseHandler ( this ) ; } } final CloseCounter counter = new CloseCounter ( ) ; for ( ConnectionProvider connectionProvider : connectionProviders . values ( ) ) { counter . addTo ( connectionProvider ) ; } Object [ ] array = connections . toArray ( ) ; for ( Object connection : array ) { counter . addTo ( ( ( Connection ) ( connection ) ) ) ; } counter . tick ( ) ; } public Registration registerService ( final String serviceType , final OpenListener openListener , final OptionMap optionMap ) throws ServiceRegistrationException { } public IoFuture < Connection > connect ( final URI destination ) throws IOException { } public IoFuture < Connection > connect ( final URI destination , final OptionMap connectOptions ) throws IOException { } private IoFuture < Connection > doConnect ( final URI destination , final OptionMap connectOptions , final CallbackHandler callbackHandler ) throws IOException { } public IoFuture < Connection > connect ( final URI destination , final OptionMap connectOptions , final CallbackHandler callbackHandler ) throws IOException { } public IoFuture < Connection > connect ( final URI destination , final OptionMap connectOptions , final String userName , final String realmName , final char [ ] password ) throws IOException { } public Registration addConnectionProvider ( final String uriScheme , final ConnectionProviderFactory providerFactory , final OptionMap optionMap ) throws IOException { } public < T > T getConnectionProviderInterface ( final String uriScheme , final Class < T > expectedType ) throws ClassCastException , UnknownURISchemeException { } public boolean isValidUriScheme ( final String uriScheme ) { } public String toString ( ) { } private static final Charset UTF_8 = Charset . forName ( "UTF-8" ) ; private static String uriDecode ( String encoded ) { } static final class UserAndRealm { private final String user ; private final String realm ; UserAndRealm ( final String user , final String realm ) { } public String getUser ( ) { } public String getRealm ( ) { } } private static final EndpointImpl . UserAndRealm EMPTY = new EndpointImpl . UserAndRealm ( null , null ) ; private EndpointImpl . UserAndRealm getUserAndRealm ( URI uri ) { } private class MapRegistration < T > extends AbstractHandleableCloseable < Registration > implements Registration { private final ConcurrentMap < String , T > map ; private final String key ; private final T value ; private MapRegistration ( final ConcurrentMap < String , T > map , final String key , final T value ) { } protected void closeAction ( ) throws IOException { map . remove ( key , value ) ; EndpointImpl . MapRegistration . closeComplete ( ) ; } public void close ( ) { } public String toString ( ) { } } final class LocalConnectionContext implements ConnectionHandlerContext { private final ConnectionProviderContext connectionProviderContext ; private final Connection connection ; LocalConnectionContext ( final ConnectionProviderContext connectionProviderContext , final Connection connection ) { } public ConnectionProviderContext getConnectionProviderContext ( ) { } public void openService ( final Channel newChannel , final String serviceType ) throws ServiceNotFoundException { } public void remoteClosed ( ) { } } private final class ConnectionProviderContextImpl implements ConnectionProviderContext { private ConnectionProviderContextImpl ( ) { } public Executor getExecutor ( ) { } public void accept ( final ConnectionHandlerFactory connectionHandlerFactory ) { } public Endpoint getEndpoint ( ) { } } }

Fix:
if ( ( decrementAndGet ( ) ) == 0 ) {