This is an automated email from the ASF dual-hosted git repository.

tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git


The following commit(s) were added to refs/heads/main by this push:
     new ccf4147f PROTON-2925 Update instanceof checks to use patterns
ccf4147f is described below

commit ccf4147ff7210c2110731ba736f13fcbd5108f4f
Author: Timothy Bish <[email protected]>
AuthorDate: Tue Mar 24 17:53:25 2026 -0400

    PROTON-2925 Update instanceof checks to use patterns
    
    Use parrtern matching in instanceof checks to clean up some code
---
 .../apache/qpid/protonj2/client/SourceOptions.java |  8 +++----
 .../protonj2/client/impl/ClientConnection.java     |  3 +--
 .../protonj2/client/impl/ClientDeliveryState.java  | 20 +++++++----------
 .../protonj2/client/impl/ClientErrorCondition.java |  4 ++--
 .../client/impl/ClientExceptionSupport.java        | 25 +++++++++++-----------
 .../protonj2/client/impl/ClientMessageSupport.java |  8 +++----
 .../client/impl/ClientNextReceiverSelector.java    |  4 +---
 .../client/impl/ClientStreamSenderMessage.java     |  4 ++--
 .../client/transport/netty4/SslSupport.java        |  4 ++--
 .../client/transport/netty4/TcpTransport.java      |  8 +++----
 .../transport/netty4/WebSocketTransport.java       | 12 ++++-------
 .../protonj2/client/util/IOExceptionSupport.java   |  4 ++--
 .../buffer/impl/ProtonByteArrayBuffer.java         |  2 +-
 .../buffer/impl/ProtonCompositeBufferImpl.java     |  6 +++---
 .../buffer/netty/Netty4ToProtonBufferAdapter.java  |  4 ++--
 .../decoders/UnknownDescribedTypeDecoder.java      |  4 ++--
 .../primitives/AbstractArrayTypeDecoder.java       |  6 ++----
 .../protonj2/codec/encoders/ProtonEncoder.java     | 12 +++++------
 .../engine/exceptions/ProtonExceptionSupport.java  |  8 +++----
 .../protonj2/engine/impl/ProtonConnection.java     |  5 ++---
 .../engine/impl/ProtonEngineConfiguration.java     |  4 ++--
 .../engine/impl/ProtonTransactionManager.java      |  3 +--
 .../protonj2/engine/util/DeliveryIdTracker.java    | 12 +++++------
 .../qpid/protonj2/engine/util/SequenceNumber.java  |  4 ++--
 .../apache/qpid/protonj2/engine/util/SplayMap.java |  6 ++----
 .../apache/qpid/protonj2/types/DeliveryTag.java    |  7 +++---
 .../org/apache/qpid/protonj2/types/Symbol.java     |  4 ++--
 .../qpid/protonj2/types/transport/Attach.java      | 12 +++++------
 28 files changed, 92 insertions(+), 111 deletions(-)

diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/SourceOptions.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/SourceOptions.java
index dd35f943..712d57de 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/SourceOptions.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/SourceOptions.java
@@ -208,13 +208,11 @@ public final class SourceOptions extends 
TerminusOptions<SourceOptions> implemen
                 return false;
             }
 
-            if (!(target instanceof DescribedType)) {
-                return false;
+            if (target instanceof DescribedType other) {
+                return Objects.equals(descriptor, other.getDescriptor()) && 
Objects.equals(described, other.getDescribed());
             }
 
-            final DescribedType other = (DescribedType) target;
-
-            return Objects.equals(descriptor, other.getDescriptor()) && 
Objects.equals(described, other.getDescribed());
+            return false;
         }
     }
 }
diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientConnection.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientConnection.java
index 2a3ba67b..f12df017 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientConnection.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientConnection.java
@@ -1054,8 +1054,7 @@ public final class ClientConnection implements Connection 
{
     }
 
     private boolean isStoppageCause(ClientException cause) {
-        if (cause instanceof ClientConnectionSecuritySaslException) {
-            ClientConnectionSecuritySaslException saslFailure = 
(ClientConnectionSecuritySaslException) cause;
+        if (cause instanceof ClientConnectionSecuritySaslException 
saslFailure) {
             return !saslFailure.isSysTempFailure();
         } else if (cause instanceof ClientConnectionSecurityException ) {
             return true;
diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientDeliveryState.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientDeliveryState.java
index afdf5155..30e4cdbf 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientDeliveryState.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientDeliveryState.java
@@ -55,10 +55,10 @@ public abstract class ClientDeliveryState implements 
DeliveryState {
             return ClientAccepted.getInstance();
         } else if (outcome instanceof Released) {
             return ClientReleased.getInstance();
-        } else if (outcome instanceof Rejected) {
-            return ClientRejected.fromProtonType((Rejected) outcome);
-        } else if (outcome instanceof Modified) {
-            return ClientModified.fromProtonType((Modified) outcome);
+        } else if (outcome instanceof Rejected rejected) {
+            return ClientRejected.fromProtonType(rejected);
+        } else if (outcome instanceof Modified modified) {
+            return ClientModified.fromProtonType(modified);
         }
 
         throw new IllegalArgumentException("Cannot map to unknown Proton 
Outcome to a DeliveryStateType: " + outcome);
@@ -100,8 +100,8 @@ public abstract class ClientDeliveryState implements 
DeliveryState {
     static org.apache.qpid.protonj2.types.transport.DeliveryState 
asProtonType(DeliveryState state) {
         if (state == null) {
             return null;
-        } else if (state instanceof ClientDeliveryState) {
-            return ((ClientDeliveryState) state).getProtonDeliveryState();
+        } else if (state instanceof ClientDeliveryState deliveryState) {
+            return deliveryState.getProtonDeliveryState();
         } else {
             switch (state.getType()) {
                 case ACCEPTED:
@@ -251,9 +251,7 @@ public abstract class ClientDeliveryState implements 
DeliveryState {
         }
 
         static Rejected fromUnknownClientType(DeliveryState deliveryState) {
-            if (deliveryState instanceof 
org.apache.qpid.protonj2.client.Rejected) {
-                org.apache.qpid.protonj2.client.Rejected rejectedState = 
(org.apache.qpid.protonj2.client.Rejected) deliveryState;
-
+            if (deliveryState instanceof 
org.apache.qpid.protonj2.client.Rejected rejectedState) {
                 return new Rejected(new 
ErrorCondition(rejectedState.getCondition(),
                                                        
rejectedState.getDescription(),
                                                        
ClientConversionSupport.toSymbolKeyedMap(rejectedState.getInfo())));
@@ -332,9 +330,7 @@ public abstract class ClientDeliveryState implements 
DeliveryState {
         }
 
         static Modified fromUnknownClientType(DeliveryState deliveryState) {
-            if (deliveryState instanceof 
org.apache.qpid.protonj2.client.Modified) {
-                org.apache.qpid.protonj2.client.Modified modifiedState = 
(org.apache.qpid.protonj2.client.Modified) deliveryState;
-
+            if (deliveryState instanceof 
org.apache.qpid.protonj2.client.Modified modifiedState) {
                 return new Modified(modifiedState.isDeliveryFailed(), 
modifiedState.isUndeliverableHere(),
                                     
ClientConversionSupport.toSymbolKeyedMap(modifiedState.getMessageAnnotations()));
             } else {
diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientErrorCondition.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientErrorCondition.java
index 285494b9..d6520293 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientErrorCondition.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientErrorCondition.java
@@ -92,8 +92,8 @@ public final class ClientErrorCondition implements 
ErrorCondition {
     static org.apache.qpid.protonj2.types.transport.ErrorCondition 
asProtonErrorCondition(ErrorCondition condition) {
         if (condition == null) {
             return null;
-        } else if (condition instanceof ClientErrorCondition) {
-            return ((ClientErrorCondition) 
condition).getProtonErrorCondition();
+        } else if (condition instanceof ClientErrorCondition errorCondition) {
+            return errorCondition.getProtonErrorCondition();
         } else {
             return new 
ClientErrorCondition(condition).getProtonErrorCondition();
         }
diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientExceptionSupport.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientExceptionSupport.java
index 94c76cd1..c22a6de8 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientExceptionSupport.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientExceptionSupport.java
@@ -54,12 +54,12 @@ final class ClientExceptionSupport {
      * @return an ClientIOException instance.
      */
     public static ClientIOException createOrPassthroughFatal(Throwable cause) {
-        if (cause instanceof ClientIOException) {
-            return (ClientIOException) cause;
+        if (cause instanceof ClientIOException ioError) {
+            return ioError;
         }
 
-        if (cause.getCause() instanceof ClientIOException) {
-            return (ClientIOException) cause.getCause();
+        if (cause.getCause() instanceof ClientIOException ioError) {
+            return ioError;
         }
 
         String message = cause.getMessage();
@@ -82,12 +82,12 @@ final class ClientExceptionSupport {
      * @return an ClientException instance.
      */
     public static ClientException createNonFatalOrPassthrough(Throwable cause) 
{
-        if (cause instanceof ClientException) {
-            return (ClientException) cause;
+        if (cause instanceof ClientException exception) {
+            return exception;
         }
 
-        if (cause.getCause() instanceof ClientException) {
-            return (ClientException) cause.getCause();
+        if (cause.getCause() instanceof ClientException exception) {
+            return exception;
         }
 
         String message = cause.getMessage();
@@ -146,11 +146,10 @@ final class ClientExceptionSupport {
     public static ClientConnectionRemotelyClosedException 
convertToConnectionClosedException(Throwable cause) {
         ClientConnectionRemotelyClosedException remoteError = null;
 
-        if (cause instanceof ClientConnectionRemotelyClosedException) {
-            remoteError = (ClientConnectionRemotelyClosedException) cause;
-        } else if (cause instanceof SaslSystemException) {
-            remoteError = new ClientConnectionSecuritySaslException(
-                cause.getMessage(), !((SaslSystemException) 
cause).isPermanent(), cause);
+        if (cause instanceof ClientConnectionRemotelyClosedException 
exception) {
+            remoteError = exception;
+        } else if (cause instanceof SaslSystemException exception) {
+            remoteError = new 
ClientConnectionSecuritySaslException(cause.getMessage(), 
!exception.isPermanent(), cause);
         } else if (cause instanceof SaslException) {
             remoteError = new 
ClientConnectionSecuritySaslException(cause.getMessage(), cause);
         } else {
diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessageSupport.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessageSupport.java
index 6c33da53..5481b2b4 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessageSupport.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessageSupport.java
@@ -208,10 +208,10 @@ public abstract class ClientMessageSupport {
     public static <E> Section<E> createSectionFromValue(E body) {
         if (body == null) {
             return null;
-        } else if (body instanceof byte[]) {
-            return (Section<E>) new Data((byte[]) body);
-        } else if (body instanceof List){
-            return new AmqpSequence((List) body);
+        } else if (body instanceof byte[] bytesBody) {
+            return (Section<E>) new Data(bytesBody);
+        } else if (body instanceof List listBody){
+            return new AmqpSequence(listBody);
         } else {
             return new AmqpValue(body);
         }
diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientNextReceiverSelector.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientNextReceiverSelector.java
index a6f04b5c..8fc27a14 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientNextReceiverSelector.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientNextReceiverSelector.java
@@ -194,9 +194,7 @@ final class ClientNextReceiverSelector {
         if (!pending.isEmpty() && !delivery.isPartial() && 
!delivery.isAborted()) {
             // We only handle next receiver events for normal client receivers 
and
             // not for stream receiver types etc.
-            if (delivery.getLink().getLinkedResource() instanceof 
ClientReceiver) {
-                ClientReceiver receiver = 
delivery.getLink().getLinkedResource();
-
+            if (delivery.getLink().getLinkedResource() instanceof 
ClientReceiver receiver) {
                 // Track last returned to update state for Round Robin next 
receiver dispatch
                 
delivery.getLink().getSession().getAttachments().set(LAST_RETURNED_STATE_KEY, 
receiver);
 
diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientStreamSenderMessage.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientStreamSenderMessage.java
index 2d90c67a..c7230eb1 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientStreamSenderMessage.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientStreamSenderMessage.java
@@ -950,8 +950,8 @@ final class ClientStreamSenderMessage implements 
StreamSenderMessage {
         if (buffer == null) {
             buffer = incoming.transfer();
         } else {
-            if (buffer instanceof ProtonCompositeBuffer) {
-                ((ProtonCompositeBuffer) buffer).append(incoming);
+            if (buffer instanceof ProtonCompositeBuffer composite) {
+                composite.append(incoming);
             } else {
                 buffer = 
ProtonBufferAllocator.defaultAllocator().composite(new ProtonBuffer[] { buffer, 
incoming });
             }
diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/SslSupport.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/SslSupport.java
index dba4d25f..5827c2dd 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/SslSupport.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/SslSupport.java
@@ -422,8 +422,8 @@ public final class SslSupport {
         KeyManager[] keyManagers = new KeyManager[origKeyManagers.length];
         for (int i = 0; i < origKeyManagers.length; i++) {
             KeyManager km = origKeyManagers[i];
-            if (km instanceof X509ExtendedKeyManager) {
-                km = new X509AliasKeyManager(alias, (X509ExtendedKeyManager) 
km);
+            if (km instanceof X509ExtendedKeyManager x509km) {
+                km = new X509AliasKeyManager(alias, x509km);
             }
 
             keyManagers[i] = km;
diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/TcpTransport.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/TcpTransport.java
index c8e0c6ea..376c0838 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/TcpTransport.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/TcpTransport.java
@@ -310,8 +310,8 @@ public class TcpTransport implements Transport {
     protected final ByteBuf toOutputBuffer(final ProtonBuffer output) throws 
IOException {
         final ByteBuf nettyBuf;
 
-        if (output instanceof Netty4ToProtonBufferAdapter) {
-            nettyBuf = ((Netty4ToProtonBufferAdapter) 
output).unwrapAndRelease();
+        if (output instanceof Netty4ToProtonBufferAdapter nettyAdapter) {
+            nettyBuf = nettyAdapter.unwrapAndRelease();
         } else {
             try (output) {
                 Netty4ToProtonBufferAdapter wrapped = 
nettyAllocator.outputBuffer(output.getReadableBytes());
@@ -330,8 +330,8 @@ public class TcpTransport implements Transport {
             for (ProtonBufferComponent output = accessor.firstReadable(); 
output != null; output = accessor.nextReadable()) {
                 final ByteBuf nettyBuf;
 
-                if (output instanceof Netty4ToProtonBufferAdapter) {
-                    nettyBuf = 
((Netty4ToProtonBufferAdapter)output).unwrapAndRelease();
+                if (output instanceof Netty4ToProtonBufferAdapter 
nettyAdapter) {
+                    nettyBuf = nettyAdapter.unwrapAndRelease();
                 } else if (output.unwrap() instanceof ByteBuf) {
                     nettyBuf = (ByteBuf) 
ReferenceCountUtil.retain(output.unwrap());
                 } else {
diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/WebSocketTransport.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/WebSocketTransport.java
index 9e28d65f..9a5414c6 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/WebSocketTransport.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/WebSocketTransport.java
@@ -225,24 +225,20 @@ public class WebSocketTransport extends TcpTransport {
             }
 
             // We shouldn't get this since we handle the handshake previously.
-            if (message instanceof FullHttpResponse) {
-                FullHttpResponse response = (FullHttpResponse) message;
+            if (message instanceof FullHttpResponse response) {
                 throw new IllegalStateException(
                     "Unexpected FullHttpResponse (getStatus=" + 
response.status() +
                     ", content=" + 
response.content().toString(StandardCharsets.UTF_8) + ')');
             }
 
             WebSocketFrame frame = (WebSocketFrame) message;
-            if (frame instanceof TextWebSocketFrame) {
-                TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
+            if (frame instanceof TextWebSocketFrame textFrame) {
                 LOG.warn("WebSocket Client received message: " + 
textFrame.text());
                 ctx.fireExceptionCaught(new IOException("Received invalid 
frame over WebSocket."));
-            } else if (frame instanceof BinaryWebSocketFrame) {
-                BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) 
frame;
+            } else if (frame instanceof BinaryWebSocketFrame binaryFrame) {
                 LOG.trace("WebSocket Client received data: {} bytes", 
binaryFrame.content().readableBytes());
                 dispatchReadBuffer(binaryFrame.content());
-            } else if (frame instanceof ContinuationWebSocketFrame) {
-                ContinuationWebSocketFrame continuationFrame = 
(ContinuationWebSocketFrame) frame;
+            } else if (frame instanceof ContinuationWebSocketFrame 
continuationFrame) {
                 LOG.trace("WebSocket Client received data continuation: {} 
bytes", continuationFrame.content().readableBytes());
                 dispatchReadBuffer(continuationFrame.content());
             } else if (frame instanceof PingWebSocketFrame) {
diff --git 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/util/IOExceptionSupport.java
 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/util/IOExceptionSupport.java
index bf2f08ef..6868bf3c 100644
--- 
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/util/IOExceptionSupport.java
+++ 
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/util/IOExceptionSupport.java
@@ -33,8 +33,8 @@ public abstract class IOExceptionSupport {
      * @return an IOException instance.
      */
     public static IOException create(Throwable cause) {
-        if (cause instanceof IOException) {
-            return (IOException) cause;
+        if (cause instanceof IOException error) {
+            return error;
         }
 
         String message = cause.getMessage();
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/impl/ProtonByteArrayBuffer.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/impl/ProtonByteArrayBuffer.java
index bae7e493..7e5e0fb3 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/impl/ProtonByteArrayBuffer.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/impl/ProtonByteArrayBuffer.java
@@ -341,7 +341,7 @@ public final class ProtonByteArrayBuffer extends 
SharedResource<ProtonBuffer> im
 
     @Override
     public boolean equals(Object o) {
-        return o instanceof ProtonBuffer && ProtonBufferUtils.equals(this, 
(ProtonBuffer) o);
+        return o instanceof ProtonBuffer buffer && 
ProtonBufferUtils.equals(this, buffer);
     }
 
     @Override
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/impl/ProtonCompositeBufferImpl.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/impl/ProtonCompositeBufferImpl.java
index 2eb2faaf..4e1c35cc 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/impl/ProtonCompositeBufferImpl.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/impl/ProtonCompositeBufferImpl.java
@@ -904,7 +904,7 @@ public final class ProtonCompositeBufferImpl extends 
SharedResource<ProtonBuffer
 
     @Override
     public boolean equals(Object o) {
-        return o instanceof ProtonBuffer && ProtonBufferUtils.equals(this, 
(ProtonBuffer) o);
+        return o instanceof ProtonBuffer buffer && 
ProtonBufferUtils.equals(this, buffer);
     }
 
     @Override
@@ -938,8 +938,8 @@ public final class ProtonCompositeBufferImpl extends 
SharedResource<ProtonBuffer
             return 0;
         }
 
-        if (channel instanceof GatheringByteChannel) {
-            return transferToGatheringByteChannel((GatheringByteChannel) 
channel, writableBytes);
+        if (channel instanceof GatheringByteChannel gatheringChannel) {
+            return transferToGatheringByteChannel(gatheringChannel, 
writableBytes);
         } else {
             return transferToWritableByteChannel(channel, writableBytes);
         }
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/netty/Netty4ToProtonBufferAdapter.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/netty/Netty4ToProtonBufferAdapter.java
index 3cdb34de..623d4968 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/netty/Netty4ToProtonBufferAdapter.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/netty/Netty4ToProtonBufferAdapter.java
@@ -502,8 +502,8 @@ public final class Netty4ToProtonBufferAdapter extends 
SharedResource<ProtonBuff
 
     @Override
     public boolean equals(Object other) {
-        if (other instanceof ProtonBuffer) {
-            return ProtonBufferUtils.equals(this, (ProtonBuffer) other);
+        if (other instanceof ProtonBuffer buffer) {
+            return ProtonBufferUtils.equals(this, buffer);
         }
 
         return false;
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/UnknownDescribedTypeDecoder.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/UnknownDescribedTypeDecoder.java
index bb040aee..3f204442 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/UnknownDescribedTypeDecoder.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/UnknownDescribedTypeDecoder.java
@@ -41,12 +41,12 @@ public abstract class UnknownDescribedTypeDecoder extends 
AbstractDescribedTypeD
 
     @Override
     public final UnsignedLong getDescriptorCode() {
-        return getDescriptor() instanceof UnsignedLong ? (UnsignedLong) 
getDescriptor() : null;
+        return getDescriptor() instanceof UnsignedLong code ? code : null;
     }
 
     @Override
     public final Symbol getDescriptorSymbol() {
-        return getDescriptor() instanceof Symbol ? (Symbol) getDescriptor() : 
null;
+        return getDescriptor() instanceof Symbol symbol ? symbol : null;
     }
 
     @Override
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/primitives/AbstractArrayTypeDecoder.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/primitives/AbstractArrayTypeDecoder.java
index cbb02ea7..f1ec7204 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/primitives/AbstractArrayTypeDecoder.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/primitives/AbstractArrayTypeDecoder.java
@@ -88,8 +88,7 @@ public abstract class AbstractArrayTypeDecoder extends 
AbstractPrimitiveTypeDeco
     private static Object decodeArray(ProtonBuffer buffer, DecoderState state, 
int count) throws DecodeException {
         final TypeDecoder<?> decoder = 
state.getDecoder().readNextTypeDecoder(buffer, state);
 
-        if (decoder instanceof PrimitiveTypeDecoder) {
-            final PrimitiveTypeDecoder<?> primitiveTypeDecoder = 
(PrimitiveTypeDecoder<?>) decoder;
+        if (decoder instanceof PrimitiveTypeDecoder primitiveTypeDecoder) {
             final int typeCode = primitiveTypeDecoder.getTypeCode();
 
             if (primitiveTypeDecoder.isJavaPrimitive()) {
@@ -275,8 +274,7 @@ public abstract class AbstractArrayTypeDecoder extends 
AbstractPrimitiveTypeDeco
     private static Object decodeAsObject(InputStream stream, 
StreamDecoderState state, int count) throws DecodeException {
         final StreamTypeDecoder<?> decoder = 
state.getDecoder().readNextTypeDecoder(stream, state);
 
-        if (decoder instanceof PrimitiveTypeDecoder) {
-            final PrimitiveTypeDecoder<?> primitiveTypeDecoder = 
(PrimitiveTypeDecoder<?>) decoder;
+        if (decoder instanceof PrimitiveTypeDecoder primitiveTypeDecoder) {
             if (primitiveTypeDecoder.isJavaPrimitive()) {
                 final Class<?> typeClass = decoder.getTypeClass();
 
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/codec/encoders/ProtonEncoder.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/codec/encoders/ProtonEncoder.java
index bdbd8ba0..430a3675 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/codec/encoders/ProtonEncoder.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/codec/encoders/ProtonEncoder.java
@@ -694,12 +694,12 @@ public final class ProtonEncoder implements Encoder {
             } else {
                 writeArray(buffer, state, (Object[]) value);
             }
-        } else if (value instanceof List) {
-            writeList(buffer, state, (List<Object>) value);
-        } else if (value instanceof Map) {
-            writeMap(buffer, state, (Map<Object, Object>) value);
-        } else if (value instanceof DescribedType) {
-            writeDescribedType(buffer, state, (DescribedType) value);
+        } else if (value instanceof List list) {
+            writeList(buffer, state, list);
+        } else if (value instanceof Map map) {
+            writeMap(buffer, state, map);
+        } else if (value instanceof DescribedType described) {
+            writeDescribedType(buffer, state, described);
         } else {
             throw new IllegalArgumentException(
                 "Do not know how to write Objects of class " + 
value.getClass().getName());
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/exceptions/ProtonExceptionSupport.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/exceptions/ProtonExceptionSupport.java
index 9b08e39b..80d36eb0 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/exceptions/ProtonExceptionSupport.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/exceptions/ProtonExceptionSupport.java
@@ -45,12 +45,12 @@ public class ProtonExceptionSupport {
      * @return an ProtonException instance.
      */
     public static EngineFailedException createFailedException(String message, 
Throwable cause) {
-        if (cause instanceof EngineFailedException) {
-            return ((EngineFailedException) cause).duplicate();
+        if (cause instanceof EngineFailedException efEx) {
+            return efEx.duplicate();
         }
 
-        if (cause.getCause() instanceof EngineFailedException) {
-            return ((EngineFailedException) cause.getCause()).duplicate();
+        if (cause.getCause() instanceof EngineFailedException efEx) {
+            return efEx.duplicate();
         }
 
         if (message == null || message.isEmpty()) {
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonConnection.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonConnection.java
index e22cee6a..a662bee0 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonConnection.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonConnection.java
@@ -699,9 +699,8 @@ public class ProtonConnection extends 
ProtonEndpoint<Connection> implements Conn
         final Symbol condition;
         final String description = cause.getMessage();
 
-        if (cause instanceof ProtocolViolationException) {
-            ProtocolViolationException error = (ProtocolViolationException) 
cause;
-            condition = error.getErrorCondition();
+        if (cause instanceof ProtocolViolationException violation) {
+            condition = violation.getErrorCondition();
         } else {
             condition = AmqpError.INTERNAL_ERROR;
         }
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonEngineConfiguration.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonEngineConfiguration.java
index 6142858b..d020a720 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonEngineConfiguration.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonEngineConfiguration.java
@@ -70,8 +70,8 @@ public class ProtonEngineConfiguration implements 
EngineConfiguration {
     @Override
     public boolean isTraceFrames() {
         EngineHandler handler = 
engine.pipeline().find(ProtonConstants.FRAME_LOGGING_HANDLER);
-        if (handler != null && handler instanceof ProtonFrameLoggingHandler) {
-            return ((ProtonFrameLoggingHandler) handler).isTraceFrames();
+        if (handler != null && handler instanceof ProtonFrameLoggingHandler 
logger) {
+            return logger.isTraceFrames();
         } else {
             return false;
         }
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonTransactionManager.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonTransactionManager.java
index 4820809c..d287659a 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonTransactionManager.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonTransactionManager.java
@@ -392,8 +392,7 @@ public final class ProtonTransactionManager extends 
ProtonEndpoint<TransactionMa
                 transaction.setState(TransactionState.DECLARING);
 
                 fireDeclare(transaction);
-            } else if (container.getValue() instanceof Discharge) {
-                Discharge discharge = (Discharge) container.getValue();
+            } else if (container.getValue() instanceof Discharge discharge) {
                 Binary txnId = discharge.getTxnId();
 
                 ProtonManagerTransaction transaction = 
transactions.get(txnId.asProtonBuffer());
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/DeliveryIdTracker.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/DeliveryIdTracker.java
index 53ab7709..07960fcb 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/DeliveryIdTracker.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/DeliveryIdTracker.java
@@ -140,12 +140,12 @@ public class DeliveryIdTracker extends Number implements 
Comparable<DeliveryIdTr
 
     @Override
     public boolean equals(Object other) {
-        if (other instanceof DeliveryIdTracker) {
-            return ((DeliveryIdTracker) other).deliveryId == this.deliveryId;
-        } else if (other instanceof SequenceNumber) {
-            return ((SequenceNumber) other).intValue() == this.deliveryId;
-        } else if (other instanceof UnsignedInteger) {
-            return ((UnsignedInteger) other).intValue() == this.deliveryId;
+        if (other instanceof DeliveryIdTracker tracker) {
+            return tracker.deliveryId == this.deliveryId;
+        } else if (other instanceof SequenceNumber sequence) {
+            return sequence.intValue() == this.deliveryId;
+        } else if (other instanceof UnsignedInteger unsigned) {
+            return unsigned.intValue() == this.deliveryId;
         }
 
         return false;
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SequenceNumber.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SequenceNumber.java
index 164334b8..b15f870f 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SequenceNumber.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SequenceNumber.java
@@ -130,8 +130,8 @@ public class SequenceNumber extends Number implements 
Comparable<SequenceNumber>
 
     @Override
     public boolean equals(Object other) {
-        if (other instanceof SequenceNumber) {
-            return ((SequenceNumber) other).sequence == this.sequence;
+        if (other instanceof SequenceNumber sequenceNo) {
+            return sequenceNo.sequence == this.sequence;
         }
 
         return false;
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SplayMap.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SplayMap.java
index c9d6ca9b..566ac6de 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SplayMap.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SplayMap.java
@@ -2344,8 +2344,7 @@ public class SplayMap<E> implements 
NavigableMap<UnsignedInteger, E> {
 
             @Override
             public boolean contains(Object o) {
-                if (o instanceof Map.Entry) {
-                    Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
+                if (o instanceof Map.Entry entry) {
                     Number key = Number.class.cast(entry.getKey());
 
                     if (!isInRange(key.intValue())) {
@@ -2364,8 +2363,7 @@ public class SplayMap<E> implements 
NavigableMap<UnsignedInteger, E> {
 
             @Override
             public boolean remove(Object o) {
-                if (o instanceof Map.Entry) {
-                    Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
+                if (o instanceof Map.Entry entry) {
                     Number key = Number.class.cast(entry.getKey());
 
                     if (!isInRange(key.intValue())) {
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/DeliveryTag.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/DeliveryTag.java
index 97531711..1986d23d 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/DeliveryTag.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/DeliveryTag.java
@@ -149,11 +149,12 @@ public interface DeliveryTag {
             if (this == other) {
                 return true;
             }
-            if (!(other instanceof DeliveryTag)) {
-                return false;
+
+            if (other instanceof DeliveryTag tag) {
+                return Arrays.equals(tagBytes, tag.tagBytes());
             }
 
-            return Arrays.equals(tagBytes, ((DeliveryTag) other).tagBytes());
+            return false;
         }
 
         @Override
diff --git a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Symbol.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Symbol.java
index f9f25c47..862118fe 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Symbol.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Symbol.java
@@ -99,8 +99,8 @@ public final class Symbol implements Comparable<Symbol> {
             return true;
         }
 
-        if (other instanceof Symbol) {
-            return underlying.equals(((Symbol) other).underlying);
+        if (other instanceof Symbol symbol) {
+            return underlying.equals(symbol.underlying);
         }
 
         return false;
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/Attach.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/Attach.java
index 04dedbf3..7ba65b37 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/Attach.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/Attach.java
@@ -292,13 +292,13 @@ public final class Attach implements Performative {
         return (T) target;
     }
 
-    public Attach setTarget(Terminus target) {
-        if (target instanceof Target) {
-            setTarget((Target) target);
-        } else if (target instanceof Coordinator) {
-            setTarget((Coordinator) target);
+    public Attach setTarget(Terminus terminus) {
+        if (terminus instanceof Target target) {
+            setTarget(target);
+        } else if (terminus instanceof Coordinator coordinator) {
+            setTarget(coordinator);
         } else {
-            throw new IllegalArgumentException("Cannot set Target terminus to 
given value: " + target);
+            throw new IllegalArgumentException("Cannot set Target terminus to 
given value: " + terminus);
         }
 
         return this;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to