You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cs...@apache.org on 2019/07/02 14:08:12 UTC

[sling-org-apache-sling-distribution-journal-kafka] branch master updated: SLING-8554 - Use try with resources instead of try final

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

cschneider pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal-kafka.git


The following commit(s) were added to refs/heads/master by this push:
     new a373be3  SLING-8554 - Use try with resources instead of try final
a373be3 is described below

commit a373be302a3a9745b73ea39999f19c5a902b2cb3
Author: Christian Schneider <cs...@adobe.com>
AuthorDate: Tue Jul 2 16:08:01 2019 +0200

    SLING-8554 - Use try with resources instead of try final
---
 .../sling/distribution/journal/kafka/KafkaClientProvider.java      | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/sling/distribution/journal/kafka/KafkaClientProvider.java b/src/main/java/org/apache/sling/distribution/journal/kafka/KafkaClientProvider.java
index 61c8173..f30c7e4 100644
--- a/src/main/java/org/apache/sling/distribution/journal/kafka/KafkaClientProvider.java
+++ b/src/main/java/org/apache/sling/distribution/journal/kafka/KafkaClientProvider.java
@@ -225,14 +225,9 @@ public class KafkaClientProvider implements MessagingProvider, Closeable {
     @Nonnull
     private synchronized KafkaProducer<String, byte[]> buildKafkaProducer() {
         if (rawProducer == null) {
-            ClassLoader oldClassloader = Thread.currentThread().getContextClassLoader();
-            Thread.currentThread().setContextClassLoader(KafkaProducer.class.getClassLoader());
-            try {
+            try (CLSwitch switcher = new CLSwitch(KafkaProducer.class.getClassLoader())) {
                 rawProducer = new KafkaProducer<>(producerConfig(ByteArraySerializer.class));
-            } finally {
-                Thread.currentThread().setContextClassLoader(oldClassloader);
             }
-
             rawProducer = new KafkaProducer<>(producerConfig(ByteArraySerializer.class));
         }
         return rawProducer;