cleanup code with findbugs plugin

This commit is contained in:
jinyu
2015-07-14 17:03:11 +08:00
parent 9c5c411587
commit 7ca050e952
15 changed files with 63 additions and 53 deletions
@@ -1,6 +1,5 @@
package com.foxinmy.weixin4j.api;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -50,21 +49,15 @@ public abstract class BaseApi {
/**
* 默认使用weixin4j.properties文件中的公众号信息
*/
public static WeixinAccount DEFAULT_WEIXIN_ACCOUNT;
public final static WeixinAccount DEFAULT_WEIXIN_ACCOUNT;
/**
* 默认token使用File的方式存储
*/
public static TokenStorager DEFAULT_TOKEN_STORAGER;
public final static TokenStorager DEFAULT_TOKEN_STORAGER;
static {
try {
DEFAULT_WEIXIN_ACCOUNT = ConfigUtil.getWeixinAccount();
} catch (MissingResourceException e) {
System.err
.println("'account' key not found in weixin4j.properties file.");
; // error
}
DEFAULT_WEIXIN_ACCOUNT = ConfigUtil.getWeixinAccount();
DEFAULT_TOKEN_STORAGER = new FileTokenStorager(ConfigUtil.getValue(
"token_path", Weixin4jConst.DEFAULT_TOKEN_PATH));
}
@@ -4,10 +4,11 @@ import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Calendar;
@@ -331,10 +332,9 @@ public class Pay3Api {
BufferedReader reader = null;
BufferedWriter writer = null;
FileWriter fw = null;
try {
fw = new FileWriter(file);
writer = new BufferedWriter(fw);
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(file), Consts.GBK));
reader = new BufferedReader(new InputStreamReader(
new ByteArrayInputStream(response.getContent()),
com.foxinmy.weixin4j.model.Consts.GBK));
@@ -352,7 +352,6 @@ public class Pay3Api {
}
if (writer != null) {
writer.close();
fw.close();
}
} catch (IOException ignore) {
;
@@ -16,7 +16,7 @@ public class StringEntity implements HttpEntity {
}
public StringEntity(String body, ContentType contentType) {
this.content = body.getBytes();
this.content = body.getBytes(contentType.getCharset());
this.contentType = contentType;
}
@@ -1,5 +1,6 @@
package com.foxinmy.weixin4j.payment.mch;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@@ -229,7 +230,10 @@ public class RedpacketRecord extends XmlResult {
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public static class RedpacketReceiver {
public static class RedpacketReceiver implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 领取红包的Openid
*/
@@ -99,7 +99,15 @@ public class ConfigUtil {
}
public static WeixinAccount getWeixinAccount() {
String text = getValue("account");
return JSON.parseObject(text, WeixinAccount.class);
WeixinAccount account = null;
try {
String text = getValue("account");
account = JSON.parseObject(text, WeixinAccount.class);
} catch (MissingResourceException e) {
System.err
.println("'account' key not found in weixin4j.properties file.");
; // error
}
return account;
}
}
@@ -148,11 +148,10 @@ public class ObjectId implements Comparable<ObjectId>, java.io.Serializable {
public boolean equals(Object o) {
if (this == o)
return true;
ObjectId other = (ObjectId) o;
if (other == null)
if (!(o instanceof ObjectId)) {
return false;
}
ObjectId other = (ObjectId) o;
return _time == other._time && _machine == other._machine
&& _inc == other._inc;
}
@@ -310,8 +309,7 @@ public class ObjectId implements Comparable<ObjectId>, java.io.Serializable {
}
ClassLoader loader = ObjectId.class.getClassLoader();
int loaderId = loader != null
? System.identityHashCode(loader)
int loaderId = loader != null ? System.identityHashCode(loader)
: 0;
StringBuilder sb = new StringBuilder();
@@ -74,7 +74,11 @@ public class ListsuffixResultDeserializer {
T t = XmlStream.fromXML(content, clazz);
Map<Field, String[]> listsuffixFields = getListsuffixFields(clazz);
if (!listsuffixFields.isEmpty()) {
for (Field field : listsuffixFields.keySet()) {
Iterator<Entry<Field, String[]>> it = listsuffixFields.entrySet()
.iterator();
while (it.hasNext()) {
Entry<Field, String[]> entry = it.next();
Field field = entry.getKey();
Type type = field.getGenericType();
Class<?> wrapperClazz = null;
if (type instanceof ParameterizedType) {
@@ -84,7 +88,7 @@ public class ListsuffixResultDeserializer {
continue;
}
ListWrapper<?> listWrapper = deserializeToListWrapper(content,
wrapperClazz, listsuffixFields.get(field));
wrapperClazz, entry.getValue());
if (listWrapper != null) {
try {
field.setAccessible(true);