Skip to content

Commit 6a96950

Browse files
apply CS:UnusedLocalVariable
1 parent 75329e6 commit 6a96950

File tree

10 files changed

+62
-97
lines changed

10 files changed

+62
-97
lines changed

.editorconfig

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
root = true
22

3-
[*.{adoc,bat,groovy,html,java,js,jsp,kt,kts,md,properties,py,rb,sh,sql,svg,txt,xml,xsd}]
3+
[*]
44
charset = utf-8
5+
end_of_line = lf
6+
indent_style = space
7+
insert_final_newline = true
58

69
[*.{groovy,java,kt,kts,xml,xsd}]
710
indent_style = tab
811
indent_size = 4
9-
continuation_indent_size = 8
10-
end_of_line = lf
12+
ij_continuation_indent_size = 8
13+
14+
[*.java]
15+
ij_java_class_count_to_use_import_on_demand = 999
16+
ij_java_names_count_to_use_import_on_demand = 999
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
2-
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
2+
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
3+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
34
<module name="Checker">
4-
55
<!-- Root Checks -->
66
<module name="io.spring.javaformat.checkstyle.check.SpringHeaderCheck">
77
<property name="fileExtensions" value="java"/>
@@ -10,17 +10,17 @@
1010
<property name="packageInfoHeaderType" value="none"/>
1111
</module>
1212
<module name="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"/>
13-
1413
<!-- TreeWalker Checks -->
1514
<module name="TreeWalker">
16-
1715
<!-- Imports -->
1816
<module name="AvoidStarImport"/>
1917
<module name="UnusedImports"/>
2018
<module name="RedundantImport"/>
2119
<!-- Modifiers -->
2220
<module name="com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck"/>
23-
21+
<!-- Best Practice -->
22+
<module name="EmptyStatement"/>
23+
<module name="UnusedLocalVariable"/>
24+
<module name="VariableDeclarationUsageDistance"/>
2425
</module>
25-
2626
</module>

integration-tests/src/test/java/org/springframework/aot/test/ReflectionInvocationsTests.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import org.springframework.aot.hint.RuntimeHints;
2222
import org.springframework.aot.test.agent.EnabledIfRuntimeHintsAgent;
23-
import org.springframework.aot.test.agent.RuntimeHintsInvocations;
23+
import org.springframework.aot.test.agent.RuntimeHintsRecorder;
2424

2525
import static org.assertj.core.api.Assertions.assertThat;
2626

@@ -34,23 +34,22 @@ void sampleTest() {
3434
RuntimeHints hints = new RuntimeHints();
3535
hints.reflection().registerType(String.class);
3636

37-
RuntimeHintsInvocations invocations = org.springframework.aot.test.agent.RuntimeHintsRecorder.record(() -> {
37+
assertThat(RuntimeHintsRecorder.record(() -> {
3838
SampleReflection sample = new SampleReflection();
39-
sample.sample(); // does Method[] methods = String.class.getMethods();
40-
});
41-
assertThat(invocations).match(hints);
39+
sample.sample(); // String.class.getMethods();
40+
})).match(hints);
4241
}
4342

4443
@Test
4544
void multipleCallsTest() {
4645
RuntimeHints hints = new RuntimeHints();
4746
hints.reflection().registerType(String.class);
4847
hints.reflection().registerType(Integer.class);
49-
RuntimeHintsInvocations invocations = org.springframework.aot.test.agent.RuntimeHintsRecorder.record(() -> {
48+
49+
assertThat(RuntimeHintsRecorder.record(() -> {
5050
SampleReflection sample = new SampleReflection();
51-
sample.multipleCalls(); // does Method[] methods = String.class.getMethods(); methods = Integer.class.getMethods();
52-
});
53-
assertThat(invocations).match(hints);
51+
sample.multipleCalls(); // String.class.getMethods(); Integer.class.getMethods();
52+
})).match(hints);
5453
}
5554

5655
}

integration-tests/src/test/java/org/springframework/aot/test/SampleReflection.java

+3-9
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,19 @@
1616

1717
package org.springframework.aot.test;
1818

