Re: NPE in creating a SQLException - Mailing list pgsql-jdbc

From Scot P. Floess
Subject Re: NPE in creating a SQLException
Date
Msg-id 5331495.1059493858253.JavaMail.nobody@wamui01.slb.atl.earthlink.net
Whole thread Raw
In response to NPE in creating a SQLException  (Peter Royal <proyal@pace2020.com>)
Responses Re: NPE in creating a SQLException
List pgsql-jdbc
Peter:

Does your class have a toString() method?  You mention that this is occurring in a constructor.  Certainly if your
toString()has object members being printed in such a way as method calls are performed on those object prior to their
beingset to instances there could be issue (ie NullPointerException).  However, assuming this to be true, one would
hopethe stack trace would indicate the toString() method. 

Have you tried to evaluate "this" first...ie if ( this == null ) { do something }

If tried the following:

public final class NullTest
{
    public NullTest ()
    {
        System.out.println ( this == null );
    }

    public static void main ( String args[] )
    {
        NullTest nt = new NullTest ();
    }
}

I get "false" printed.

I would be very suprised if "this" ever equaled null...

Can you send the whole class source in question?

Scot

-------Original Message-------
From: Peter Royal <proyal@pace2020.com>
Sent: 07/29/03 11:26 AM
To: "Scot P. Floess" <floess@mindspring.com>
Subject: Re: [JDBC] NPE in creating a SQLException

>
> On Tuesday, July 29, 2003, at 11:17  AM, Scot P. Floess wrote:
> Can you send more code?  Is "s" initialized in your synchronized
> block?  You might print s before the synchronized block to verify...
> It could be your null pointer is there...

Sorry I didn't include more.. This is with JVM 1.4.1, so all the java.*
stuff is the standard source for that.

>>
>> I'm getting the below NPE:
>
> java.lang.NullPointerException
>          at java.io.PrintWriter.write(PrintWriter.java:247)
>          at java.io.PrintWriter.print(PrintWriter.java:392)
>          at java.io.PrintWriter.println(PrintWriter.java:529)
>          at java.lang.Throwable.printStackTrace(Throwable.java:509)
>          at java.sql.SQLException.<init>(SQLException.java:103)
>          at
> org.postgresql.util.PSQLException.<init>(PSQLException.java:19)
>          at
> org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Conne
> c
> tion.java:480)
>          at
> org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Conne
> c
> tion.java:461)
>          at
> org.postgresql.jdbc1.AbstractJdbc1Connection.setAutoCommit(AbstractJdbc
> 1
> Connection.java:942)
>
> The offense starts here (SQLException:103)
>
>           if (!(this instanceof SQLWarning)) {
>               if (DriverManager.getLogWriter() != null) {
>                     printStackTrace(DriverManager.getLogWriter());
>               }
>           }
>
> And then continues on to (Throwable:509)
>
>          synchronized (s) {
>              s.println(this);
>              StackTraceElement[] trace = getOurStackTrace();

Which is fully:

     public void printStackTrace(PrintWriter s) {
         synchronized (s) {
             s.println(this);
             StackTraceElement[] trace = getOurStackTrace();
             for (int i=0; i < trace.length; i++)
                 s.println("\tat " + trace[i]);

             Throwable ourCause = getCause();
             if (ourCause != null)
                 ourCause.printStackTraceAsCause(s, trace);
         }
     }

> It is the "s.println(this)" that is causing errors... All of this is
> happening in the constructor, so I guess that is why 'this' is null?
> I'm not 100% sure and pretty confused by it all :/

But 'this' is null.... which is very weird to me.
-pete

>

pgsql-jdbc by date:

Previous
From: Peter Royal
Date:
Subject: Re: NPE in creating a SQLException
Next
From: Peter Royal
Date:
Subject: Re: NPE in creating a SQLException