From 65c395494252f7a2dd52eead82fd7c7481afdc3d Mon Sep 17 00:00:00 2001 From: Karan Kumar Date: Mon, 6 Mar 2023 10:42:04 +0530 Subject: [PATCH] Adding forbidden api for Properties#get() and Properties#getOrDefault() (#13882) Properties#getOrDefault method does not check the default map for values where as Properties#getProperty() does. --- codestyle/druid-forbidden-apis.txt | 2 ++ .../apache/druid/indexing/kafka/KafkaRecordSupplier.java | 2 +- .../druid/server/initialization/IndexerZkConfigTest.java | 4 ++-- .../org/apache/druid/guice/JsonConfigTesterBaseTest.java | 2 +- .../apache/druid/cli/Log4JShutdownPropertyCheckerTest.java | 6 +++--- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/codestyle/druid-forbidden-apis.txt b/codestyle/druid-forbidden-apis.txt index a99654f1212..cc55b8f2eb2 100644 --- a/codestyle/druid-forbidden-apis.txt +++ b/codestyle/druid-forbidden-apis.txt @@ -41,6 +41,8 @@ java.util.HashSet#(int, float) @ Use com.google.collect.Sets#newHashSetWit java.util.LinkedHashSet#(int) @ Use com.google.collect.Sets#newLinkedHashSatWithExpectedSize(int) instead java.util.LinkedHashSet#(int, float) @ Use com.google.collect.Sets#newLinkedHashSatWithExpectedSize(int) instead java.util.LinkedList @ Use ArrayList or ArrayDeque instead +java.util.Properties#get(java.lang.Object) @ Properties#get method does not check the default map for values. Use Properties#getProperty() instead. +java.util.Properties#getOrDefault(java.lang.Object,java.lang.Object) @ Properties#getOrDefault method does not check the default map for values. Use Properties#getProperty() instead. java.util.Random#() @ Use ThreadLocalRandom.current() or the constructor with a seed (the latter in tests only!) java.lang.Math#random() @ Use ThreadLocalRandom.current() java.util.regex.Pattern#matches(java.lang.String,java.lang.CharSequence) @ Use String.startsWith(), endsWith(), contains(), or compile and cache a Pattern explicitly diff --git a/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/KafkaRecordSupplier.java b/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/KafkaRecordSupplier.java index 255250d9243..eb3833a0b69 100644 --- a/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/KafkaRecordSupplier.java +++ b/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/KafkaRecordSupplier.java @@ -262,7 +262,7 @@ public class KafkaRecordSupplier implements RecordSupplier configs = new HashMap<>(); for (String key : properties.stringPropertyNames()) { - configs.put(key, properties.get(key)); + configs.put(key, properties.getProperty(key)); } deserializerObject.configure(configs, isKey); diff --git a/indexing-service/src/test/java/org/apache/druid/server/initialization/IndexerZkConfigTest.java b/indexing-service/src/test/java/org/apache/druid/server/initialization/IndexerZkConfigTest.java index e2f4a837e03..8ae8217e491 100644 --- a/indexing-service/src/test/java/org/apache/druid/server/initialization/IndexerZkConfigTest.java +++ b/indexing-service/src/test/java/org/apache/druid/server/initialization/IndexerZkConfigTest.java @@ -109,7 +109,7 @@ public class IndexerZkConfigTest field.getName().substring(1) ); Method method = ZkPathsConfig.class.getDeclaredMethod(getter); - Assert.assertEquals(propertyValues.get(property), method.invoke(zkPathsConfig)); + Assert.assertEquals(propertyValues.getProperty(property), method.invoke(zkPathsConfig)); ++assertions; } } @@ -127,7 +127,7 @@ public class IndexerZkConfigTest field.getName().substring(1) ); Method method = IndexerZkConfig.class.getDeclaredMethod(getter); - Assert.assertEquals(propertyValues.get(property), method.invoke(indexerZkConfig)); + Assert.assertEquals(propertyValues.getProperty(property), method.invoke(indexerZkConfig)); ++assertions; } } diff --git a/server/src/test/java/org/apache/druid/guice/JsonConfigTesterBaseTest.java b/server/src/test/java/org/apache/druid/guice/JsonConfigTesterBaseTest.java index 89cabf8c5f4..8107c2b59bd 100644 --- a/server/src/test/java/org/apache/druid/guice/JsonConfigTesterBaseTest.java +++ b/server/src/test/java/org/apache/druid/guice/JsonConfigTesterBaseTest.java @@ -43,7 +43,7 @@ public final class JsonConfigTesterBaseTest Assert.assertEquals("[]", testProperties.getProperty("druid.test.prefix.set")); Assert.assertEquals("{}", testProperties.getProperty("druid.test.prefix.map")); for (Map.Entry entry : System.getProperties().entrySet()) { - Assert.assertEquals(entry.getValue(), testProperties.get(entry.getKey())); + Assert.assertEquals(entry.getValue(), testProperties.getProperty(String.valueOf(entry.getKey()))); } } diff --git a/services/src/test/java/org/apache/druid/cli/Log4JShutdownPropertyCheckerTest.java b/services/src/test/java/org/apache/druid/cli/Log4JShutdownPropertyCheckerTest.java index a3fff7cb4c8..415e91558c3 100644 --- a/services/src/test/java/org/apache/druid/cli/Log4JShutdownPropertyCheckerTest.java +++ b/services/src/test/java/org/apache/druid/cli/Log4JShutdownPropertyCheckerTest.java @@ -35,9 +35,9 @@ public class Log4JShutdownPropertyCheckerTest Assert.assertEquals( "org.apache.druid.common.config.Log4jShutdown", - properties.get("log4j.shutdownCallbackRegistry") + properties.getProperty("log4j.shutdownCallbackRegistry") ); - Assert.assertEquals("true", properties.get("log4j.shutdownHookEnabled")); - Assert.assertEquals("false", properties.get("log4j2.is.webapp")); + Assert.assertEquals("true", properties.getProperty("log4j.shutdownHookEnabled")); + Assert.assertEquals("false", properties.getProperty("log4j2.is.webapp")); } }