19-
import java.lang.reflect.Method;
20-
2119
/**
2220
* @author Brian Clozel
2321
* @since 6.0
2422
*/
2523
public class SampleReflection {
2624

27-
@SuppressWarnings("unused")
2825
public void sample() {
29-
String value = "Sample";
30-
Method[] methods = String.class.getMethods();
26+
String.class.getMethods();
3127
}
3228

33-
@SuppressWarnings("unused")
3429
public void multipleCalls() {
35-
String value = "Sample";
36-
Method[] methods = String.class.getMethods();
37-
methods = Integer.class.getMethods();
30+
String.class.getMethods();
31+
Integer.class.getMethods();
3832
}
3933

4034
}

spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java

+5-30
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,11 @@ void testStringArgGetter() throws Exception {
123123
.addPropertyValue("serviceLocatorInterface", TestServiceLocator2.class)
124124
.getBeanDefinition());
125125

126-
// test string-arg getter with null id
127-
TestServiceLocator2 factory = (TestServiceLocator2) bf.getBean("factory");
128-
129-
@SuppressWarnings("unused")
130-
TestService testBean = factory.getTestService(null);
131-
// now test with explicit id
132-
testBean = factory.getTestService("testService");
133-
// now verify failure on bad id
134-
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
135-
factory.getTestService("bogusTestService"));
126+
final var factory = (TestServiceLocator2) bf.getBean("factory"); // test string-arg getter
127+
factory.getTestService(null); // with null id
128+
factory.getTestService("testService"); // test with explicit id
129+
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
130+
.isThrownBy(() -> factory.getTestService("bogusTestService")); // verify failure on bad id
136131
}
137132

138133
@Disabled @Test // worked when using an ApplicationContext (see commented), fails when using BeanFactory
@@ -145,14 +140,6 @@ public void testCombinedLocatorInterface() {
145140
.addPropertyValue("serviceLocatorInterface", TestServiceLocator3.class)
146141
.getBeanDefinition());
147142

