Skip to content

Commit

Permalink
enh: cleaned up all compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lprimak committed Dec 20, 2023
1 parent 6ecb862 commit 5755721
Show file tree
Hide file tree
Showing 77 changed files with 384 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public abstract class AbstractCacheManager implements CacheManager, Destroyable
/**
* Retains all Cache objects maintained by this cache manager.
*/
private final ConcurrentMap<String, Cache> caches;
private final ConcurrentMap<String, Cache<?, ?>> caches;

/**
* Default no-arg constructor that instantiates an internal name-to-cache {@code ConcurrentMap}.
*/
public AbstractCacheManager() {
this.caches = new ConcurrentHashMap<String, Cache>();
this.caches = new ConcurrentHashMap<>();
}

/**
Expand All @@ -56,17 +56,18 @@ public AbstractCacheManager() {
* @throws IllegalArgumentException if the {@code name} argument is {@code null} or does not contain text.
* @throws CacheException if there is a problem lazily creating a {@code Cache} instance.
*/
@SuppressWarnings("unchecked")
public <K, V> Cache<K, V> getCache(String name) throws IllegalArgumentException, CacheException {
if (!StringUtils.hasText(name)) {
throw new IllegalArgumentException("Cache name cannot be null or empty.");
}

Cache cache;
Cache<K, V> cache;

cache = caches.get(name);
cache = (Cache<K, V>) caches.get(name);
if (cache == null) {
cache = createCache(name);
Cache existing = caches.putIfAbsent(name, cache);
Cache<K, V> existing = (Cache<K, V>) caches.putIfAbsent(name, cache);
if (existing != null) {
cache = existing;
}
Expand All @@ -83,7 +84,7 @@ public <K, V> Cache<K, V> getCache(String name) throws IllegalArgumentException,
* @return a new {@code Cache} instance associated with the specified {@code name}.
* @throws CacheException if the {@code Cache} instance cannot be created.
*/
protected abstract Cache createCache(String name) throws CacheException;
protected abstract <K, V> Cache<K, V> createCache(String name) throws CacheException;

/**
* Cleanup method that first {@link LifecycleUtils#destroy destroys} all of it's managed caches and then
Expand All @@ -101,7 +102,7 @@ public void destroy() throws Exception {
}

public String toString() {
Collection<Cache> values = caches.values();
Collection<Cache<?, ?>> values = caches.values();
StringBuilder sb = new StringBuilder(getClass().getSimpleName())
.append(" with ")
.append(caches.size())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class MemoryConstrainedCacheManager extends AbstractCacheManager {
* @return a new {@link MapCache MapCache} instance backed by a {@link SoftHashMap}.
*/
@Override
protected Cache createCache(String name) {
return new MapCache<Object, Object>(name, new SoftHashMap<Object, Object>());
protected <K, V> Cache<K, V> createCache(String name) {
return new MapCache<>(name, new SoftHashMap<>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

import org.apache.commons.configuration2.interpol.ConfigurationInterpolator;
import org.apache.commons.configuration2.interpol.ConstantLookup;
import org.apache.commons.configuration2.interpol.EnvironmentLookup;
import org.apache.commons.configuration2.interpol.SystemPropertiesLookup;
import org.apache.commons.configuration2.interpol.DefaultLookups;

/**
* Commons-Config interpolation wrapper. This implementation uses a {@link ConfigurationInterpolator} with the default
Expand Down Expand Up @@ -61,8 +60,8 @@ public CommonsInterpolator() {
this.interpolator = new ConfigurationInterpolator();

interpolator.registerLookup("const", new ConstantLookup());
interpolator.addDefaultLookup(new SystemPropertiesLookup());
interpolator.addDefaultLookup(new EnvironmentLookup());
interpolator.addDefaultLookup(DefaultLookups.SYSTEM_PROPERTIES.getLookup());
interpolator.addDefaultLookup(DefaultLookups.ENVIRONMENT.getLookup());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ public ReflectionBuilder(Map<String, ?> defaults) {
// SHIRO-739
beanUtilsBean = new BeanUtilsBean(new ConvertUtilsBean() {
@Override
public Object convert(String value, Class clazz) {
@SuppressWarnings("unchecked")
public Object convert(String value, Class<?> clazz) {
if (clazz.isEnum()) {
return Enum.valueOf(clazz, value);
return Enum.valueOf((Class<Enum>) clazz, value);
} else {
return super.convert(value, clazz);
}
Expand Down Expand Up @@ -460,7 +461,7 @@ protected Object resolveReference(String reference) {
return referencedObject;
}

protected boolean isTypedProperty(Object object, String propertyName, Class clazz) {
protected boolean isTypedProperty(Object object, String propertyName, Class<?> clazz) {
if (clazz == null) {
throw new NullPointerException("type (class) argument cannot be null.");
}
Expand All @@ -471,7 +472,7 @@ protected boolean isTypedProperty(Object object, String propertyName, Class claz
+ "type " + object.getClass().getName() + ".";
throw new ConfigurationException(msg);
}
Class propertyClazz = descriptor.getPropertyType();
Class<?> propertyClazz = descriptor.getPropertyType();
return clazz.isAssignableFrom(propertyClazz);
} catch (ConfigurationException ce) {
//let it propagate:
Expand Down Expand Up @@ -666,7 +667,8 @@ protected void applyProperty(Object object, String propertyPath, Object value) {
} else {
//we're assigning a map or array entry. Check to see which we should call:
if (isTypedProperty(object, mapPropertyPath, Map.class)) {
Map map = (Map) getProperty(object, mapPropertyPath);
@SuppressWarnings("unchecked")
var map = (Map<Object, Object>) getProperty(object, mapPropertyPath);
Object mapKey = resolveValue(keyString);
//noinspection unchecked
map.put(mapKey, value);
Expand Down
4 changes: 4 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SaltedAuthenticationInfo;
import org.apache.shiro.crypto.hash.AbstractHash;
import org.apache.shiro.crypto.hash.Hash;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.lang.codec.Base64;
Expand Down Expand Up @@ -294,11 +293,7 @@ public int getHashIterations() {
* @param hashIterations the number of times to hash a submitted {@code AuthenticationToken}'s credentials.
*/
public void setHashIterations(int hashIterations) {
if (hashIterations < 1) {
this.hashIterations = 1;
} else {
this.hashIterations = hashIterations;
}
this.hashIterations = Math.max(hashIterations, 1);
}

/**
Expand Down Expand Up @@ -362,7 +357,7 @@ protected Object getCredentials(AuthenticationInfo info) {
storedBytes = Base64.decode(storedBytes);
}
}
AbstractHash hash = newHashInstance();
SimpleHash hash = newHashInstance();
hash.setBytes(storedBytes);
return hash;
}
Expand Down Expand Up @@ -460,7 +455,7 @@ protected Hash hashProvidedCredentials(Object credentials, Object salt, int hash
*
* @return a new, <em>uninitialized</em> instance, without its byte array set.
*/
protected AbstractHash newHashInstance() {
protected SimpleHash newHashInstance() {
String hashAlgorithmName = assertHashAlgorithmName();
return new SimpleHash(hashAlgorithmName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @deprecated since 1.1 - use the HashedCredentialsMatcher directly and set its
* {@link HashedCredentialsMatcher#setHashAlgorithmName(String) hashAlgorithmName} property.
*/
@Deprecated
public class Sha256CredentialsMatcher extends HashedCredentialsMatcher {

public Sha256CredentialsMatcher() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @deprecated since 1.1 - use the HashedCredentialsMatcher directly and set its
* {@link HashedCredentialsMatcher#setHashAlgorithmName(String) hashAlgorithmName} property.
*/
@Deprecated
public class Sha384CredentialsMatcher extends HashedCredentialsMatcher {

public Sha384CredentialsMatcher() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @deprecated since 1.1 - use the HashedCredentialsMatcher directly and set its
* {@link HashedCredentialsMatcher#setHashAlgorithmName(String) hashAlgorithmName} property.
*/
@Deprecated
public class Sha512CredentialsMatcher extends HashedCredentialsMatcher {

public Sha512CredentialsMatcher() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@
* @since 1.5
*/
public class BasicIniEnvironment extends DefaultEnvironment {
@SuppressWarnings({"deprecation", "checkstyle:JavadocVariable"})
public static final String INI_REALM_NAME = IniSecurityManagerFactory.INI_REALM_NAME;

public BasicIniEnvironment(Ini ini) {
this(ini, (name) -> null);
}

public BasicIniEnvironment(Ini ini, Function<String, ?> alternateObjectSupplier) {
@SuppressWarnings("deprecation")
var securityManagerFactory = new IniSecurityManagerFactory(ini);
securityManagerFactory.getReflectionBuilder().setAlternateObjectSupplier(alternateObjectSupplier);
setSecurityManager(securityManagerFactory.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class JndiObjectFactory<T> extends JndiLocator implements Factory<T> {
private String resourceName;
private Class<? extends T> requiredType;

@SuppressWarnings("unchecked")
public T getInstance() {
try {
if (requiredType != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) {
* @return the authenticationToken class supported by this realm.
* @see #setAuthenticationTokenClass
*/
public Class getAuthenticationTokenClass() {
public Class<? extends AuthenticationToken> getAuthenticationTokenClass() {
return authenticationTokenClass;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @since 1.1
* @deprecated Renamed to {@link DefaultLdapRealm}, this class will be removed prior to 2.0
*/
@Deprecated
public class JndiLdapRealm extends DefaultLdapRealm {

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class EnterpriseCacheSessionDAO extends CachingSessionDAO {
public EnterpriseCacheSessionDAO() {
setCacheManager(new AbstractCacheManager() {
@Override
protected Cache<Serializable, Session> createCache(String name) throws CacheException {
return new MapCache<Serializable, Session>(name, new ConcurrentHashMap<Serializable, Session>());
protected <Serializable, Session> Cache<Serializable, Session> createCache(String name) throws CacheException {
return new MapCache<>(name, new ConcurrentHashMap<>());
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/apache/shiro/util/CollectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public final class CollectionUtils {
private CollectionUtils() {
}

@SafeVarargs
public static <E> Set<E> asSet(E... elements) {
if (elements == null || elements.length == 0) {
return Collections.emptySet();
Expand Down Expand Up @@ -116,6 +117,7 @@ public static boolean isEmpty(PrincipalCollection principals) {
return principals == null || principals.isEmpty();
}

@SafeVarargs
public static <E> List<E> asList(E... elements) {
if (elements == null || elements.length == 0) {
return Collections.emptyList();
Expand Down
30 changes: 30 additions & 0 deletions core/src/main/java/org/apache/shiro/util/OsgiDependencies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.shiro.util;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.configuration2.BaseConfiguration;

/**
* This class only exists to satisfy the OSGi plugin
*/
class OsgiDependencies {
BeanUtils bu;
BaseConfiguration bc;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.crypto.hash.AbstractHash;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.lang.util.ClassUtils;
import org.junit.jupiter.api.Test;

Expand All @@ -36,7 +36,7 @@ public abstract class AbstractHashedCredentialsMatcherTest {

public abstract Class<? extends HashedCredentialsMatcher> getMatcherClass();

public abstract AbstractHash hash(Object credentials);
public abstract SimpleHash hash(Object credentials);

@Test
void testBasic() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public Object getCredentials() {
* <a href="https://issues.apache.org/jira/browse/SHIRO-186">SHIRO-186</a> edits.
*/
@Test
@SuppressWarnings("deprecation")
void testBackwardsCompatibleSaltedAuthenticationInfo() {
HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(Sha512Hash.ALGORITHM_NAME);
//enable this for Shiro 1.0 backwards compatibility:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@
*/
package org.apache.shiro.authc.credential;

import org.apache.shiro.crypto.hash.AbstractHash;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.apache.shiro.crypto.hash.SimpleHash;


/**
* @since Jun 10, 2008 5:01:00 PM
*/
@Deprecated
public class Sha256CredentialsMatcherTest extends AbstractHashedCredentialsMatcherTest {

public Class<? extends HashedCredentialsMatcher> getMatcherClass() {
return Sha256CredentialsMatcher.class;
}

public AbstractHash hash(Object credentials) {
public SimpleHash hash(Object credentials) {
return new Sha256Hash(credentials);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@
*/
package org.apache.shiro.authc.credential;

import org.apache.shiro.crypto.hash.AbstractHash;
import org.apache.shiro.crypto.hash.Sha384Hash;
import org.apache.shiro.crypto.hash.SimpleHash;


/**
* @since Jun 10, 2008 5:02:27 PM
*/
@Deprecated
public class Sha384CredentialsMatcherTest extends AbstractHashedCredentialsMatcherTest {

public Class<? extends HashedCredentialsMatcher> getMatcherClass() {
return Sha384CredentialsMatcher.class;
}

public AbstractHash hash(Object credentials) {
public SimpleHash hash(Object credentials) {
return new Sha384Hash(credentials);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@
*/
package org.apache.shiro.authc.credential;

import org.apache.shiro.crypto.hash.AbstractHash;
import org.apache.shiro.crypto.hash.Sha512Hash;
import org.apache.shiro.crypto.hash.SimpleHash;


/**
* @since Jun 10, 2008 5:02:58 PM
*/
@Deprecated
public class Sha512CredentialsMatcherTest extends AbstractHashedCredentialsMatcherTest {

public Class<? extends HashedCredentialsMatcher> getMatcherClass() {
return Sha512CredentialsMatcher.class;
}

public AbstractHash hash(Object credentials) {
public SimpleHash hash(Object credentials) {
return new Sha512Hash(credentials);
}
}
Loading

0 comments on commit 5755721

Please sign in to comment.