Low Priority: Harmless but useless code in AbstractJdbc1Statement.setObject??? - Mailing list pgsql-jdbc

From Jeroen Habets
Subject Low Priority: Harmless but useless code in AbstractJdbc1Statement.setObject???
Date
Msg-id LHEKIEALPFANFIKAIAPJGELDCLAA.Jeroen@twofoldmedia.com
Whole thread Raw
Responses Re: Low Priority: Harmless but useless code in
List pgsql-jdbc
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

While looking at the PreparedStatement functionality of the
postgresql driver I ran in
AbstractJdbc1Statement.setObject(int parameterIndex, Object x))
into the following snippet of code.

if (x == null)
{
    int l_sqlType;
    if (x instanceof String)
        l_sqlType = Types.VARCHAR;
    else if (x instanceof BigDecimal)
        l_sqlType = Types.DECIMAL;
    else if (x instanceof Short)
        l_sqlType = Types.SMALLINT;
    else if (x instanceof Integer)
        l_sqlType = Types.INTEGER;
    else if (x instanceof Long)
        l_sqlType = Types.BIGINT;
    else if (x instanceof Float)
        l_sqlType = Types.FLOAT;
    else if (x instanceof Double)
        l_sqlType = Types.DOUBLE;
    else if (x instanceof byte[])
        l_sqlType = Types.BINARY;
    else if (x instanceof java.sql.Date)
        l_sqlType = Types.DATE;
    else if (x instanceof Time)
        l_sqlType = Types.TIME;
    else if (x instanceof Timestamp)
        l_sqlType = Types.TIMESTAMP;
    else if (x instanceof Boolean)
        l_sqlType = Types.OTHER;
    else
        l_sqlType = Types.OTHER;

    setNull(parameterIndex, l_sqlType);
    return ;
}

According to my O'Reilly Java Language Reference, x instanceof
<Type>, where x == null will always return false...am I overlooking
something?

I tested it using the following class:

/**
 * test class for 'x instanceof <Class>' where x is null
 */
public class InstanceOf {
    public static void main(String[] args) {

        Object x = null;

        System.out.println("x instanceof Object: "+(x instanceof Object));
        System.out.println("x instanceof String: "+(x instanceof String));
        System.out.println("x instanceof Integer: "+(x instanceof
Integer));

    }
}

With java version "1.4.1_01" I get:

$ java InstanceOf
x instanceof Object: false
x instanceof String: false
x instanceof Integer: false

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPoAgA/IWL7P9qCbyEQKevQCgwTUiGCmM8h+Bqmz7OZRlj/rAEZ4AmwY3
fUmH1CLmMNXfmrChdFn/qtne
=Ndff
-----END PGP SIGNATURE-----


pgsql-jdbc by date:

Previous
From: "Jeroen Habets"
Date:
Subject: Patch AbstractJdbc1Statement.setBoolean support BIT and INTEGER columns
Next
From: Dave Cramer
Date:
Subject: Re: Patch AbstractJdbc1Statement.setBoolean support BIT and