Skip to content

Commit

Permalink
Revert try-with-resources for BufferedReader
Browse files Browse the repository at this point in the history
Reverting try-with-resources for BufferedReader since it gets closed before the query executes, causing a Stream closed error. Fixes: wso2#3985
  • Loading branch information
DedunuKarunarathne committed Feb 19, 2025
1 parent 36dc5cc commit 18e12e3
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1683,24 +1683,20 @@ private void setClobValue(int queryType, String paramName,
if (value == null) {
sqlQuery.setNull(i + 1, Types.CLOB);
} else {
try (BufferedReader reader = new BufferedReader(new StringReader(value))) {
sqlQuery.setClob(i + 1, reader, value.length());
} catch (IOException e) {
throw new DataServiceFault(e, "Error processing parameter: " + paramName
+ ", Error: " + e.getMessage());
}
// Use of Try-with-resources is removed since it causes "Stream closed" error.
// The JDBC driver will handle closing the stream after reading the data.
sqlQuery.setClob(i + 1, new BufferedReader(new StringReader(value)),
value.length());
}
} else if ("INOUT".equals(paramType)) {
if (value == null) {
((CallableStatement) sqlQuery).setNull(i + 1,
Types.CLOB);
} else {
try (BufferedReader reader = new BufferedReader(new StringReader(value))) {
((CallableStatement) sqlQuery).setClob(i + 1, reader, value.length());
} catch (IOException e) {
throw new DataServiceFault(e, "Error processing parameter: " + paramName + ", Error: "
+ e.getMessage());
}
// Use of Try-with-resources is removed since it causes "Stream closed" error.
// The JDBC driver will handle closing the stream after reading the data.
((CallableStatement) sqlQuery).setClob(i + 1,
new BufferedReader(new StringReader(value)), value.length());
}
((CallableStatement) sqlQuery).registerOutParameter(i + 1,
Types.CLOB);
Expand Down

0 comments on commit 18e12e3

Please sign in to comment.