Fixed: Fix Default or Empty Catch block in Java and Groovy files

(OFBIZ-8341)

In many Java and Groovy files we have auto generated catch blocks or empty catch 
blocks. 
To avoid such exception swallowing this should be improved to at least log the 
error and also return error in case of service.

Here we use 3 try-with-ressource blocks and log some errors

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1866957 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2019-09-15 06:32:42 +00:00
parent 73ebcfb095
commit 28dfdf5c2e
7 changed files with 31 additions and 38 deletions
@@ -192,19 +192,11 @@ public abstract class JdbcValueHandler<T> {
protected static byte[] serializeObject(Object obj) throws SQLException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(os);
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(obj);
os.close();
} catch (IOException e) {
throw new SQLException(e);
} finally {
if (oos != null) {
try {
oos.close();
} catch (IOException e) {}
}
}
return os.toByteArray();
}
@@ -448,9 +440,8 @@ public abstract class JdbcValueHandler<T> {
if (clob == null || clob.length() == 0) {
return null;
}
Reader clobReader = null;
try {
clobReader = clob.getCharacterStream();
try (Reader clobReader = clob.getCharacterStream()) {
int clobLength = (int) clob.length();
char[] charBuffer = new char[clobLength];
int offset = 0;
@@ -466,13 +457,6 @@ public abstract class JdbcValueHandler<T> {
} catch (IOException e) {
throw new SQLException(e);
}
finally {
if (clobReader != null) {
try {
clobReader.close();
} catch (IOException e) {}
}
}
}
@Override
protected JdbcValueHandler<Object> newInstance(int sqlType) {
@@ -627,9 +611,8 @@ public abstract class JdbcValueHandler<T> {
@Override
public Object getValue(ResultSet rs, int columnIndex) throws SQLException {
ObjectInputStream in = null;
InputStream bis = null;
try {
bis = rs.getBinaryStream(columnIndex);
try (InputStream bis = rs.getBinaryStream(columnIndex)) {
if (bis == null) {
return null;
}
@@ -641,12 +624,9 @@ public abstract class JdbcValueHandler<T> {
if (in != null) {
try {
in.close();
} catch (IOException e) {}
}
if (bis != null) {
try {
bis.close();
} catch (IOException e) {}
} catch (IOException e) {
Debug.logError(e, module);
}
}
}
}