修复 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 { public class PathAnalyzer {
private static Map<String, PathAnalyzer> cached = new LinkedHashMap<>(); private static final Map<String, PathAnalyzer> cached = new LinkedHashMap<>();
private Pattern pattern; private final Pattern pattern;
public static PathAnalyzer get(String expr) { public static PathAnalyzer get(String expr) {
PathAnalyzer pa = (PathAnalyzer)cached.get(expr); PathAnalyzer pa = cached.get(expr);
if (pa == null) { if (pa == null) {
synchronized(expr.intern()) { synchronized(expr.intern()) {
pa = (PathAnalyzer)cached.get(expr); pa = cached.get(expr);
if (pa == null) { if (pa == null) {
pa = new PathAnalyzer(expr); pa = new PathAnalyzer(expr);
cached.put(expr, pa); cached.put(expr, pa);
@ -41,7 +41,7 @@ public class PathAnalyzer {
} }
private PathAnalyzer(String expr) { 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) { public Matcher matcher(String uri) {
@ -57,7 +57,7 @@ public class PathAnalyzer {
p = p.replace("$", "\\$"); p = p.replace("$", "\\$");
p = p.replace("**", ".[]"); p = p.replace("**", ".[]");
p = p.replace("*", "[^/]*"); p = p.replace("*", "[^/]*");
if (p.indexOf("{") >= 0) { if (p.contains("{")) {
if (p.indexOf("_}") > 0) { if (p.indexOf("_}") > 0) {
p = p.replaceAll("\\{[^\\}]+?\\_\\}", "(.+?)"); p = p.replaceAll("\\{[^\\}]+?\\_\\}", "(.+?)");
} }

View File

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