148-
// StaticApplicationContext ctx = new StaticApplicationContext();
149-
// ctx.registerPrototype("testService", TestService.class, new MutablePropertyValues());
150-
// ctx.registerAlias("testService", "1");
151-
// MutablePropertyValues mpv = new MutablePropertyValues();
152-
// mpv.addPropertyValue("serviceLocatorInterface", TestServiceLocator3.class);
153-
// ctx.registerSingleton("factory", ServiceLocatorFactoryBean.class, mpv);
154-
// ctx.refresh();
155-
156143
TestServiceLocator3 factory = (TestServiceLocator3) bf.getBean("factory");
157144
TestService testBean1 = factory.getTestService();
158145
TestService testBean2 = factory.getTestService("testService");
@@ -177,16 +164,6 @@ public void testServiceMappings() {
177164
.addPropertyValue("serviceLocatorInterface", TestServiceLocator3.class)
178165
.addPropertyValue("serviceMappings", "=testService1\n1=testService1\n2=testService2")
179166
.getBeanDefinition());
180-
181-
// StaticApplicationContext ctx = new StaticApplicationContext();
182-
// ctx.registerPrototype("testService1", TestService.class, new MutablePropertyValues());
183-
// ctx.registerPrototype("testService2", ExtendedTestService.class, new MutablePropertyValues());
184-
// MutablePropertyValues mpv = new MutablePropertyValues();
185-
// mpv.addPropertyValue("serviceLocatorInterface", TestServiceLocator3.class);
186-
// mpv.addPropertyValue("serviceMappings", "=testService1\n1=testService1\n2=testService2");
187-
// ctx.registerSingleton("factory", ServiceLocatorFactoryBean.class, mpv);
188-
// ctx.refresh();
189-
190167
TestServiceLocator3 factory = (TestServiceLocator3) bf.getBean("factory");
191168
TestService testBean1 = factory.getTestService();
192169
TestService testBean2 = factory.getTestService("testService1");
@@ -303,8 +280,6 @@ public interface TestService2Locator {
303280

304281
public interface ServiceLocatorInterfaceWithExtraNonCompliantMethod {
305282

306-
TestService2 getTestService();
307-
308283
TestService2 getTestService(String serviceName, String defaultNotAllowedParameter);
309284
}
310285

spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -7145,8 +7145,7 @@ public TestClass9(int i) {
71457145
static class HttpServlet3RequestFactory {
71467146

71477147
static Servlet3SecurityContextHolderAwareRequestWrapper getOne() {
7148-
HttpServlet3RequestFactory outer = new HttpServlet3RequestFactory();
7149-
return outer.new Servlet3SecurityContextHolderAwareRequestWrapper();
7148+
return new HttpServlet3RequestFactory().new Servlet3SecurityContextHolderAwareRequestWrapper();
71507149
}
71517150

71527151
// private class Servlet3SecurityContextHolderAwareRequestWrapper extends SecurityContextHolderAwareRequestWrapper

spring-test/src/test/java/org/springframework/test/web/client/samples/SampleTests.java

+9-12
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ public void performGet() {
7070
String responseBody = "{\"name\" : \"Ludwig van Beethoven\", \"someDouble\" : \"1.6035\"}";
7171

7272
this.mockServer.expect(requestTo("/composers/42")).andExpect(method(HttpMethod.GET))
73-
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
73+
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
7474

75-
@SuppressWarnings("unused")
76-
Person ludwig = this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
75+
this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
7776

7877
// We are only validating the request. The response is mocked out.
7978
// hotel.getId() == 42
@@ -90,8 +89,7 @@ public void performGetManyTimes() {
9089
this.mockServer.expect(manyTimes(), requestTo("/composers/42")).andExpect(method(HttpMethod.GET))
9190
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
9291

93-
@SuppressWarnings("unused")
94-
Person ludwig = this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
92+
this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
9593

9694
// We are only validating the request. The response is mocked out.
9795
// hotel.getId() == 42
@@ -142,8 +140,7 @@ public void performGetWithResponseBodyFromFile() {
142140
this.mockServer.expect(requestTo("/composers/42")).andExpect(method(HttpMethod.GET))
143141
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
144142

145-
@SuppressWarnings("unused")
146-
Person ludwig = this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
143+
this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
147144

148145
// hotel.getId() == 42
149146
// hotel.getName().equals("Holiday Inn")
@@ -155,16 +152,16 @@ public void performGetWithResponseBodyFromFile() {
155152
public void verify() {
156153

157154
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
158-
.andRespond(withSuccess("1", MediaType.TEXT_PLAIN));
155+
.andRespond(withSuccess("1", MediaType.TEXT_PLAIN));
159156

160157
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
161-
.andRespond(withSuccess("2", MediaType.TEXT_PLAIN));
158+
.andRespond(withSuccess("2", MediaType.TEXT_PLAIN));
162159

163160
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
164-
.andRespond(withSuccess("4", MediaType.TEXT_PLAIN));
161+
.andRespond(withSuccess("4", MediaType.TEXT_PLAIN));
165162

166163
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
167-
.andRespond(withSuccess("8", MediaType.TEXT_PLAIN));
164+
.andRespond(withSuccess("8", MediaType.TEXT_PLAIN));
168165

169166
@SuppressWarnings("unused")
170167
String result1 = this.restTemplate.getForObject("/number", String.class);
@@ -215,7 +212,7 @@ private ContentInterceptor(Resource resource) {
215212

216213
@Override
217214
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
218-
ClientHttpRequestExecution execution) throws IOException {
215+
ClientHttpRequestExecution execution) throws IOException {
219216

220217
ClientHttpResponse response = execution.execute(request, body);
221218
byte[] expected = FileCopyUtils.copyToByteArray(this.resource.getInputStream());

spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMethodMappingTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ void getCorsConfigWithBeanNameHandler() throws Exception {
289289

290290
this.mapping.setApplicationContext(context);
291291
this.mapping.registerMapping(key, beanName, this.method1);
292-
HandlerMethod handlerMethod = this.mapping.getHandlerInternal(new MockHttpServletRequest("GET", key));
292+
this.mapping.getHandlerInternal(new MockHttpServletRequest("GET", key));
293293
}
294294

295295
@Test

0 commit comments

Comments
 (0)