Skip to content

Commit

Permalink
4.x: Replace manual casts on pattern with instanceof in helidon/messa…
Browse files Browse the repository at this point in the history
…ging modules .
  • Loading branch information
Captain1653 committed Sep 6, 2024
1 parent 2397b81 commit 6f1a9e7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,8 +35,8 @@ public void onCompletion(Message message) {
public void onException(Message message, Exception exception) {
javax.jms.Message msg = ShimUtil.message(message);

if (exception instanceof JMSException) {
delegate.onException(msg, ShimUtil.exception((JMSException) exception));
if (exception instanceof JMSException jmsException) {
delegate.onException(msg, ShimUtil.exception(jmsException));
} else {
delegate.onException(msg, exception);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
* Copyright (c) 2021, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -183,20 +183,20 @@ public static <T> T resolve(Object obj, Class<T> expectedType) {
* @return shimmed jakarta namespace instance
*/
public static Message create(javax.jms.Message delegate) {
if (delegate instanceof javax.jms.TextMessage) {
return create((javax.jms.TextMessage) delegate);
if (delegate instanceof javax.jms.TextMessage textMessage) {
return create(textMessage);
}
if (delegate instanceof javax.jms.MapMessage) {
return create((javax.jms.MapMessage) delegate);
if (delegate instanceof javax.jms.MapMessage mapMessage) {
return create(mapMessage);
}
if (delegate instanceof javax.jms.BytesMessage) {
return create((javax.jms.BytesMessage) delegate);
if (delegate instanceof javax.jms.BytesMessage bytesMessage) {
return create(bytesMessage);
}
if (delegate instanceof javax.jms.StreamMessage) {
return create((javax.jms.StreamMessage) delegate);
if (delegate instanceof javax.jms.StreamMessage streamMessage) {
return create(streamMessage);
}
if (delegate instanceof javax.jms.ObjectMessage) {
return create((javax.jms.ObjectMessage) delegate);
if (delegate instanceof javax.jms.ObjectMessage objectMessage) {
return create(objectMessage);
}
if (delegate == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,8 +33,8 @@ public void onCompletion(Message message) {

@Override
public void onException(Message message, Exception exception) {
if (exception instanceof JMSException) {
delegate.onException(JakartaJms.create(message), ShimUtil.exception(((JMSException) exception)));
if (exception instanceof JMSException jmsException) {
delegate.onException(JakartaJms.create(message), ShimUtil.exception(jmsException));
} else {
delegate.onException(JakartaJms.create(message), exception);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,29 +78,29 @@ static javax.jms.JMSException exception(JMSException source) {
}

static javax.jms.Destination destination(Destination destination) {
if (destination instanceof JakartaDestination) {
return ((JakartaDestination) destination).unwrap();
if (destination instanceof JakartaDestination jakartaDestination) {
return jakartaDestination.unwrap();
}
if (destination instanceof javax.jms.Destination) {
return (javax.jms.Destination) destination;
if (destination instanceof javax.jms.Destination javaxDestination) {
return javaxDestination;
}
throw new RuntimeException("Destination was not created correctly, cannot convert to javax.jms.Destination: "
+ destination);
}

static Topic topic(jakarta.jms.Topic topic) {
if (topic instanceof JakartaTopic) {
return ((JakartaTopic) topic).unwrap();
if (topic instanceof JakartaTopic jakartaTopic) {
return jakartaTopic.unwrap();
}
if (topic instanceof javax.jms.Topic) {
return (javax.jms.Topic) topic;
if (topic instanceof javax.jms.Topic javaxTopic) {
return javaxTopic;
}
throw new RuntimeException("Topic was not created correctly, cannot convert to javax.jms.Topic: " + topic);
}

static Queue queue(jakarta.jms.Queue queue) {
if (queue instanceof JakartaQueue) {
return ((JakartaQueue) queue).unwrap();
if (queue instanceof JakartaQueue jakartaQueue) {
return jakartaQueue.unwrap();
}
if (queue instanceof javax.jms.Topic) {
return (javax.jms.Queue) queue;
Expand All @@ -109,11 +109,11 @@ static Queue queue(jakarta.jms.Queue queue) {
}

static javax.jms.Message message(Message message) {
if (message instanceof JakartaMessage) {
return ((JakartaMessage) message).unwrap();
if (message instanceof JakartaMessage jakartaMessage) {
return jakartaMessage.unwrap();
}
if (message instanceof javax.jms.Message) {
return (javax.jms.Message) message;
if (message instanceof javax.jms.Message javaxMessage) {
return javaxMessage;
}
throw new RuntimeException("Message was not created correctly, cannot convert to javax.jms.Message: " + message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -424,10 +424,10 @@ protected JmsMessage<?> createMessage(NackHandler nackHandler,
jakarta.jms.Message message,
Executor executor,
SessionMetadata sessionMetadata) {
if (message instanceof TextMessage) {
return new JmsTextMessage(nackHandler, (TextMessage) message, executor, sessionMetadata);
} else if (message instanceof BytesMessage) {
return new JmsBytesMessage(nackHandler, (BytesMessage) message, executor, sessionMetadata);
if (message instanceof TextMessage textMessage) {
return new JmsTextMessage(nackHandler, textMessage, executor, sessionMetadata);
} else if (message instanceof BytesMessage bytesMessage) {
return new JmsBytesMessage(nackHandler, bytesMessage, executor, sessionMetadata);
} else {
return new AbstractJmsMessage<jakarta.jms.Message>(nackHandler, executor, sessionMetadata) {

Expand Down

0 comments on commit 6f1a9e7

Please sign in to comment.