I am mulling over the idea of writing a program to check for "leaky abstractions" in Java. The one area that popped into mind right away is with exceptions:
public class X
{
// this one is fine, Readers throw IOExceptions so it is
// reasonable for the caller to handle it
public void parse(final Reader r)
throws IOException
{
}
// This one is bad. Nothing in the API indicate that JDBC
// is being used at all.
public void process()
throws SQLException
{
}
}
Note, I do not want an argument on relative merits of checked/unchecked exceptions. What I am looking for is other examples (doesn't have to be exception handling) that people have that could also be reasonably caught via examining the source code or class files.
I am aware of checkstyle, findbugs, and PMD, and AFAIK none of them deal with this (and I am not opposed to putting the checks into one of those tools rather than write my own).
Are there any other examples of leaky abstractions that you come to mind that could be statically check for?
EDIT:
The reason why the second one is bad is that the method throws an exception where the client has no way of knowing that JDBC (for example, it could be anything) is being used. So the "leaky abstraction" is that JDBC is being used. If the underlying mechanism changed to soemthing else (say JPA which is a different database abstraction library) then the exceptions would all need to change as well. So the underlying database library is being leaked out.