Skip to content

Commit 682f620

Browse files
committed
Fix NPE on query error path and improve error reporting
1 parent 82532d4 commit 682f620

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

vertx-db2-client/src/main/java/io/vertx/db2client/impl/drda/DRDAQueryResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ private long parseEXCSQLSTTreply(/*StatementCallbackInterface statementI*/) {
548548

549549
//statementI.completeExecute(netSqlca);
550550
NetSqlca.complete(netSqlca);
551-
updateCount = netSqlca.getUpdateCount();
551+
updateCount = netSqlca == null ? 0 : netSqlca.getUpdateCount();
552552
peekCP = peekCodePoint();
553553
} else if (peekCP == CodePoint.SQLDTARD) {
554554
throw new UnsupportedOperationException("stored procedure");

vertx-db2-client/src/main/java/io/vertx/db2client/impl/drda/NetSqlca.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,38 @@ public static void throwSqlError(NetSqlca sqlca) {
112112
if (sqlca == null || sqlca.sqlCode_ == 0) {
113113
return;
114114
}
115+
116+
// Force population of the sqlErrmc
117+
String sqlErrmc = sqlca.getSqlErrmc();
118+
if (sqlErrmc == null || sqlErrmc.trim().length() == 0) {
119+
sqlErrmc = "";
120+
}
121+
115122
// Add additional error messages to this list
116123
switch(sqlca.sqlCode_) {
117124
// The SQL syntax is invalid
118125
case SqlCode.INVALID_SQL_STATEMENT:
119126
throw new DB2Exception("The SQL syntax provided was invalid", SqlCode.INVALID_SQL_STATEMENT, sqlca.sqlState_);
120127
// The object (table?) is not defined/available
121128
case SqlCode.OBJECT_NOT_DEFINED:
122-
if (sqlca.sqlErrmc_ != null && sqlca.sqlErrmc_.trim().length() > 0)
123-
throw new DB2Exception("The object " + sqlca.sqlErrmc_ + " provided is not defined", SqlCode.OBJECT_NOT_DEFINED, sqlca.sqlState_);
129+
if (sqlErrmc.length() > 0)
130+
throw new DB2Exception("The object '" + sqlErrmc + "' provided is not defined", SqlCode.OBJECT_NOT_DEFINED, sqlca.sqlState_);
124131
else
125132
throw new DB2Exception("An object provided is not defined", SqlCode.OBJECT_NOT_DEFINED, sqlca.sqlState_);
126133
// The object (table?) is not defined/available
127134
case SqlCode.COLUMN_DOES_NOT_EXIST:
128-
if (sqlca.sqlErrmc_ != null && sqlca.sqlErrmc_.trim().length() > 0)
129-
throw new DB2Exception("The column " + sqlca.sqlErrmc_ + " provided does not exist", SqlCode.COLUMN_DOES_NOT_EXIST, sqlca.sqlState_);
135+
if (sqlErrmc.length() > 0)
136+
throw new DB2Exception("The column '" + sqlErrmc + "' provided does not exist", SqlCode.COLUMN_DOES_NOT_EXIST, sqlca.sqlState_);
130137
else
131138
throw new DB2Exception("A column provided does not exist", SqlCode.COLUMN_DOES_NOT_EXIST, sqlca.sqlState_);
132139
// Invalid database specified
133140
case SqlCode.DATABASE_NOT_FOUND:
134-
if (sqlca.sqlErrmc_ != null && sqlca.sqlErrmc_.trim().length() > 0)
135-
throw new DB2Exception("The database " + sqlca.sqlErrmc_ + " provided was not found", SqlCode.DATABASE_NOT_FOUND, sqlca.sqlState_);
141+
if (sqlErrmc.length() > 0)
142+
throw new DB2Exception("The database '" + sqlErrmc + "' provided was not found", SqlCode.DATABASE_NOT_FOUND, sqlca.sqlState_);
136143
else
137144
throw new DB2Exception("The database provided was not found", SqlCode.DATABASE_NOT_FOUND, sqlca.sqlState_);
138145
default:
139-
throw new IllegalStateException("ERROR sqlcode=" + sqlca.sqlCode_ + " Full Sqlca: " + sqlca.toString());
146+
throw new IllegalStateException("ERROR: " + sqlca.toString());
140147
}
141148
}
142149

vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2SimpleQueryTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
import org.junit.Before;
2020
import org.junit.ClassRule;
21-
import org.junit.Ignore;
2221
import org.junit.Rule;
23-
import org.junit.Test;
2422
import org.junit.rules.TestName;
2523
import org.junit.runner.RunWith;
2624

@@ -57,11 +55,4 @@ protected void cleanTestTable(TestContext ctx) {
5755
}));
5856
}));
5957
}
60-
61-
@Override
62-
@Test
63-
@Ignore // TODO implement error path handling properly
64-
public void testQueryError(TestContext ctx) {
65-
super.testQueryError(ctx);
66-
}
6758
}

0 commit comments

Comments
 (0)