Permalink
Browse files

refactor: remove ClassCastException catch

CopyManager has two catches for ClassCastException. This ins't very
nice and can easily be changed to do a check before the cast.

closes #527
  • Loading branch information...
marschall authored and vlsi committed Mar 3, 2016
1 parent a274321 commit 8bee06be4b9679d880f97dbe68cf9a301dd6c420
Showing with 8 additions and 10 deletions.
  1. +8 −10 pgjdbc/src/main/java/org/postgresql/copy/CopyManager.java
@@ -48,26 +48,24 @@ public CopyManager(BaseConnection connection) throws SQLException {
}
public CopyIn copyIn(String sql) throws SQLException {
CopyOperation op = null;
try {
op = queryExecutor.startCopy(sql, connection.getAutoCommit());
CopyOperation op = queryExecutor.startCopy(sql, connection.getAutoCommit());
if (op == null || op instanceof CopyIn) {
return (CopyIn) op;
} catch (ClassCastException cce) {
} else {
op.cancelCopy();
throw new PSQLException(GT.tr("Requested CopyIn but got {0}", op.getClass().getName()),
PSQLState.WRONG_OBJECT_TYPE, cce);
PSQLState.WRONG_OBJECT_TYPE);
}
}
public CopyOut copyOut(String sql) throws SQLException {
CopyOperation op = null;
try {
op = queryExecutor.startCopy(sql, connection.getAutoCommit());
CopyOperation op = queryExecutor.startCopy(sql, connection.getAutoCommit());
if (op == null || op instanceof CopyOut) {
return (CopyOut) op;
} catch (ClassCastException cce) {
} else {
op.cancelCopy();
throw new PSQLException(GT.tr("Requested CopyOut but got {0}", op.getClass().getName()),
PSQLState.WRONG_OBJECT_TYPE, cce);
PSQLState.WRONG_OBJECT_TYPE);
}
}

0 comments on commit 8bee06b

Please sign in to comment.