### Question:
AuthenticationFilter extends EnvironmentFilter { @Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { try { super.removeConnection(context, info, error); } finally { SecurityContext secCtx = context.getSecurityContext(); if (secCtx instanceof SubjectSecurityContext) { SubjectSecurityContext subjectSecurityContext = (SubjectSecurityContext) secCtx; Subject subject = subjectSecurityContext.getSubject(); if (subject != null) { try { subject.logout(); } catch (Throwable t) { String msg = "Unable to cleanly logout connection Subject during connection removal. This is " + "unexpected but not critical: it can be safely ignored because the " + "connection will no longer be used."; LOG.info(msg, t); } } } } } AuthenticationFilter(); AuthenticationPolicy getAuthenticationPolicy(); void setAuthenticationPolicy(AuthenticationPolicy authenticationPolicy); AuthenticationTokenFactory getAuthenticationTokenFactory(); void setAuthenticationTokenFactory(AuthenticationTokenFactory authenticationTokenFactory); @Override void addConnection(ConnectionContext context, ConnectionInfo info); @Override void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error);  }### Answer:
@Test public void testRemoveAuthenticationWithLogoutThrowable() throws Exception { final boolean[] invoked = new boolean[1]; Broker broker = new BrokerPluginSupport() { @Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { invoked[0] = true; } }; DefaultEnvironment env = new DefaultEnvironment(); filter.setNext(broker); filter.setEnvironment(env); Subject subject = new SubjectAdapter() { @Override public void logout() { throw new RuntimeException("Simulated failure."); } }; ConnectionContext ctx = new ConnectionContext(); ConnectionInfo info = new ConnectionInfo(); SubjectConnectionReference conn = new SubjectConnectionReference(ctx, info, env, subject); SubjectSecurityContext ssc = new SubjectSecurityContext(conn); ctx.setSecurityContext(ssc); filter.removeConnection(ctx, info, null); assertTrue(invoked[0]); }