This is an automated email from the ASF dual-hosted git repository.
terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 52b2bf79a63 Fixes code inspections on agent module (#38760)
52b2bf79a63 is described below
commit 52b2bf79a63fa31637fb325acd32d2fa73aabf4b
Author: Liang Zhang <[email protected]>
AuthorDate: Sat May 30 17:09:04 2026 +0800
Fixes code inspections on agent module (#38760)
---
agent/README.md | 6 +++---
.../core/advisor/executor/type/ConstructorAdviceExecutorTest.java | 2 +-
.../advisor/executor/type/InstanceMethodAdviceExecutorTest.java | 2 +-
.../shardingsphere/agent/core/builder/AgentBuilderFactoryTest.java | 6 +++---
.../config/yaml/loader/YamlPluginConfigurationLoaderTest.java | 3 +--
.../config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java | 7 ++-----
.../core/config/validator/PluginConfigurationValidatorTest.java | 3 ++-
.../collector/type/PrometheusMetricsHistogramCollectorTest.java | 2 +-
src/resources/idea/inspections.xml | 5 -----
9 files changed, 14 insertions(+), 22 deletions(-)
diff --git a/agent/README.md b/agent/README.md
index 8a6dbec7d2b..5022996d68c 100644
--- a/agent/README.md
+++ b/agent/README.md
@@ -7,17 +7,17 @@ ShardingSphere-Agent module provides an observable framework
for ShardingSphere,
### Logging
The logging plugin uses to record logs of ShardingSphere.
-Supports for File.
+Support for File.
### Metrics
The metrics plugin uses to collect and expose monitoring metrics.
-Supports for prometheus.
+Support for prometheus.
### Tracing
The tracing plugin uses to obtain the link trace information of SQL parsing
and SQL execution.
-Supports for OpenTelemetry.
+Support for OpenTelemetry.
## How To Build
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/executor/type/ConstructorAdviceExecutorTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/executor/type/ConstructorAdviceExecutorTest.java
index 50bd2b9cefd..97a6253e41a 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/executor/type/ConstructorAdviceExecutorTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/executor/type/ConstructorAdviceExecutorTest.java
@@ -59,7 +59,7 @@ class ConstructorAdviceExecutorTest {
assertDoesNotThrow(() -> executor.advice(new
SimpleTargetAdviceObject(), new Object[]{new LinkedList<>()}));
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Test
void assertIntercept() {
Builder<?> builder = mock(Builder.class);
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutorTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutorTest.java
index c7b84b0e18d..2765d1d4cf5 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutorTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutorTest.java
@@ -142,7 +142,7 @@ class InstanceMethodAdviceExecutorTest {
assertThat(queue, is(Arrays.asList("first before foo", "second before
bar", "origin call")));
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Test
void assertIntercept() {
Builder<?> builder = mock(Builder.class);
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactoryTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactoryTest.java
index 472369c1789..0b15af44f33 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactoryTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactoryTest.java
@@ -51,7 +51,7 @@ class AgentBuilderFactoryTest {
@BeforeAll
static void setup() {
ByteBuddyAgent.install();
- AdvisorConfiguration advisorConfig =
createAdvisorConfiguration(TARGET_CLASS_NAME);
+ AdvisorConfiguration advisorConfig = createAdvisorConfiguration();
Map<String, AdvisorConfiguration> advisorConfigs =
Collections.singletonMap(advisorConfig.getTargetClassName(), advisorConfig);
AgentBuilder agentBuilder =
AgentBuilderFactory.create(Collections.emptyMap(), Collections.emptyList(),
advisorConfigs, true);
agent = agentBuilder.installOnByteBuddyAgent();
@@ -62,8 +62,8 @@ class AgentBuilderFactoryTest {
.getLoaded();
}
- private static AdvisorConfiguration createAdvisorConfiguration(final
String targetClassName) {
- AdvisorConfiguration result = new
AdvisorConfiguration(targetClassName);
+ private static AdvisorConfiguration createAdvisorConfiguration() {
+ AdvisorConfiguration result = new
AdvisorConfiguration(TARGET_CLASS_NAME);
result.getAdvisors().add(new
MethodAdvisorConfiguration(ElementMatchers.isConstructor().and(ElementMatchers.takesArguments(1)),
FooAdvice.class.getName(), "FIXTURE"));
result.getAdvisors().add(new
MethodAdvisorConfiguration(ElementMatchers.isConstructor().and(ElementMatchers.takesArguments(1)),
BarAdvice.class.getName(), "FIXTURE"));
result.getAdvisors().add(new
MethodAdvisorConfiguration(ElementMatchers.named("call"),
FooAdvice.class.getName(), "FIXTURE"));
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/loader/YamlPluginConfigurationLoaderTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/loader/YamlPluginConfigurationLoaderTest.java
index 29e6e42f9c0..40effbeede3 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/loader/YamlPluginConfigurationLoaderTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/loader/YamlPluginConfigurationLoaderTest.java
@@ -38,8 +38,7 @@ class YamlPluginConfigurationLoaderTest {
@Test
void assertLoad(@TempDir final Path tempDir) throws IOException {
Path yamlFile = tempDir.resolve("agent.yaml");
- String yamlContent = ""
- + "plugins:\n"
+ String yamlContent = "plugins:\n"
+ " logging:\n"
+ " FILE:\n"
+ " host: localhost\n"
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
index 38dab75c8e8..00182a0b76f 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
@@ -30,14 +30,13 @@ import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.file.Files;
-import java.util.LinkedHashMap;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
-import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -102,9 +101,7 @@ class YamlPluginsConfigurationSwapperTest {
@Test
void assertSwapWithNullPluginConfigurationValue() {
YamlPluginCategoryConfiguration yamlPluginCategoryConfig = new
YamlPluginCategoryConfiguration();
- Map<String, YamlPluginConfiguration> logging = new LinkedHashMap<>();
- logging.put("log_fixture", null);
- yamlPluginCategoryConfig.setLogging(logging);
+
yamlPluginCategoryConfig.setLogging(Collections.singletonMap("log_fixture",
null));
YamlAgentConfiguration yamlAgentConfig = new YamlAgentConfiguration();
yamlAgentConfig.setPlugins(yamlPluginCategoryConfig);
Map<String, PluginConfiguration> actual =
YamlPluginsConfigurationSwapper.swap(yamlAgentConfig);
diff --git
a/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/config/validator/PluginConfigurationValidatorTest.java
b/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/config/validator/PluginConfigurationValidatorTest.java
index d0f05755d44..9cbda72cc56 100644
---
a/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/config/validator/PluginConfigurationValidatorTest.java
+++
b/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/config/validator/PluginConfigurationValidatorTest.java
@@ -20,13 +20,14 @@ package
org.apache.shardingsphere.agent.plugin.core.config.validator;
import org.apache.shardingsphere.agent.api.PluginConfiguration;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
class PluginConfigurationValidatorTest {
@Test
void assertValidateHostAndPortSuccess() {
- PluginConfigurationValidator.validateHostAndPort("foo_type", new
PluginConfiguration("localhost", 8080, "pwd", null));
+ assertDoesNotThrow(() ->
PluginConfigurationValidator.validateHostAndPort("foo_type", new
PluginConfiguration("localhost", 8080, "pwd", null)));
}
@Test
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusMetricsHistogramCollectorTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusMetricsHistogramCollectorTest.java
index 049654ef27c..84f87c20ea4 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusMetricsHistogramCollectorTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusMetricsHistogramCollectorTest.java
@@ -42,7 +42,7 @@ class PrometheusMetricsHistogramCollectorTest {
MetricCollectorType.HISTOGRAM, "foo_help",
Collections.emptyList(), Collections.emptyMap()));
collector.observe(1D);
Histogram histogram = (Histogram)
Plugins.getMemberAccessor().get(PrometheusMetricsHistogramCollector.class.getDeclaredField("histogram"),
collector);
- assertThat(histogram.collect().get(0).samples.stream().filter(sample
-> sample.name.endsWith("_count")).findFirst().get().value, is(1D));
+ assertThat(histogram.collect().get(0).samples.stream().filter(sample
-> sample.name.endsWith("_count")).findFirst().map(optional ->
optional.value).orElse(0D), is(1D));
}
@Test
diff --git a/src/resources/idea/inspections.xml
b/src/resources/idea/inspections.xml
index 777c25fec50..05cf99f8ec3 100644
--- a/src/resources/idea/inspections.xml
+++ b/src/resources/idea/inspections.xml
@@ -145,7 +145,6 @@
<inspection_tool class="DoubleLiteralMayBeFloatLiteral" enabled="true"
level="WARNING" enabled_by_default="true" />
<inspection_tool class="DuplicateExpressions" enabled="false" level="WEAK
WARNING" enabled_by_default="false" />
<inspection_tool class="DuplicatedBeanNamesInspection" enabled="false"
level="WARNING" enabled_by_default="false" />
- <inspection_tool class="DynamicRegexReplaceableByCompiledPattern"
enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="EmptyClass" enabled="true" level="WARNING"
enabled_by_default="true">
<option name="ignorableAnnotations">
<value />
@@ -215,7 +214,6 @@
<inspection_tool
class="GroovyUnsynchronizedMethodOverridesSynchronizedMethod" enabled="false"
level="WARNING" enabled_by_default="false" />
<inspection_tool class="GroovyUnusedAssignment" enabled="false"
level="WARNING" enabled_by_default="false" />
<inspection_tool class="GroovyUnusedIncOrDec" enabled="false"
level="WARNING" enabled_by_default="false" />
- <inspection_tool class="HardcodedLineSeparators" enabled="true"
level="WARNING" enabled_by_default="true" />
<inspection_tool class="HasPlatformType" enabled="false" level="WEAK
WARNING" enabled_by_default="false" />
<inspection_tool class="HashCodeUsesNonFinalVariable" enabled="true"
level="WARNING" enabled_by_default="true" />
<inspection_tool class="HtmlExtraClosingTag" enabled="false" level="WARNING"
enabled_by_default="false" />
@@ -242,9 +240,6 @@
<inspection_tool class="InjectionValueTypeInspection" enabled="false"
level="ERROR" enabled_by_default="false" />
<inspection_tool class="InnerClassReferencedViaSubclass" enabled="true"
level="WARNING" enabled_by_default="true" />
<inspection_tool class="InstanceofCatchParameter" enabled="true"
level="WARNING" enabled_by_default="true" />
- <inspection_tool class="InstanceofChain" enabled="true" level="WARNING"
enabled_by_default="true">
- <option name="ignoreInstanceofOnLibraryClasses" value="false" />
- </inspection_tool>
<inspection_tool class="InstanceofThis" enabled="true" level="WARNING"
enabled_by_default="true" />
<inspection_tool class="IntLiteralMayBeLongLiteral" enabled="true"
level="WARNING" enabled_by_default="true" />
<inspection_tool class="IntroduceWhenSubject" enabled="false" level="WEAK
WARNING" enabled_by_default="false" />