diff --git a/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JakartaCompletionListener.java b/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JakartaCompletionListener.java index 27be3b8b942..aebbb353669 100644 --- a/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JakartaCompletionListener.java +++ b/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JakartaCompletionListener.java @@ -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. @@ -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); } diff --git a/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JakartaJms.java b/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JakartaJms.java index 96e4653fb6a..fd2d5ad456b 100644 --- a/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JakartaJms.java +++ b/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JakartaJms.java @@ -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. @@ -183,20 +183,20 @@ public static T resolve(Object obj, Class 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; diff --git a/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JavaxCompletionListener.java b/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JavaxCompletionListener.java index cc70db25d1c..c9fe5566d73 100644 --- a/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JavaxCompletionListener.java +++ b/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/JavaxCompletionListener.java @@ -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. @@ -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); } diff --git a/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/ShimUtil.java b/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/ShimUtil.java index 5380e00e73f..25d8dd4b082 100644 --- a/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/ShimUtil.java +++ b/messaging/connectors/jms-shim/src/main/java/io/helidon/messaging/connectors/jms/shim/ShimUtil.java @@ -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. @@ -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; @@ -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); } diff --git a/messaging/connectors/jms/src/main/java/io/helidon/messaging/connectors/jms/JmsConnector.java b/messaging/connectors/jms/src/main/java/io/helidon/messaging/connectors/jms/JmsConnector.java index f3d9ec52116..07812f31896 100644 --- a/messaging/connectors/jms/src/main/java/io/helidon/messaging/connectors/jms/JmsConnector.java +++ b/messaging/connectors/jms/src/main/java/io/helidon/messaging/connectors/jms/JmsConnector.java @@ -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. @@ -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(nackHandler, executor, sessionMetadata) {