db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jose de Castro" <jose.decas...@voxeo.com>
Subject NPE in setTimestamp(int,Timestamp,Calendar)
Date Wed, 01 Nov 2006 20:25:13 GMT
A NullPointerException occurs if you pass in a null Timestamp into
org.apache.derby.client.am.PreparedStatement.setTimestamp(int,Timestamp,Cale
ndar)

 

Does anyone know if this is being addressed in 10.3? I have included a
suggested fix. Is this something I should add to JIRA?

 

    public void setTimestamp(int parameterIndex,

                             java.sql.Timestamp x,

                             java.util.Calendar calendar) throws
SQLException {

        try

        {

            synchronized (connection_) {

                if (agent_.loggingEnabled()) {

                    agent_.logWriter_.traceEntry(this, "setTimestamp",
parameterIndex, x, calendar);

                }

                checkForClosedStatement();

+               if (x == null) {

+                 setTimestamp(parameterIndex,null);

+               }

+               else {

                       if (calendar == null) {

                           throw new SqlException(agent_.logWriter_, 

                               new
ClientMessageId(SQLState.INVALID_API_PARAMETER),

                               "null", "calendar", "setTimestamp()");

                       }

                       java.util.Calendar targetCalendar =
java.util.Calendar.getInstance(calendar.getTimeZone());

                       targetCalendar.clear();

                       targetCalendar.setTime(x);

                       java.util.Calendar defaultCalendar =
java.util.Calendar.getInstance();

                       defaultCalendar.clear();

                       defaultCalendar.setTime(x);

                       long timeZoneOffset =

 
targetCalendar.get(java.util.Calendar.ZONE_OFFSET) -
defaultCalendar.get(java.util.Calendar.ZONE_OFFSET) +

 
targetCalendar.get(java.util.Calendar.DST_OFFSET) -
defaultCalendar.get(java.util.Calendar.DST_OFFSET);

                       java.sql.Timestamp adjustedTimestamp =
((timeZoneOffset == 0) || (x == null)) ? x : new
java.sql.Timestamp(x.getTime() + timeZoneOffset);

                       if (x != null) {

                           adjustedTimestamp.setNanos(x.getNanos());

                       }

                       setTimestamp(parameterIndex, adjustedTimestamp);

+                }

            }

        }

        catch ( SqlException se )

        {

            throw se.getSQLException();

        }

    }  


Mime
View raw message