Make fields final

Closes gh-33537
This commit is contained in:
Moritz Halbritter
2022-12-16 14:28:44 +01:00
parent 216d15997a
commit 725337f976
285 changed files with 445 additions and 437 deletions

View File

@@ -401,11 +401,11 @@ public abstract class EndpointDiscoverer<E extends ExposableEndpoint<O>, O exten
private final EndpointId id;
private boolean enabledByDefault;
private final boolean enabledByDefault;
private final Class<?> filter;
private Set<ExtensionBean> extensions = new LinkedHashSet<>();
private final Set<ExtensionBean> extensions = new LinkedHashSet<>();
EndpointBean(Environment environment, String beanName, Class<?> beanType, Supplier<Object> beanSupplier) {
MergedAnnotation<Endpoint> annotation = MergedAnnotations.from(beanType, SearchStrategy.TYPE_HIERARCHY)

View File

@@ -190,7 +190,7 @@ public final class Health extends HealthComponent {
private Status status;
private Map<String, Object> details;
private final Map<String, Object> details;
private Throwable exception;

View File

@@ -161,7 +161,7 @@ public class LoggersEndpoint {
*/
public static class LoggerLevelsDescriptor implements OperationResponseBody {
private String configuredLevel;
private final String configuredLevel;
public LoggerLevelsDescriptor(LogLevel configuredLevel) {
this.configuredLevel = getName(configuredLevel);
@@ -182,7 +182,7 @@ public class LoggersEndpoint {
*/
public static class GroupLoggerLevelsDescriptor extends LoggerLevelsDescriptor {
private List<String> members;
private final List<String> members;
public GroupLoggerLevelsDescriptor(LogLevel configuredLevel, List<String> members) {
super(configuredLevel);
@@ -200,7 +200,7 @@ public class LoggersEndpoint {
*/
public static class SingleLoggerLevelsDescriptor extends LoggerLevelsDescriptor {
private String effectiveLevel;
private final String effectiveLevel;
public SingleLoggerLevelsDescriptor(LoggerConfiguration configuration) {
super(configuration.getConfiguredLevel());

View File

@@ -146,9 +146,9 @@ public class HeapDumpWebEndpoint {
*/
protected static class HotSpotDiagnosticMXBeanHeapDumper implements HeapDumper {
private Object diagnosticMXBean;
private final Object diagnosticMXBean;
private Method dumpHeapMethod;
private final Method dumpHeapMethod;
@SuppressWarnings("unchecked")
protected HotSpotDiagnosticMXBeanHeapDumper() {
@@ -189,9 +189,9 @@ public class HeapDumpWebEndpoint {
*/
private static final class OpenJ9DiagnosticsMXBeanHeapDumper implements HeapDumper {
private Object diagnosticMXBean;
private final Object diagnosticMXBean;
private Method dumpHeapMethod;
private final Method dumpHeapMethod;
@SuppressWarnings("unchecked")
private OpenJ9DiagnosticsMXBeanHeapDumper() {

View File

@@ -56,7 +56,7 @@ public class PrometheusPushGatewayManager {
private final TaskScheduler scheduler;
private ScheduledFuture<?> scheduled;
private final ScheduledFuture<?> scheduled;
/**
* Create a new {@link PrometheusPushGatewayManager} instance using a single threaded

View File

@@ -53,7 +53,7 @@ public class AuthenticationAuditListener extends AbstractAuthenticationAuditList
private static final String WEB_LISTENER_CHECK_CLASS = "org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent";
private WebAuditListener webListener = maybeCreateWebListener();
private final WebAuditListener webListener = maybeCreateWebListener();
private static WebAuditListener maybeCreateWebListener() {
if (ClassUtils.isPresent(WEB_LISTENER_CHECK_CLASS, null)) {

View File

@@ -497,9 +497,9 @@ class ConfigurationPropertiesReportEndpointSerializationTests {
public static class InitializedMapAndListProperties extends Foo {
private Map<String, Boolean> map = new HashMap<>();
private final Map<String, Boolean> map = new HashMap<>();
private List<String> list = new ArrayList<>();
private final List<String> list = new ArrayList<>();
public Map<String, Boolean> getMap() {
return this.map;

View File

@@ -435,7 +435,7 @@ class ConfigurationPropertiesReportEndpointTests {
private Duration duration = Duration.ofSeconds(10);
private String ignored = "dummy";
private final String ignored = "dummy";
public String getDbPassword() {
return this.dbPassword;
@@ -803,7 +803,7 @@ class ConfigurationPropertiesReportEndpointTests {
private URI noPasswordUri = URI.create("http://user:@localhost:8080");
private List<String> simpleList = new ArrayList<>();
private final List<String> simpleList = new ArrayList<>();
private String rawSensitiveAddresses = "http://user:password@localhost:8080,http://user2:password2@localhost:8082";

View File

@@ -38,16 +38,17 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class OperationMethodParameterTests {
private Method example = ReflectionUtils.findMethod(getClass(), "example", String.class, String.class);
private final Method example = ReflectionUtils.findMethod(getClass(), "example", String.class, String.class);
private Method exampleJsr305 = ReflectionUtils.findMethod(getClass(), "exampleJsr305", String.class, String.class);
private Method exampleMetaJsr305 = ReflectionUtils.findMethod(getClass(), "exampleMetaJsr305", String.class,
private final Method exampleJsr305 = ReflectionUtils.findMethod(getClass(), "exampleJsr305", String.class,
String.class);
private Method exampleJsr305NonNull = ReflectionUtils.findMethod(getClass(), "exampleJsr305NonNull", String.class,
private final Method exampleMetaJsr305 = ReflectionUtils.findMethod(getClass(), "exampleMetaJsr305", String.class,
String.class);
private final Method exampleJsr305NonNull = ReflectionUtils.findMethod(getClass(), "exampleJsr305NonNull",
String.class, String.class);
@Test
void getNameShouldReturnName() {
OperationMethodParameter parameter = new OperationMethodParameter("name", this.example.getParameters()[0]);

View File

@@ -43,9 +43,9 @@ import static org.mockito.Mockito.mock;
*/
class OperationMethodParametersTests {
private Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example", String.class);
private final Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example", String.class);
private Method exampleNoParamsMethod = ReflectionUtils.findMethod(getClass(), "exampleNoParams");
private final Method exampleNoParamsMethod = ReflectionUtils.findMethod(getClass(), "exampleNoParams");
@Test
void createWhenMethodIsNullShouldThrowException() {

View File

@@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
*/
class OperationMethodTests {
private Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example", String.class);
private final Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example", String.class);
@Test
void createWhenMethodIsNullShouldThrowException() {

View File

@@ -54,9 +54,9 @@ class EndpointMBeanTests {
private static final String[] NO_SIGNATURE = {};
private TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(new TestJmxOperation());
private final TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(new TestJmxOperation());
private TestJmxOperationResponseMapper responseMapper = new TestJmxOperationResponseMapper();
private final TestJmxOperationResponseMapper responseMapper = new TestJmxOperationResponseMapper();
@Test
void createWhenResponseMapperIsNullShouldThrowException() {

View File

@@ -42,7 +42,7 @@ import static org.mockito.Mockito.spy;
*/
class JacksonJmxOperationResponseMapperTests {
private JacksonJmxOperationResponseMapper mapper = new JacksonJmxOperationResponseMapper(null);
private final JacksonJmxOperationResponseMapper mapper = new JacksonJmxOperationResponseMapper(null);
private final BasicJsonTester json = new BasicJsonTester(getClass());

View File

@@ -61,9 +61,9 @@ class JmxEndpointExporterTests {
@Spy
private EndpointObjectNameFactory objectNameFactory = new TestEndpointObjectNameFactory();
private JmxOperationResponseMapper responseMapper = new TestJmxOperationResponseMapper();
private final JmxOperationResponseMapper responseMapper = new TestJmxOperationResponseMapper();
private List<ExposableJmxEndpoint> endpoints = new ArrayList<>();
private final List<ExposableJmxEndpoint> endpoints = new ArrayList<>();
@Captor
private ArgumentCaptor<Object> objectCaptor;

View File

@@ -39,7 +39,7 @@ import static org.mockito.Mockito.mock;
*/
class MBeanInfoFactoryTests {
private MBeanInfoFactory factory = new MBeanInfoFactory(new TestJmxOperationResponseMapper());
private final MBeanInfoFactory factory = new MBeanInfoFactory(new TestJmxOperationResponseMapper());
@Test
void getMBeanInfoShouldReturnMBeanInfo() {

View File

@@ -42,7 +42,7 @@ class RequestPredicateFactoryTests {
private final RequestPredicateFactory factory = new RequestPredicateFactory(
new EndpointMediaTypes(Collections.emptyList(), Collections.emptyList()));
private String rootPath = "/root";
private final String rootPath = "/root";
@Test
void getRequestPredicateWhenHasMoreThanOneMatchAllThrowsException() {

View File

@@ -94,7 +94,7 @@ class AbstractHealthIndicatorTests {
static class TestHealthIndicator extends AbstractHealthIndicator {
private Consumer<Builder> action;
private final Consumer<Builder> action;
TestHealthIndicator(String message, Consumer<Builder> action) {
super(message);

View File

@@ -83,7 +83,7 @@ class HeapDumpWebEndpointWebIntegrationTests {
private boolean available;
private String heapDump = "HEAPDUMP";
private final String heapDump = "HEAPDUMP";
private File file;

View File

@@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class MetricsEndpointWebIntegrationTests {
private static MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
private static final MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
private final ObjectMapper mapper = new ObjectMapper();

View File

@@ -39,7 +39,7 @@ import static org.mockito.Mockito.mock;
*/
class DefaultRepositoryTagsProviderTests {
private DefaultRepositoryTagsProvider provider = new DefaultRepositoryTagsProvider();
private final DefaultRepositoryTagsProvider provider = new DefaultRepositoryTagsProvider();
@Test
void repositoryTagsIncludesRepository() {

View File

@@ -61,9 +61,9 @@ class PrometheusPushGatewayManagerTests {
@Mock
private TaskScheduler scheduler;
private Duration pushRate = Duration.ofSeconds(1);
private final Duration pushRate = Duration.ofSeconds(1);
private Map<String, String> groupingKey = Collections.singletonMap("foo", "bar");
private final Map<String, String> groupingKey = Collections.singletonMap("foo", "bar");
@Captor
private ArgumentCaptor<Runnable> task;

View File

@@ -34,11 +34,11 @@ class ObservationRestTemplateCustomizerTests {
private static final String TEST_METRIC_NAME = "http.test.metric.name";
private ObservationRegistry observationRegistry = TestObservationRegistry.create();
private final ObservationRegistry observationRegistry = TestObservationRegistry.create();
private RestTemplate restTemplate = new RestTemplate();
private final RestTemplate restTemplate = new RestTemplate();
private ObservationRestTemplateCustomizer customizer = new ObservationRestTemplateCustomizer(
private final ObservationRestTemplateCustomizer customizer = new ObservationRestTemplateCustomizer(
this.observationRegistry, new DefaultClientRequestObservationConvention(TEST_METRIC_NAME));
@Test

View File

@@ -44,7 +44,7 @@ class DefaultWebClientExchangeTagsProviderTests {
private static final String URI_TEMPLATE_ATTRIBUTE = WebClient.class.getName() + ".uriTemplate";
private WebClientExchangeTagsProvider tagsProvider = new DefaultWebClientExchangeTagsProvider();
private final WebClientExchangeTagsProvider tagsProvider = new DefaultWebClientExchangeTagsProvider();
private ClientRequest request;

View File

@@ -34,15 +34,15 @@ class ObservationWebClientCustomizerTests {
private static final String TEST_METRIC_NAME = "http.test.metric.name";
private TestObservationRegistry observationRegistry = TestObservationRegistry.create();
private final TestObservationRegistry observationRegistry = TestObservationRegistry.create();
private ClientRequestObservationConvention observationConvention = new DefaultClientRequestObservationConvention(
private final ClientRequestObservationConvention observationConvention = new DefaultClientRequestObservationConvention(
TEST_METRIC_NAME);
private ObservationWebClientCustomizer customizer = new ObservationWebClientCustomizer(this.observationRegistry,
this.observationConvention);
private final ObservationWebClientCustomizer customizer = new ObservationWebClientCustomizer(
this.observationRegistry, this.observationConvention);
private WebClient.Builder clientBuilder = WebClient.builder();
private final WebClient.Builder clientBuilder = WebClient.builder();
@Test
void shouldCustomizeObservationConfiguration() {