You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/03/30 18:44:01 UTC

[camel] branch main updated: removed unused assignments. Sometimes it allows removing related blocks (#9711)

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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new cd511ec61f5 removed unused assignments. Sometimes it allows removing related blocks (#9711)
cd511ec61f5 is described below

commit cd511ec61f579bfebd1e1031bed38e4c1aa1c72d
Author: dk2k <dk...@users.noreply.github.com>
AuthorDate: Thu Mar 30 21:43:51 2023 +0300

    removed unused assignments. Sometimes it allows removing related blocks (#9711)
    
    * removed unused assignments. Sometimes it allows removing related blocks of code
    
    * removed unused class SjmsConnectionTestSupport
    
    ---------
    
    Co-authored-by: dk2k <dk...@ya.ru>
---
 .../arangodb/integration/ArangoGraphQueriesIT.java |   1 -
 .../camel/component/as2/api/util/AS2Utils.java     |   2 +-
 .../avro/processors/ReflectionInOutProcessor.java  |   5 +-
 .../camel/dataformat/bindy/BindyCsvFactory.java    |   2 +-
 .../aggregate/Etcd3AggregationRepository.java      |   2 +-
 .../storage/localstorage/FakeStorageRpc.java       |   4 -
 .../apache/camel/component/ironmq/GsonUtil.java    |   5 +-
 .../conf/ConnectionParamsConfiguration.java        |   2 +-
 .../http/JettyCustomPlatformHttpConsumer.java      |   2 +-
 .../sjms/support/SjmsConnectionTestSupport.java    | 107 ---------------------
 .../component/smpp/SmppConnectionFactory.java      |   6 +-
 .../thrift/impl/CalculatorSyncServerImpl.java      |   2 +-
 12 files changed, 13 insertions(+), 127 deletions(-)

diff --git a/components/camel-arangodb/src/test/java/org/apache/camel/component/arangodb/integration/ArangoGraphQueriesIT.java b/components/camel-arangodb/src/test/java/org/apache/camel/component/arangodb/integration/ArangoGraphQueriesIT.java
index a77a966cefd..efd1229d565 100644
--- a/components/camel-arangodb/src/test/java/org/apache/camel/component/arangodb/integration/ArangoGraphQueriesIT.java
+++ b/components/camel-arangodb/src/test/java/org/apache/camel/component/arangodb/integration/ArangoGraphQueriesIT.java
@@ -81,7 +81,6 @@ public class ArangoGraphQueriesIT extends BaseGraph {
         assertTrue(result.getMessage().getBody() instanceof Collection);
 
         Collection<String> list = (Collection<String>) result.getMessage().getBody();
-        list = (Collection<String>) result.getMessage().getBody();
         assertEquals(3, list.size());
         assertThat(list, hasItems("A", "B", "D"));
 
diff --git a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/AS2Utils.java b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/AS2Utils.java
index 87fc0a34dfc..67454e94634 100644
--- a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/AS2Utils.java
+++ b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/AS2Utils.java
@@ -69,7 +69,7 @@ public final class AS2Utils {
         Matcher matcher = AS_NAME_PATTERN.matcher(name);
         if (!matcher.matches()) {
             // if name does not match, determine where it fails to match.
-            int i = 0;
+            int i;
             for (i = name.length() - 1; i > 0; i--) {
                 Matcher region = matcher.region(0, i);
                 if (region.matches() || region.hitEnd()) {
diff --git a/components/camel-avro-rpc/camel-avro-rpc-component/src/test/java/org/apache/camel/component/avro/processors/ReflectionInOutProcessor.java b/components/camel-avro-rpc/camel-avro-rpc-component/src/test/java/org/apache/camel/component/avro/processors/ReflectionInOutProcessor.java
index c86ad8e92cc..fed84f71d1c 100644
--- a/components/camel-avro-rpc/camel-avro-rpc-component/src/test/java/org/apache/camel/component/avro/processors/ReflectionInOutProcessor.java
+++ b/components/camel-avro-rpc/camel-avro-rpc-component/src/test/java/org/apache/camel/component/avro/processors/ReflectionInOutProcessor.java
@@ -19,11 +19,10 @@ package org.apache.camel.component.avro.processors;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.avro.test.TestReflection;
-import org.apache.camel.avro.test.TestReflectionImpl;
 
 public class ReflectionInOutProcessor implements Processor {
 
-    private TestReflection testReflection = new TestReflectionImpl();
+    private TestReflection testReflection;
 
     public ReflectionInOutProcessor(TestReflection testReflection) {
         this.testReflection = testReflection;
@@ -34,7 +33,7 @@ public class ReflectionInOutProcessor implements Processor {
         Object body = exchange.getIn().getBody();
         if (body instanceof Object[] && ((Object[]) body).length == 0) {
             exchange.getMessage().setBody(testReflection.getTestPojo());
-        } else if (body instanceof Object) {
+        } else if (body != null) {
             exchange.getMessage().setBody(testReflection.increaseAge((Integer) body));
         }
     }
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
index 1949ae7d5ba..58c895c2a55 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
@@ -418,7 +418,7 @@ public class BindyCsvFactory extends BindyAbstractFactory implements BindyFactor
         List<List<String>> product = new ArrayList<>();
 
         int idx = 0;
-        int idxSize = 0;
+        int idxSize;
         do {
             idxSize = 0;
             List<String> v = new ArrayList<>();
diff --git a/components/camel-etcd3/src/main/java/org/apache/camel/component/etcd3/processor/aggregate/Etcd3AggregationRepository.java b/components/camel-etcd3/src/main/java/org/apache/camel/component/etcd3/processor/aggregate/Etcd3AggregationRepository.java
index 0e80b729862..aad0e2fcd10 100644
--- a/components/camel-etcd3/src/main/java/org/apache/camel/component/etcd3/processor/aggregate/Etcd3AggregationRepository.java
+++ b/components/camel-etcd3/src/main/java/org/apache/camel/component/etcd3/processor/aggregate/Etcd3AggregationRepository.java
@@ -452,7 +452,7 @@ public class Etcd3AggregationRepository extends ServiceSupport
     public Set<String> getKeys() {
         CompletableFuture<GetResponse> completableGetResponse = kvClient.get(ByteSequence.from(prefixName.getBytes()),
                 GetOption.newBuilder().withRange(ByteSequence.from(prefixName.getBytes())).build());
-        Set<String> scanned = Collections.unmodifiableSet(new TreeSet<>());
+        Set<String> scanned;
         try {
             GetResponse getResponse = completableGetResponse.get();
             Set<String> keys = new TreeSet<>();
diff --git a/components/camel-google/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/localstorage/FakeStorageRpc.java b/components/camel-google/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/localstorage/FakeStorageRpc.java
index 75794919da8..53f518b2315 100644
--- a/components/camel-google/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/localstorage/FakeStorageRpc.java
+++ b/components/camel-google/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/localstorage/FakeStorageRpc.java
@@ -142,10 +142,6 @@ class FakeStorageRpc extends StorageRpcTestBase {
                     pageToken = (String) e.getValue();
                     break;
                 case PREFIX:
-                    preprefix = (String) e.getValue();
-                    if (preprefix.startsWith("/")) {
-                        preprefix = preprefix.substring(1);
-                    }
                     break;
                 case DELIMITER:
                     //delimiter = (String) e.getValue();
diff --git a/components/camel-ironmq/src/main/java/org/apache/camel/component/ironmq/GsonUtil.java b/components/camel-ironmq/src/main/java/org/apache/camel/component/ironmq/GsonUtil.java
index 95659a6d019..bd287a39439 100644
--- a/components/camel-ironmq/src/main/java/org/apache/camel/component/ironmq/GsonUtil.java
+++ b/components/camel-ironmq/src/main/java/org/apache/camel/component/ironmq/GsonUtil.java
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.component.ironmq;
 
-import java.util.HashMap;
 import java.util.Map;
 
 import com.google.gson.Gson;
@@ -29,8 +28,8 @@ public final class GsonUtil {
     }
 
     static class IronMqMessage {
-        private Map<String, Object> headers = new HashMap<>();
-        private String body;
+        private Map<String, Object> headers;
+        private final String body;
 
         IronMqMessage(String body, Map<String, Object> headers) {
             this.headers = headers;
diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/conf/ConnectionParamsConfiguration.java b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/conf/ConnectionParamsConfiguration.java
index c6714628ddb..1999c21fd04 100644
--- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/conf/ConnectionParamsConfiguration.java
+++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/conf/ConnectionParamsConfiguration.java
@@ -20,7 +20,7 @@ import java.util.Map;
 
 public class ConnectionParamsConfiguration {
 
-    private String host = "localhost:27017";
+    private String host;
     private String user;
     private String password;
     private String adminDB = "admin";
diff --git a/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyCustomPlatformHttpConsumer.java b/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyCustomPlatformHttpConsumer.java
index 56de9a983be..f83211f3e78 100644
--- a/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyCustomPlatformHttpConsumer.java
+++ b/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyCustomPlatformHttpConsumer.java
@@ -74,7 +74,7 @@ public class JettyCustomPlatformHttpConsumer extends DefaultConsumer {
                 try {
                     BufferedReader reader = httpServletRequest.getReader();
                     String bodyRequest = "";
-                    String strCurrentLine = "";
+                    String strCurrentLine;
                     while ((strCurrentLine = reader.readLine()) != null) {
                         bodyRequest += strCurrentLine;
                     }
diff --git a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/support/SjmsConnectionTestSupport.java b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/support/SjmsConnectionTestSupport.java
deleted file mode 100644
index 188fb8946a2..00000000000
--- a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/support/SjmsConnectionTestSupport.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.sjms.support;
-
-import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
-import org.apache.camel.util.ObjectHelper;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class SjmsConnectionTestSupport {
-
-    static {
-        System.setProperty("org.apache.activemq.default.directory.prefix", "target/activemq/");
-    }
-
-    public static final String VM_BROKER_CONNECT_STRING = "vm://broker";
-    public static final String TCP_BROKER_CONNECT_STRING = "tcp://localhost:61616";
-    protected Logger logger = LoggerFactory.getLogger(getClass());
-    private ActiveMQConnectionFactory vmTestConnectionFactory;
-    private ActiveMQConnectionFactory testConnectionFactory;
-    //    private BrokerService brokerService;
-    private boolean persistenceEnabled;
-
-    public abstract String getConnectionUri();
-
-    @BeforeAll
-    public static void setUpBeforeClass() {
-    }
-
-    @AfterAll
-    public static void tearDownAfterClass() {
-    }
-
-    @BeforeEach
-    public void setup() throws Exception {
-        if (ObjectHelper.isEmpty(getConnectionUri())
-                || getConnectionUri().startsWith("vm")) {
-            vmTestConnectionFactory = new ActiveMQConnectionFactory(
-                    VM_BROKER_CONNECT_STRING);
-        } else {
-            createBroker();
-        }
-    }
-
-    @AfterEach
-    public void teardown() throws Exception {
-
-        if (vmTestConnectionFactory != null) {
-            vmTestConnectionFactory = null;
-        }
-        if (testConnectionFactory != null) {
-            testConnectionFactory = null;
-        }
-    }
-
-    public ActiveMQConnectionFactory createTestConnectionFactory(String uri) {
-        ActiveMQConnectionFactory cf = null;
-        if (ObjectHelper.isEmpty(uri)) {
-            cf = new ActiveMQConnectionFactory(VM_BROKER_CONNECT_STRING);
-        } else {
-            cf = new ActiveMQConnectionFactory(uri);
-        }
-        return cf;
-    }
-
-    protected void createBroker() throws Exception {
-        String connectString = getConnectionUri();
-        if (ObjectHelper.isEmpty(connectString)) {
-            connectString = TCP_BROKER_CONNECT_STRING;
-        }
-    }
-
-    public void setTestConnectionFactory(
-            ActiveMQConnectionFactory testConnectionFactory) {
-        this.testConnectionFactory = testConnectionFactory;
-    }
-
-    public ActiveMQConnectionFactory getTestConnectionFactory() {
-        return testConnectionFactory;
-    }
-
-    public void setPersistenceEnabled(boolean persistenceEnabled) {
-        this.persistenceEnabled = persistenceEnabled;
-    }
-
-    public boolean isPersistenceEnabled() {
-        return persistenceEnabled;
-    }
-}
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConnectionFactory.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConnectionFactory.java
index 756acf6818b..9b401610411 100644
--- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConnectionFactory.java
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConnectionFactory.java
@@ -70,7 +70,7 @@ import org.jsmpp.session.connection.socket.SocketConnection;
  * A Jsmpp ConnectionFactory that creates SSL Sockets.
  */
 public final class SmppConnectionFactory implements ConnectionFactory {
-    private SmppConfiguration config;
+    private final SmppConfiguration config;
 
     private SmppConnectionFactory(SmppConfiguration config) {
         this.config = config;
@@ -153,8 +153,8 @@ public final class SmppConnectionFactory implements ConnectionFactory {
             if (response == null) {
                 throw new RuntimeCamelException("Empty response to CONNECT request to host " + host + ":" + port);
             }
-            String reason = "Unknown reason";
-            int code = -1;
+            String reason;
+            int code;
             try {
                 ch = response.indexOf(' ');
                 int bar = response.indexOf(' ', ch + 1);
diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorSyncServerImpl.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorSyncServerImpl.java
index 127f6221769..7cb1aefe3cf 100644
--- a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorSyncServerImpl.java
+++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorSyncServerImpl.java
@@ -42,7 +42,7 @@ public class CalculatorSyncServerImpl implements Calculator.Iface {
 
     @Override
     public int calculate(int logId, Work work) throws TException {
-        int val = 0;
+        int val;
         switch (work.op) {
             case ADD:
                 val = work.num1 + work.num2;