Discussion:
NullPointerException in RemoteDatabaseInterface.ConnectionThread
R***@emc.com
2006-03-08 16:40:37 UTC
Permalink
Hi,

The NPE happens in RemoteDatabaseInterface.ConnectionThread:

java.lang.NullPointerException
at
com.mckoi.database.jdbc.RemoteDatabaseInterface$ConnectionThread.getCommand(
RemoteDatabaseInterface.java:510)
at
com.mckoi.database.jdbc.RemoteDatabaseInterface.execQuery(RemoteDatabaseInte
rface.java:196)
at
com.mckoi.database.jdbc.MConnection.executeQuery(MConnection.java:348)
at
com.mckoi.database.jdbc.MStatement.executeQuery(MStatement.java:110)
at
com.mckoi.database.jdbc.MPreparedStatement.executeUpdate(MPreparedStatement.
java:124)

I think the connection thread finishes and set commands_list to null:

public void run() {
...
finally {
// Invalidate this object when the thread finishes.
Object old_commands_list = commands_list;
synchronized (old_commands_list) {
commands_list = null;
old_commands_list.notifyAll();
}
}
}

I suppose that a different thread is waiting in getCommand(), then it awakes
and goes on with its job but commands_list is null now:

ServerCommand getCommand(int timeout, int dispatch_id) throws SQLException {
final long time_in = System.currentTimeMillis();
final long time_out_high = time_in + ((long) timeout * 1000);

synchronized (commands_list) {
if (commands_list == null) {
throw new SQLException("Connection to server closed");
}

while (true) {

for (int i = 0; i < commands_list.size(); ++i) {
ServerCommand command = (ServerCommand)
commands_list.elementAt(i);
if (command.dispatchID() == dispatch_id) {
commands_list.removeElementAt(i);
return command;
}
}

// Return null if we haven't received a response in the timeout
// period.
if (timeout != 0 &&
System.currentTimeMillis() > time_out_high) {
return null;
}

// Wait a second.
try {
commands_list.wait(1000);
}
catch (InterruptedException e) { /* ignore */ }

} // while (true)

} // synchronized

}

By the way, is there a scheduled next release?

Regards,

Bruno.


---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/
To unsubscribe, send a message to mckoidb-***@mckoi.com
Tobias Downer
2006-03-18 01:54:33 UTC
Permalink
Bruno,

This is actually a case of an incorrectly reported error. The
"Connection to server closed" check needs to be moved into the loop for
the error to be reported correctly. What is causing the error is an
attempt to execute a query on a database connection that is closed at
about the same time.

Thanks for reporting the problem,
Toby.
Post by R***@emc.com
Hi,
java.lang.NullPointerException
at
com.mckoi.database.jdbc.RemoteDatabaseInterface$ConnectionThread.getCommand(
RemoteDatabaseInterface.java:510)
at
com.mckoi.database.jdbc.RemoteDatabaseInterface.execQuery(RemoteDatabaseInte
rface.java:196)
at
com.mckoi.database.jdbc.MConnection.executeQuery(MConnection.java:348)
at
com.mckoi.database.jdbc.MStatement.executeQuery(MStatement.java:110)
at
com.mckoi.database.jdbc.MPreparedStatement.executeUpdate(MPreparedStatement.
java:124)
public void run() {
...
finally {
// Invalidate this object when the thread finishes.
Object old_commands_list = commands_list;
synchronized (old_commands_list) {
commands_list = null;
old_commands_list.notifyAll();
}
}
}
I suppose that a different thread is waiting in getCommand(), then it awakes
ServerCommand getCommand(int timeout, int dispatch_id) throws SQLException {
final long time_in = System.currentTimeMillis();
final long time_out_high = time_in + ((long) timeout * 1000);
synchronized (commands_list) {
if (commands_list == null) {
throw new SQLException("Connection to server closed");
}
while (true) {
for (int i = 0; i < commands_list.size(); ++i) {
ServerCommand command = (ServerCommand)
commands_list.elementAt(i);
if (command.dispatchID() == dispatch_id) {
commands_list.removeElementAt(i);
return command;
}
}
// Return null if we haven't received a response in the timeout
// period.
if (timeout != 0 &&
System.currentTimeMillis() > time_out_high) {
return null;
}
// Wait a second.
try {
commands_list.wait(1000);
}
catch (InterruptedException e) { /* ignore */ }
} // while (true)
} // synchronized
}
By the way, is there a scheduled next release?
Regards,
Bruno.
---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/
To unsubscribe, send a message to mckoidb-***@mckoi.com

Loading...