This is -1 from me, as this a classic anti-pattern: You are using the enum's ordinal value for sorting :-(
I am guessing Micheal will also recognize this from Effective Java's guidelines "Never derive a value associated with an enum from its ordinal; store it in an instance field instead". Guess what happens if you change the order of the enum values in the source? Everything breaks. Please revert. Gary On Tue, Dec 31, 2019 at 11:53 AM <[email protected]> wrote: > This is an automated email from the ASF dual-hosted git repository. > > olegk pushed a commit to branch master > in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git > > > The following commit(s) were added to refs/heads/master by this push: > new 4eff05c HTTPCORE-620: removed unnecessary rank attribute from > IOSession.Status enum > 4eff05c is described below > > commit 4eff05c2b6f21b08878c33b364fd9552c66dcc5b > Author: Oleg Kalnichevski <[email protected]> > AuthorDate: Tue Dec 31 17:48:22 2019 +0100 > > HTTPCORE-620: removed unnecessary rank attribute from IOSession.Status > enum > --- > .../main/java/org/apache/hc/core5/reactor/IOSession.java | 14 > ++++---------- > .../java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java | 9 ++++----- > 2 files changed, 8 insertions(+), 15 deletions(-) > > diff --git > a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java > b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java > index b8ca8c7..f1c10ab 100644 > --- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java > +++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java > @@ -55,17 +55,11 @@ import org.apache.hc.core5.util.Timeout; > @Internal > public interface IOSession extends ByteChannel, SocketModalCloseable, > Identifiable { > > - public enum Status { > + enum Status { > > - ACTIVE(0), > - CLOSING(1), > - CLOSED(Integer.MAX_VALUE); > - > - private Status(final int rank) { > - this.rank = rank; > - } > - > - public final int rank; > + ACTIVE, > + CLOSING, > + CLOSED > > } > > diff --git > a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java > b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java > index f4678ab..c135ea4 100644 > --- > a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java > +++ > b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java > @@ -41,7 +41,6 @@ import javax.net.ssl.SSLContext; > import javax.net.ssl.SSLEngine; > import javax.net.ssl.SSLEngineResult; > import javax.net.ssl.SSLEngineResult.HandshakeStatus; > -import javax.net.ssl.SSLEngineResult.Status; > import javax.net.ssl.SSLException; > import javax.net.ssl.SSLSession; > > @@ -228,7 +227,7 @@ public class SSLIOSession implements IOSession { > > this.session.getLock().lock(); > try { > - if (this.status.rank >= Status.CLOSING.rank) { > + if (this.status.compareTo(Status.CLOSING) >= 0) { > return; > } > switch (this.sslMode) { > @@ -352,7 +351,7 @@ public class SSLIOSession implements IOSession { > } > } > > - if (this.status.rank >= Status.CLOSING.rank) { > + if (this.status.compareTo(Status.CLOSING) >= 0) { > this.inPlain.release(); > } > if (result.getStatus() != SSLEngineResult.Status.OK) { > @@ -404,7 +403,7 @@ public class SSLIOSession implements IOSession { > this.status = Status.CLOSED; > } > // Abnormal session termination > - if (this.status.rank <= Status.CLOSING.rank && > this.endOfStream > + if (this.status.compareTo(Status.CLOSING) <= 0 && > this.endOfStream > && this.sslEngine.getHandshakeStatus() == > HandshakeStatus.NEED_UNWRAP) { > this.status = Status.CLOSED; > } > @@ -632,7 +631,7 @@ public class SSLIOSession implements IOSession { > this.session.getLock().lock(); > try { > if (closeMode == CloseMode.GRACEFUL) { > - if (this.status.rank >= Status.CLOSING.rank) { > + if (this.status.compareTo(Status.CLOSING) >= 0) { > return; > } > this.status = Status.CLOSING; > >
