X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9F4FD3A4AAF for ; Fri, 29 Oct 2004 10:57:52 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46480-08 for ; Fri, 29 Oct 2004 09:57:45 +0000 (GMT) Received: from mail.profdata.nl (server.profdata.nl [213.196.2.244]) by svr1.postgresql.org (Postfix) with SMTP id 6FA433A4AA9 for ; Fri, 29 Oct 2004 10:57:44 +0100 (BST) Received: (qmail 34425 invoked from network); 29 Oct 2004 09:57:43 -0000 Received: from unknown (HELO ?10.0.0.6?) (62.221.227.121) by server.profdata.nl with SMTP; 29 Oct 2004 09:57:42 -0000 Subject: \0 and IllegalArgumentException From: Sebastiaan van Erk To: pgsql-jdbc@postgresql.org Content-Type: text/plain Message-Id: <1099043710.595.50.camel@localhost> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Fri, 29 Oct 2004 11:55:10 +0200 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/300 X-Sequence-Number: 11405 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