我有这段代码,就是将 Ojbect 写入字节数组流:
static byte[] toBytes(MyTokens tokens) throws IOException {
ByteArrayOutputStream out = null;
ObjectOutput s = null;
try {
out = new ByteArrayOutputStream();
try {
s = new ObjectOutputStream(out);
s.writeObject(tokens);
} finally {
try {
s.close();
} catch (Exception e) {
throw new CSBRuntimeException(e);
}
}
} catch (Exception e) {
throw new CSBRuntimeException(e);
} finally {
IOUtils.closeQuietly(out);
}
return out.toByteArray();
}
然而,FindBugs 一直在抱怨这一行:
s = new ObjectOutputStream(out);
“可能无法关闭流” - BAD_PRACTICE - OS_OPEN_STREAM。有人可以帮忙吗?