Skip to content
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

Cleanup redundant type casts #7073

Merged
Merged
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 @@ -455,7 +455,7 @@ private AclImpl convert(Map<Serializable, Acl> inputMap, Long currentIdentity) {

// Now we have the parent (if there is one), create the true AclImpl
AclImpl result = new AclImpl(inputAcl.getObjectIdentity(),
(Long) inputAcl.getId(), aclAuthorizationStrategy, grantingStrategy,
inputAcl.getId(), aclAuthorizationStrategy, grantingStrategy,
parent, null, inputAcl.isEntriesInheriting(), inputAcl.getOwner());

// Copy the "aces" from the input to the destination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Acl readAclById(ObjectIdentity object, List<Sid> sids)
Assert.isTrue(map.containsKey(object),
() -> "There should have been an Acl entry for ObjectIdentity " + object);

return (Acl) map.get(object);
return map.get(object);
}

public Acl readAclById(ObjectIdentity object) throws NotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,13 @@ public void isSidLoadedBehavesAsExpected() throws Exception {
assertThat(acl.isSidLoaded(BEN)).isTrue();
assertThat(acl.isSidLoaded(null)).isTrue();
assertThat(acl.isSidLoaded(new ArrayList<>(0))).isTrue();
assertThat(acl.isSidLoaded(Arrays.asList((Sid) new GrantedAuthoritySid(
assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid(
"ROLE_IGNORED"), new GrantedAuthoritySid("ROLE_IGNORED"))))
.isTrue();
assertThat(acl.isSidLoaded(Arrays.asList((Sid) new GrantedAuthoritySid(
assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid(
"ROLE_GENERAL"), new GrantedAuthoritySid("ROLE_IGNORED"))))
.isFalse();
assertThat(acl.isSidLoaded(Arrays.asList((Sid) new GrantedAuthoritySid(
assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid(
"ROLE_IGNORED"), new GrantedAuthoritySid("ROLE_GENERAL"))))
.isFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void deleteAclAlsoDeletesChildren() throws Exception {

Acl acl = jdbcMutableAclService.readAclById(getTopParentOid());
assertThat(acl).isNotNull();
assertThat(getTopParentOid()).isEqualTo(((MutableAcl) acl).getObjectIdentity());
assertThat(getTopParentOid()).isEqualTo(acl.getObjectIdentity());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.springframework.security.cas.jackson2;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.jasig.cas.client.authentication.AttributePrincipalImpl;
import org.jasig.cas.client.validation.AssertionImpl;
Expand Down Expand Up @@ -48,7 +47,7 @@ public CasJackson2Module() {

@Override
public void setupModule(SetupContext context) {
SecurityJackson2Modules.enableDefaultTyping((ObjectMapper) context.getOwner());
SecurityJackson2Modules.enableDefaultTyping(context.getOwner());
context.setMixInAnnotations(AssertionImpl.class, AssertionImplMixin.class);
context.setMixInAnnotations(AttributePrincipalImpl.class, AttributePrincipalImplMixin.class);
context.setMixInAnnotations(CasAuthenticationToken.class, CasAuthenticationTokenMixin.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,6 @@ public UserDetailsService getDefaultUserDetailsService() {
private <C extends UserDetailsAwareConfigurer<AuthenticationManagerBuilder, ? extends UserDetailsService>> C apply(
C configurer) throws Exception {
this.defaultUserDetailsService = configurer.getUserDetailsService();
return (C) super.apply(configurer);
return super.apply(configurer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2072,11 +2072,11 @@ private void mockRestOperations(String response) {
}

private <T> T bean(Class<T> beanClass) {
return (T) this.spring.getContext().getBean(beanClass);
return this.spring.getContext().getBean(beanClass);
}

private <T> T verifyBean(Class<T> beanClass) {
return (T) verify(this.spring.getContext().getBean(beanClass));
return verify(this.spring.getContext().getBean(beanClass));
}

private String json(String name) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class ExpressionUtils {

public static boolean evaluateAsBoolean(Expression expr, EvaluationContext ctx) {
try {
return ((Boolean) expr.getValue(ctx, Boolean.class)).booleanValue();
return expr.getValue(ctx, Boolean.class).booleanValue();
}
catch (EvaluationException e) {
throw new IllegalArgumentException("Failed to evaluate expression '"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private List<ConfigAttribute> findAttributesSpecifiedAgainst(Method method,
Class<?> clazz) {
RegisteredMethod registeredMethod = new RegisteredMethod(method, clazz);
if (methodMap.containsKey(registeredMethod)) {
return (List<ConfigAttribute>) methodMap.get(registeredMethod);
return methodMap.get(registeredMethod);
}
// Search superclass
if (clazz.getSuperclass() != null) {
Expand Down Expand Up @@ -166,7 +166,7 @@ public void addSecureMethod(Class<?> javaType, String mappedName,
// register all matching methods
for (Method method : matchingMethods) {
RegisteredMethod registeredMethod = new RegisteredMethod(method, javaType);
String regMethodName = (String) this.nameMap.get(registeredMethod);
String regMethodName = this.nameMap.get(registeredMethod);

if ((regMethodName == null)
|| (!regMethodName.equals(name) && (regMethodName.length() <= name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.springframework.security.jackson2;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.authentication.BadCredentialsException;
Expand Down Expand Up @@ -54,7 +53,7 @@ public CoreJackson2Module() {

@Override
public void setupModule(SetupContext context) {
SecurityJackson2Modules.enableDefaultTyping((ObjectMapper) context.getOwner());
SecurityJackson2Modules.enableDefaultTyping(context.getOwner());
context.setMixInAnnotations(AnonymousAuthenticationToken.class, AnonymousAuthenticationTokenMixin.class);
context.setMixInAnnotations(RememberMeAuthenticationToken.class, RememberMeAuthenticationTokenMixin.class);
context.setMixInAnnotations(SimpleGrantedAuthority.class, SimpleGrantedAuthorityMixin.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testConstructorRejectsNulls() {

try {
new AnonymousAuthenticationToken("key", "Test",
(List<GrantedAuthority>) null);
null);
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
import java.util.HashMap;
import java.util.Map;

import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserCache;
import org.springframework.security.core.userdetails.UserDetails;

public class MockUserCache implements UserCache {
private Map<String, UserDetails> cache = new HashMap<>();

public UserDetails getUserFromCache(String username) {
return (User) cache.get(username);
return cache.get(username);
}

public void putUserInCache(UserDetails user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void scheduleRunnable() {
@Test
public void scheduleCallable() {
when(
(ScheduledFuture<Object>) delegate.schedule(wrappedCallable, 1,
delegate.schedule(wrappedCallable, 1,
TimeUnit.SECONDS)).thenReturn(expectedResult);
ScheduledFuture<Object> result = executor.schedule(callable, 1, TimeUnit.SECONDS);
assertThat(result).isEqualTo(expectedResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private KeyBasedPersistenceTokenService getService() {
service.setServerSecret("MY:SECRET$$$#");
service.setServerInteger(Integer.valueOf(454545));
try {
SecureRandom rnd = (SecureRandom) fb.getObject();
SecureRandom rnd = fb.getObject();
service.setSecureRandom(rnd);
service.afterPropertiesSet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private class MockUserCache implements UserCache {
private Map<String, UserDetails> cache = new HashMap<>();

public UserDetails getUserFromCache(String username) {
return (User) cache.get(username);
return cache.get(username);
}

public void putUserInCache(UserDetails user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private String encode(CharSequence rawPassword, byte[] salt) {
sha.update(salt);
}

byte[] hash = combineHashAndSalt(sha.digest(), (byte[]) salt);
byte[] hash = combineHashAndSalt(sha.digest(), salt);

String prefix;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public boolean before(Authentication authentication, MethodInvocation mi,
throw new IllegalStateException("Python script did not set the permit flag");
}

return (Boolean) Py.tojava(allowed, Boolean.class);
return Py.tojava(allowed, Boolean.class);
}

private Map<String, Object> createArgumentMap(MethodInvocation mi) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.springframework.security.crypto.keygen.KeyGenerators;
import org.springframework.security.crypto.password.LdapShaPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.ldap.AbstractLdapIntegrationTests;

import org.springframework.ldap.core.DirContextAdapter;
Expand Down Expand Up @@ -122,7 +121,7 @@ public void testLdapCompareSucceedsWithShaEncodedPassword() {

@Test(expected = IllegalArgumentException.class)
public void testPasswordEncoderCantBeNull() {
authenticator.setPasswordEncoder((PasswordEncoder) null);
authenticator.setPasswordEncoder(null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void updateUser(UserDetails user) {
ListIterator<ModificationItem> modIt = mods.listIterator();

while (modIt.hasNext()) {
ModificationItem mod = (ModificationItem) modIt.next();
ModificationItem mod = modIt.next();
Attribute a = mod.getAttribute();
if ("objectclass".equalsIgnoreCase(a.getID())) {
modIt.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public IndexPage(WebDriver webDriver) {

public static <T> T to(WebDriver driver, int port, Class<T> page) {
driver.get("http://localhost:" + port +"/");
return (T) PageFactory.initElements(driver, page);
return PageFactory.initElements(driver, page);
}

public IndexPage assertAt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Contact mapRow(ResultSet rs, int rowNum) throws SQLException {
return null;
}
else {
return (Contact) list.get(0);
return list.get(0);
}
}

Expand Down
4 changes: 2 additions & 2 deletions samples/xml/dms/src/main/java/sample/dms/DocumentDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public Directory mapRow(ResultSet rs, int rowNumber)
.getLong("id")));
}
});
return (AbstractElement[]) directories.toArray(new AbstractElement[] {});
return directories.toArray(new AbstractElement[] {});
}
List<AbstractElement> directories = getJdbcTemplate().query(
SELECT_FROM_DIRECTORY, new Object[] { directory.getId() },
Expand Down Expand Up @@ -140,7 +140,7 @@ public File mapRow(ResultSet rs, int rowNumber) throws SQLException {
});
// Add the File elements after the Directory elements
directories.addAll(files);
return (AbstractElement[]) directories.toArray(new AbstractElement[] {});
return directories.toArray(new AbstractElement[] {});
}

public void update(File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public SecureDocumentDaoImpl(MutableAclService mutableAclService) {
}

public String[] getUsers() {
return (String[]) getJdbcTemplate().query(SELECT_FROM_USERS,
return getJdbcTemplate().query(SELECT_FROM_USERS,
new RowMapper<String>() {
public String mapRow(ResultSet rs, int rowNumber) throws SQLException {
return rs.getString("USERNAME");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static <T extends Filter> T findFilter(HttpServletRequest request,
if (springSecurityFilterChain == null) {
return null;
}
List<Filter> filters = (List<Filter>) ReflectionTestUtils
List<Filter> filters = ReflectionTestUtils
.invokeMethod(springSecurityFilterChain, "getFilters", request);
if (filters == null) {
return null;
Expand Down Expand Up @@ -157,4 +157,4 @@ private static Filter getSpringSecurityFilterChain(ServletContext servletContext

private WebTestUtils() {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void afterPropertiesSet() throws Exception {
NodeList roles = secRoleElt.getElementsByTagName("role-name");

if (roles.getLength() > 0) {
String roleName = ((Element) roles.item(0)).getTextContent().trim();
String roleName = roles.item(0).getTextContent().trim();
roleNames.add(roleName);
logger.info("Retrieved role-name '" + roleName + "' from web.xml");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void afterPropertiesSet() throws Exception {

public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException, ServletException {
HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpServletResponse httpResponse = response;

// compute a nonce (do not use remote IP address due to proxy farms)
// format of nonce is:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static long parseDate(String value, DateFormat[] threadLocalformats) {
Long cachedDate = null;

try {
cachedDate = (Long) parseCache.get(value);
cachedDate = parseCache.get(value);
}
catch (Exception ignored) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public class DefaultServerRedirectStrategyTests {

@Test(expected = IllegalArgumentException.class)
public void sendRedirectWhenLocationNullThenException() {
this.strategy.sendRedirect(this.exchange, (URI) null);
this.strategy.sendRedirect(this.exchange, null);
}

@Test(expected = IllegalArgumentException.class)
public void sendRedirectWhenExchangeNullThenException() {
this.strategy.sendRedirect((ServerWebExchange) null, this.location);
this.strategy.sendRedirect(null, this.location);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class RedirectServerAuthenticationEntryPointTests {

@Test(expected = IllegalArgumentException.class)
public void constructorStringWhenNullLocationThenException() {
new RedirectServerAuthenticationEntryPoint((String) null);
new RedirectServerAuthenticationEntryPoint(null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class RedirectServerAuthenticationFailureHandlerTests {

@Test(expected = IllegalArgumentException.class)
public void constructorStringWhenNullLocationThenException() {
new RedirectServerAuthenticationEntryPoint((String) null);
new RedirectServerAuthenticationEntryPoint(null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class HttpStatusServerAccessDeniedHandlerTests {

@Test(expected = IllegalArgumentException.class)
public void constructorHttpStatusWhenNullThenException() {
new HttpStatusServerAccessDeniedHandler((HttpStatus) null);
new HttpStatusServerAccessDeniedHandler(null);
}

@Test
Expand Down