Skip to content

Use explicit types instead of var #15537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,15 @@ else if (authenticationProviders.size() > 1) {
+ "using the DSL.", authenticationProviders.size(), beanNames));
return;
}
var authenticationProvider = authenticationProviders.get(0).getBean();
var authenticationProviderBeanName = authenticationProviders.get(0).getName();
AuthenticationProvider authenticationProvider = authenticationProviders.get(0).getBean();
String authenticationProviderBeanName = authenticationProviders.get(0).getName();

auth.authenticationProvider(authenticationProvider);
this.logger.info(LogMessage.format(
"Global AuthenticationManager configured with AuthenticationProvider bean with name %s",
authenticationProviderBeanName));
}

/**
* @return a bean of the requested class if there's just a single registered
* component, null otherwise.
*/
private <T> T getBeanOrNull(Class<T> type) {
String[] beanNames = InitializeAuthenticationProviderBeanManagerConfigurer.this.context
.getBeanNamesForType(type);
if (beanNames.length != 1) {
return null;
}
return InitializeAuthenticationProviderBeanManagerConfigurer.this.context.getBean(beanNames[0], type);
}

/**
* @return a list of beans of the requested class, along with their names. If
* there are no registered beans of that type, the list is empty.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ else if (userDetailsServices.size() > 1) {
beanNames));
return;
}
var userDetailsService = userDetailsServices.get(0).getBean();
var userDetailsServiceBeanName = userDetailsServices.get(0).getName();
UserDetailsService userDetailsService = userDetailsServices.get(0).getBean();
String userDetailsServiceBeanName = userDetailsServices.get(0).getName();
PasswordEncoder passwordEncoder = getBeanOrNull(PasswordEncoder.class);
UserDetailsPasswordService passwordManager = getBeanOrNull(UserDetailsPasswordService.class);
CompromisedPasswordChecker passwordChecker = getBeanOrNull(CompromisedPasswordChecker.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import org.springframework.aop.framework.ProxyFactory;
Expand Down Expand Up @@ -141,7 +142,7 @@ public void autowireBeanFactoryWhenBeanNameAutoProxyCreatorThenWorks() {

@Test
void postProcessWhenObjectIsCgLibProxyAndInNativeImageThenUseExistingBean() {
try (var detector = Mockito.mockStatic(NativeDetector.class)) {
try (MockedStatic<NativeDetector> detector = Mockito.mockStatic(NativeDetector.class)) {
given(NativeDetector.inNativeImage()).willReturn(true);

ProxyFactory proxyFactory = new ProxyFactory(new MyClass());
Expand All @@ -158,7 +159,7 @@ void postProcessWhenObjectIsCgLibProxyAndInNativeImageThenUseExistingBean() {

@Test
void postProcessWhenObjectIsCgLibProxyAndInNativeImageAndBeanDoesNotExistsThenIllegalStateException() {
try (var detector = Mockito.mockStatic(NativeDetector.class)) {
try (MockedStatic<NativeDetector> detector = Mockito.mockStatic(NativeDetector.class)) {
given(NativeDetector.inNativeImage()).willReturn(true);

ProxyFactory proxyFactory = new ProxyFactory(new MyClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void testRoleNamesStartWithDefaultRolePrefix() {

@Test
public void testRoleNamesStartWithCustomRolePrefix() {
var customPrefix = "GROUP_";
String customPrefix = "GROUP_";
this.mgr.setRolePrefix(customPrefix);

this.mgr.setUsernameMapper(new DefaultLdapUsernameToDnMapper("ou=people", "uid"));
Expand Down