From: Sebastiaan van Erk <sebster@sebster.com>
To: pgsql-jdbc@postgresql.org
Subject: \0 and IllegalArgumentException
Date: Fri, 29 Oct 2004 11:55:10 +0200
Message-ID: <1099043710.595.50.camel@localhost> (raw)
Hi,
I'm using postgres 7.4 with the latest JDBC driver, and had an insert
statement to insert data as follows
try
{
...
ps.setCharacterStream(1, myStream, myStreamLength);
ps.executeUpdate();
}
catch (SQLException e)
{
...
}
With this I was hoping to catch invalid inserts (with an SQLException),
however I'm getting:
java.lang.IllegalArgumentException: \0 not allowed
which is an UNCHECKED runtime exception, that in no way indicates
(programatically) that the insert failed.
I think very few people would expect a runtime exception on what
essentially amounts to a failed insert. Futhermore, it is very hard to
discover the SOURCE of the runtime exception (lots of things might throw
an IllegalArgumentException) and to programatically do something
sensible with this.
Thus in my opinion, an SQLException would be better here for at least
three reasons:
1) It's a checked exception (I'm counting on it happening)...
2) I will know where it came from (postgres)...
3) Now I'm totally unsure of what other kind of runtime exceptions the
postgres driver may throw for some reason or other, nor do I know how to
handle a runtime exception properly if one does occur... I want runtime
exceptions basically only on PROGRAMMATIC errors, errors that I as the
developer made and can fix. User data CAN in fact contain \0, and the
fact that postgres cannot handle this is an issue of the backend, which
(in the case of postgres, but certainly not in the case of all
databases) does not consider these kind of strings as valid. As the
developer (oblivious to what kind of backend database is used) I cannot
take any programmatic steps to avoid this problem (other than string
scanning caught IllegalArgumentExceptions for this specific problem).
In conclusion, I REALLY think that this is the wrong exception to be
thrown.
Greetings,
Sebastiaan van Erk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: sebster@sebster.com
Subject: Re: \0 and IllegalArgumentException
In-Reply-To: <1099043710.595.50.camel@localhost>
References: <1099043710.595.50.camel@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox