Skip to content

For connections created outside the global field, use try-with-resour…#1667

Merged
jeanouii merged 4 commits intoapache:mainfrom
jeanouii:fix/amqp-leak-connections
Feb 12, 2026
Merged

For connections created outside the global field, use try-with-resour…#1667
jeanouii merged 4 commits intoapache:mainfrom
jeanouii:fix/amqp-leak-connections

Conversation

@jeanouii
Copy link
Contributor

…ces to avoid leaks

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates AMQP transport test code to ensure JMS Connection instances are reliably closed (especially on exceptions) by using try-with-resources, reducing the chance of resource leaks during test runs.

Changes:

  • Wrap JMS Connection usage in try-with-resources blocks across multiple AMQP-related test classes.
  • Remove manual close() / finally patterns made redundant by try-with-resources (including a double-close case).
  • Adjust test structure (indentation / block scoping) to keep assertions within the resource lifecycle.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 14 comments.

File Description
activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/JMSLargeMessageSendRecvTest.java Wraps per-test connection creation in try-with-resources to ensure closure.
activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/JMSInteroperabilityTest.java Wraps OpenWire/AMQP connections in try-with-resources across multiple interop tests.
activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/AmqpTransformerTest.java Wraps AMQP and OpenWire JMS connections in try-with-resources; removes redundant close logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +95 to +101
Message message = c.receive(1000);

assertTrue(message instanceof BytesMessage);
Boolean nativeTransformationUsed = message.getBooleanProperty("JMS_AMQP_NATIVE");
assertTrue("Didn't use the correct transformation, expected NATIVE", nativeTransformationUsed);
assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
assertEquals(7, message.getJMSPriority());
assertTrue(message instanceof BytesMessage);
Boolean nativeTransformationUsed = message.getBooleanProperty("JMS_AMQP_NATIVE");
assertTrue("Didn't use the correct transformation, expected NATIVE", nativeTransformationUsed);
assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
assertEquals(7, message.getJMSPriority());
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.receive(1000) can return null; assertTrue(message instanceof BytesMessage) will then fail with a generic message. Add an assertNotNull (with a helpful message) before the type assertion to make failures easier to diagnose.

Copilot uses AI. Check for mistakes.
Comment on lines +153 to +154
LOG.debug("Appclication Property not set by client: {}", propertyName);
fail("Appclication Property not set by client: " + propertyName);
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in log / failure message: "Appclication" should be "Application" (both the LOG message and fail(...) message).

Copilot uses AI. Check for mistakes.
Comment on lines +144 to +145
LOG.debug("Appclication Property set by client is: {}", propertyName);
if (!inbound.propertyExists(propertyName)) {
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in log message: "Appclication" should be "Application".

Copilot uses AI. Check for mistakes.
Comment on lines +234 to +235
LOG.debug("Appclication Property not set by client: {}", propertyName);
fail("Appclication Property not set by client: " + propertyName);
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in log / failure message: "Appclication" should be "Application" (both the LOG message and fail(...) message).

Copilot uses AI. Check for mistakes.
assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
assertEquals(7, message.getJMSPriority());
assertTrue(message instanceof BytesMessage);
Boolean nativeTransformationUsed = message.getBooleanProperty("JMS_AMQP_NATIVE");
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'nativeTransformationUsed' is only assigned values of primitive type and is never 'null', but it is declared with the boxed type 'Boolean'.

Suggested change
Boolean nativeTransformationUsed = message.getBooleanProperty("JMS_AMQP_NATIVE");
boolean nativeTransformationUsed = message.getBooleanProperty("JMS_AMQP_NATIVE");

Copilot uses AI. Check for mistakes.
assertNotNull("Should have received a message", message);
LOG.info("Recieved message: {}", message);
assertTrue(message instanceof BytesMessage);
Boolean nativeTransformationUsed = message.getBooleanProperty("JMS_AMQP_NATIVE");
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'nativeTransformationUsed' is only assigned values of primitive type and is never 'null', but it is declared with the boxed type 'Boolean'.

Suggested change
Boolean nativeTransformationUsed = message.getBooleanProperty("JMS_AMQP_NATIVE");
boolean nativeTransformationUsed = message.getBooleanProperty("JMS_AMQP_NATIVE");

Copilot uses AI. Check for mistakes.
assertFalse("Didn't use the correct transformation, expected NOT to be NATIVE", nativeTransformationUsed);
assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
assertTrue(message instanceof TextMessage);
Boolean nativeTransformationUsed = message.getBooleanProperty("JMS_AMQP_NATIVE");
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'nativeTransformationUsed' is only assigned values of primitive type and is never 'null', but it is declared with the boxed type 'Boolean'.

Suggested change
Boolean nativeTransformationUsed = message.getBooleanProperty("JMS_AMQP_NATIVE");
boolean nativeTransformationUsed = message.getBooleanProperty("JMS_AMQP_NATIVE");

Copilot uses AI. Check for mistakes.
jeanouii and others added 3 commits February 12, 2026 15:38
@jeanouii jeanouii merged commit 4809b1e into apache:main Feb 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant