修复 sa-token-jboot-plugin 模块代码警告

This commit is contained in:
click33 2023-05-16 15:48:44 +08:00
parent b1d2306b7d
commit 5699977f62
3 changed files with 16 additions and 18 deletions

View File

@ -22,14 +22,14 @@ import java.util.regex.Pattern;
public class PathAnalyzer {
private static Map<String, PathAnalyzer> cached = new LinkedHashMap<>();
private Pattern pattern;
private static final Map<String, PathAnalyzer> cached = new LinkedHashMap<>();
private final Pattern pattern;
public static PathAnalyzer get(String expr) {
PathAnalyzer pa = (PathAnalyzer)cached.get(expr);
PathAnalyzer pa = cached.get(expr);
if (pa == null) {
synchronized(expr.intern()) {
pa = (PathAnalyzer)cached.get(expr);
pa = cached.get(expr);
if (pa == null) {
pa = new PathAnalyzer(expr);
cached.put(expr, pa);
@ -41,7 +41,7 @@ public class PathAnalyzer {
}
private PathAnalyzer(String expr) {
this.pattern = Pattern.compile(exprCompile(expr), 2);
this.pattern = Pattern.compile(exprCompile(expr), Pattern.CASE_INSENSITIVE);
}
public Matcher matcher(String uri) {
@ -57,7 +57,7 @@ public class PathAnalyzer {
p = p.replace("$", "\\$");
p = p.replace("**", ".[]");
p = p.replace("*", "[^/]*");
if (p.indexOf("{") >= 0) {
if (p.contains("{")) {
if (p.indexOf("_}") > 0) {
p = p.replaceAll("\\{[^\\}]+?\\_\\}", "(.+?)");
}

View File

@ -37,7 +37,7 @@ import java.util.List;
public class SaRedisCache implements JbootCache {
protected JbootRedisConfig config;
protected JedisPool jedisPool;
private ThreadLocal<String> CACHE_NAME_PREFIX_TL = new ThreadLocal<>();
private final ThreadLocal<String> CACHE_NAME_PREFIX_TL = new ThreadLocal<>();
public SaRedisCache(JbootRedisConfig config) {
this.config = config;
@ -247,7 +247,7 @@ public class SaRedisCache implements JbootCache {
return jedisPool.getResource();
} catch (JedisConnectionException e) {
throw new JbootIllegalConfigException("can not connect to redis host " + config.getHost() + ":" + config.getPort() + " ," +
" cause : " + e.toString(), e);
" cause : " + e, e);
}
}

View File

@ -34,19 +34,19 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* 使用Jboot的缓存方法存取Token数据
*/
@SuppressWarnings({"deprecation", "unchecked", "rawtypes"})
@SuppressWarnings({"unchecked", "rawtypes"})
public class SaTokenCacheDao implements SaTokenDao {
protected SaRedisCache saRedisCache;
protected JbootSerializer serializer;
private Map<String, SaRedisCache> saRedisMap = new ConcurrentHashMap();
private final Map<String, SaRedisCache> saRedisMap = new ConcurrentHashMap();
/**
* 使用默认redis配置
*/
public SaTokenCacheDao() {
JbootRedisConfig config = (JbootRedisConfig) Jboot.config(JbootRedisConfig.class);
JbootRedisConfig config = Jboot.config(JbootRedisConfig.class);
this.saRedisCache = new SaRedisCache(config);
this.serializer = new SaJdkSerializer();
}
@ -57,21 +57,19 @@ public class SaTokenCacheDao implements SaTokenDao {
* @param cacheName 使用的缓存配置名默认为 default
*/
public SaTokenCacheDao(String cacheName) {
SaRedisCache saCache = (SaRedisCache) this.saRedisMap.get(cacheName);
SaRedisCache saCache = this.saRedisMap.get(cacheName);
if (saCache == null) {
synchronized (this) {
saCache = (SaRedisCache) this.saRedisMap.get(cacheName);
saCache = this.saRedisMap.get(cacheName);
if (saCache == null) {
Map<String, JbootRedisConfig> configModels = ConfigUtil.getConfigModels(JbootRedisConfig.class);
if (!configModels.containsKey(cacheName)) {
throw new JbootIllegalConfigException("Please config \"jboot.redis." + cacheName + ".host\" in your jboot.properties.");
}
JbootRedisConfig jbootRedisConfig = (JbootRedisConfig) configModels.get(cacheName);
JbootRedisConfig jbootRedisConfig = configModels.get(cacheName);
saCache = new SaRedisCache(jbootRedisConfig);
if (saCache != null) {
this.saRedisMap.put(cacheName, saCache);
}
this.saRedisMap.put(cacheName, saCache);
}
}
}
@ -271,7 +269,7 @@ public class SaTokenCacheDao implements SaTokenDao {
Jedis jedis = saRedisCache.getJedis();
try {
Set<String> keys = jedis.keys(prefix + "*" + keyword + "*");
List<String> list = new ArrayList<String>(keys);
List<String> list = new ArrayList<>(keys);
return SaFoxUtil.searchList(list, start, size, sortType);
} finally {
saRedisCache.returnResource(jedis);