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

极少数情况下会出现NumberFormatException #44

Open
hi-lay opened this issue Aug 21, 2019 · 1 comment
Open

极少数情况下会出现NumberFormatException #44

hi-lay opened this issue Aug 21, 2019 · 1 comment

Comments

@hi-lay
Copy link

hi-lay commented Aug 21, 2019

昨天发现NumberFormatException这个异常,定位到判断时候过期的判断,但是缓存的数据并没有设置过期时间,但是刚好缓存的数据包含‘-’,查看那一段代码,是截取前13位字符,判断是不是时间的,然后转化为时间的,所以这里会有一个问题就是,极少数情况下,刚好string中包含,“-”,有同时满足后面有一个“ ”空格,就满足indexOf(data, mSeparator),这一个string就会被错认为一个包含过期时间的字段,然后转化时间就会报错,所以过期时间的判断有点不严谨,会有这种情况的出现,虽然很少很少,建议转化加一个try catch,可以解决

@hi-lay
Copy link
Author

hi-lay commented Aug 22, 2019

/***
* 解析过期时间
* @param data
* @return
* 此处处理hasDateInfo() 当[13] = '-'并且刚好后面还有空格‘ ’,就满足了包含时间的判断,转为就会出错
*/
private static boolean hasDateInfo(byte[] data) {
if(data != null && data.length > 15 && data[13] == '-'
&& indexOf(data, mSeparator) > 14){
try{
String saveDate = new String(copyOfRange(data, 0, 13));
Long.valueOf(saveDate);
return true;
}catch (Exception e){ }
}
return false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant