RegistrationContextImpl.removeListener() always returns false - it initialises the return value in the beginning, but never changes it even if the listener for removal is found. The result is that when detachListener() calls removeListener, it allways gets false, and finally does not return the correct registration id.
This pull request contains a test case, which illustrates the problem and a fix for it: https://github.com/apache/tomcat/pull/86
Again, many thanks for the report, patch and test case. Fixed in: - trunk for 9.0.2 onwards - 8.5.x for 8.5.24 onwards