println inside catch throwing Nullpointerexception?

O

ohaya

Hi,

We are running a problem with some existing code that was compiled
under JDK 1.42 under 1.50_05, where it looks like the println inside
of a catch is throwing a Nullpointerexception, i.e., we have something
like:

try {
..
..
..
} catch (Exception e) {
println("The error was: " + e);
}

As a test, we added a try inside the catch, surrounding the println,
where we just printed out a fixed msg (i.e., not using the Exception:

try {
..
..
..
} catch (Exception e) {
try {
println("The error was: " + e);
} catch (Exception x){
println("An exception was thrown inside the catch");
}
}

And we did see that "An exception was thrown inside the catch" output.

This problem doesn't occur when we run this same code under an older
JRE, e.g., 1.42.

Has anyone run across this problem before? Is there some known
behavior change with the Exception class or with println that would
cause println to throw an error like that?

Thanks,
jim
 
D

Dundonald

Hi,

We are running a problem with some existing code that was compiled
under JDK 1.42 under 1.50_05, where it looks like the println inside
of a catch is throwing a Nullpointerexception, i.e., we have something
like:

try {
.
.
.} catch (Exception e) {

println("The error was: " + e);
}

As a test, we added a try inside the catch, surrounding the println,
where we just printed out a fixed msg (i.e., not using the Exception:

try {
.
.
.} catch (Exception e) {

try {
println("The error was: " + e);
} catch (Exception x){
println("An exception was thrown inside the catch");
}
}

And we did see that "An exception was thrown inside the catch" output.

This problem doesn't occur when we run this same code under an older
JRE, e.g., 1.42.

Has anyone run across this problem before? Is there some known
behavior change with the Exception class or with println that would
cause println to throw an error like that?

First of all it's not idea to be banging an exception object in to a
String output stream.

Why don't you try something like

println("The error was: " + e.toString());
 
L

Lew

Hi,

We are running a problem with some existing code that was compiled
under JDK 1.42 under 1.50_05, where it looks like the println inside
of a catch is throwing a Nullpointerexception, i.e., we have something
like:

try {
..
..
..
} catch (Exception e) {
println("The error was: " + e);
}

As a test, we added a try inside the catch, surrounding the println,
where we just printed out a fixed msg (i.e., not using the Exception:

try {
..
..
..
} catch (Exception e) {
try {
println("The error was: " + e);
} catch (Exception x){
println("An exception was thrown inside the catch");
}
}

And we did see that "An exception was thrown inside the catch" output.

This problem doesn't occur when we run this same code under an older
JRE, e.g., 1.42.

Has anyone run across this problem before? Is there some known
behavior change with the Exception class or with println that would
cause println to throw an error like that?

There is no change in Exception or in try...catch, so the problem must be
elsewhere.

I note that you have not captured any information about the Exception that
would help diagnose it. Why is that?

What is the type of the Exception? What is its message (as in e.getMessage())?
 
L

Lew

Dundonald said:
First of all it's not idea to be banging an exception object in to a
String output stream.

Why don't you try something like

println("The error was: " + e.toString());

This is semantically identical to
println("The error was: " + e );

No difference at all, since String concatenation is defined to invoke the
toString() method of a (non-null) non-String argument.
<http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#39990>

More useful would be to deliver the e.getMessage() and to identify the type of
e itself.
 
L

Lew

Incidentally, what println() method is this? You don't show us enough of the
class to see how println() is defined. Undoubtedly the error is in the
implementation of the println() method.

Inevitably, the problem is in the part of the code that you don't show, unless
you provide an SSCCE:
<http://www.physci.org/codes/sscce.html>

Please provide an SSCCE.
 
O

ohaya

Incidentally, what println() method is this? You don't show us enough of the
class to see how println() is defined. Undoubtedly the error is in the
implementation of the println() method.

Inevitably, the problem is in the part of the code that you don't show, unless
you provide an SSCCE:
<http://www.physci.org/codes/sscce.html>

Please provide an SSCCE.


Hi,

Sorry, I am trying to help out a colleague with this problem. Here's
a (hopefully) more complete snippet which I got:

try
{ // outer try
System.out.println("Connecting to [" + dsType + "] server: [" + dsHost
+ ":" + ("" + dsPort) + "]");
ld.connect(dsHost, dsPort);

LDAPSearchResults results = ld.search(baseDN, searchScope,
searchFilter, getAttributes, false);

if (!results.hasMoreElements())
{
return "";
}

while (results.hasMoreElements()) // loop, looking for all
returned entities
{
LDAPEntry findEntry = null;
try
{ // inner try
findEntry = results.next(); // get next entity returned by
LDAP server
LDAPAttribute attribute = findEntry.getAttribute(dsUserAtr);
Enumeration enumValues = attribute.getStringValues(); // put
attribute values into an Enumeration
if (!enumValues.hasMoreElements())
{
System.out.println("** ERROR **: enumValues.hasMoreElements() is
false ==> found match to certificate Subject and found desired
attribute, but attribute had no values...");
System.out.println("** ERROR **: -> So, will now return
indication that authentication failed...");
return "";
}
returnString = (String)enumValues.nextElement(); // move 1st
attribute value into returnString
numMatches++; // increment count of matches for this search
System.out.println("found match, returned string #(" + numMatches +
") = [" + returnString + "]");
} // end inner try
catch (LDAPReferralException e)
{
System.out.println("LDAP search failed ...");
System.out.println("LDAPReferralException = [" + e + "]"); <<--We
think Nullpointerexception being thrown here...
return "";
}
} // end while
System.out.println("LDAP search found [" + numMatches + "]
matches");
System.out.println("Disconnecting from LDAP server");
ld.disconnect();
} // end outer try
catch (LDAPException e)
{
System.out.println("** ERROR **: Failed ...");
System.out.println("** ERROR **: -> LDAPException = [" + e +
"]");
return "";
}
 
L

Lew

Sorry, I am trying to help out a colleague with this problem. Here's
a (hopefully) more complete snippet which I got:

Not an SSCCE. Read the link.

Please do not embed TAB characters in Usenet listing.

Please provide an SSCCE.
 
L

Lew

catch (LDAPReferralException e)
{
System.out.println("LDAP search failed ...");
System.out.println("LDAPReferralException = [" + e + "]"); <<--We
think Nullpointerexception being thrown here...

Unlikely. But we won't be able to tell until you answer the three questions I
asked earlier about the exception, along with at least the first few lines of
the stack trace.

You're aware that the exception message tells what's wrong and the stack trace
tells where, right?
 
A

Andreas Leitgeb

Inevitably, the problem is in the part of the code that you don't show, unless
you provide an SSCCE:
<http://www.physci.org/codes/sscce.html>
Please provide an SSCCE.
catch (LDAPReferralException e)
{
System.out.println("LDAP search failed ...");
System.out.println("LDAPReferralException = [" + e + "]"); <<--We think Nullpointerexception being thrown here...
return "";
}

You could find out more about it if you had a closer look at the
stack-dump that comes with the nullpointerexception.
It should tell you, where the exception really happened.

It's quite impossible, that e itself was null, but theoretically, the
exception's .toString() implementation could also be the culprit
(e.g. trying to use some internal null-value)

Is the LDAPReferralException from some library or your own creation?
If the latter, did you overwrite its .toString() and did you perhaps
unconditionally use the rootCause-element inside it?
 
M

Martin Gregorie

Dundonald said:
First of all it's not idea to be banging an exception object in to a
String output stream.

Why don't you try something like

println("The error was: " + e.toString());
I normally use println("The error is: " + e.getMessage()); except when
the String returned by getMessage() is empty or meaningless, which is
the case in a minority of cases. The ClassNotFoundException thrown by
Class.forName() is one where getMessage() returns an empty String and
you end up building your own error message.
 
O

ohaya

Inevitably, the problem is in the part of the code that you don't show, unless
you provide an SSCCE:
<http://www.physci.org/codes/sscce.html>
Please provide an SSCCE.
catch (LDAPReferralException e)
{
System.out.println("LDAP search failed ...");
System.out.println("LDAPReferralException = [" + e + "]"); <<--We think Nullpointerexception being thrown here...
return "";
}

You could find out more about it if you had a closer look at the
stack-dump that comes with the nullpointerexception.
It should tell you, where the exception really happened.

It's quite impossible, that e itself was null, but theoretically, the
exception's .toString() implementation could also be the culprit
(e.g. trying to use some internal null-value)

Is the LDAPReferralException from some library or your own creation?
If the latter, did you overwrite its .toString() and did you perhaps
unconditionally use the rootCause-element inside it?


Andreas (and Lew),

We're not getting a stack trace :(, otherwise I'd have posted some of
it (we can't get files directly off of this system).

Also, FYI, the LDAPReferralException is from the LDAP JDK
(ldapjdk.jar), and we compared the ldapjdk.jar files from the system
where this is working vs. this system, and they're byte-for-byte the
same.

Jim
 
O

ohaya

catch (LDAPReferralException e)
{
System.out.println("LDAP search failed ...");
System.out.println("LDAPReferralException = [" + e + "]"); <<--We
think Nullpointerexception being thrown here...

Unlikely. But we won't be able to tell until you answer the three questions I
asked earlier about the exception, along with at least the first few lines of
the stack trace.

You're aware that the exception message tells what's wrong and the stack trace
tells where, right?

Lew,

The reason that we think that that is where the problem is occurring
is that we see the output line:

LDAP search failed ...

But we don't see an output line like:

LDAPReferralException = [xxxxxxxxxxxxxxxx]

after that...

Jim
 
L

Lew

catch (LDAPReferralException e)
{
System.out.println("LDAP search failed ...");
System.out.println("LDAPReferralException = [" + e + "]"); <<--We
think Nullpointerexception being thrown here...
Unlikely. But we won't be able to tell until you answer the three questions I
asked earlier about the exception, along with at least the first few lines of
the stack trace.

You're aware that the exception message tells what's wrong and the stack trace
tells where, right?

The reason that we think that that is where the problem is occurring
is that we see the output line:

LDAP search failed ...

But we don't see an output line like:

LDAPReferralException = [xxxxxxxxxxxxxxxx]

after that...

How does this indicate a NullPointerException?
We're not getting a stack trace :( , otherwise I'd have posted some of
it (we can't get files directly off of this system).

Huh? Don't you control the code that catches the exception? Have it print a
stack trace as part of its message, along with the e.getMessage() output.

If you don't answer our questions, we aren't able to answer yours.

Good luck.
 
R

RedGrittyBrick

Inevitably, the problem is in the part of the code that you don't show, unless
you provide an SSCCE:
<http://www.physci.org/codes/sscce.html>
Please provide an SSCCE.

catch (LDAPReferralException e)
{
System.out.println("LDAP search failed ...");
System.out.println("LDAPReferralException = [" + e + "]"); <<--We think Nullpointerexception being thrown here...
return "";
}

You could find out more about it if you had a closer look at the
stack-dump that comes with the nullpointerexception.
It should tell you, where the exception really happened.

It's quite impossible, that e itself was null, but theoretically, the
exception's .toString() implementation could also be the culprit
(e.g. trying to use some internal null-value)

Is the LDAPReferralException from some library or your own creation?
If the latter, did you overwrite its .toString() and did you perhaps
unconditionally use the rootCause-element inside it?

We're not getting a stack trace :(, otherwise I'd have posted some of
it (we can't get files directly off of this system).

Also, FYI, the LDAPReferralException is from the LDAP JDK
(ldapjdk.jar), and we compared the ldapjdk.jar files from the system
where this is working vs. this system, and they're byte-for-byte the
same.

After
catch (LDAPReferralException e)
{
Can you not insert
e.printStackTrace();
System.out.println(e.getMessage());
?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top