Dear Cassandra developers, we are developing a tool to detect
exception-related bugs in Java. Our prototype has spotted the following
throw statement whose exception class and error message indicate different
error conditions.



Version: Cassandra-3.11 (commit: 123113f7b887370a248669ee0db6fdf13df0146e)

File:
CASSANDRA-ROOT/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java

Line: 225

File[] files = new File(dir).listFiles();
if (files == null)
{
    throw new RuntimeException("Unable to list directory " + dir);
}


RuntimeException is usually used to represent errors in the program logic
(think of one of its subclasses, NullPointerException), while the error
message indicates that maybeRestoreArchive() failed to list a directory.
This mismatch could be a problem. For example, the callers may miss the
possibility that maybeRestoreArchive() can fail to list a directory because
it does not throw any IOException. Or, the callers trying to handle other
RuntimeException may accidentally (and incorrectly) handle the
directory listing failure.


Do you think this is a bug?


Thanks!

Reply via email to