jump to navigation

Spot the bug… October 28, 2009

Posted by Phill in Other Stuff.
Tags: , ,
comments closed

Have you ever written something really stupid but not noticed it for ages?

Witness this statement of mine I wrote a month or so ago. The point of the code is to append a prefix to an existing description, or the empty string if the description is null.

description = prefix + " " + description == null ? "" : description;

Can you spot the error?

It turns out that Java was looking at this statement like this:

description = (prefix + " " + description) == null ? "" : description;

D’oh! Not what I intended! I changed the statement to put brackets round the description == null ternary statement and it seems to work.

Just goes to show, brackets are generally a good idea when making statements like this – it’s too easy to make mistakes with operator precedence otherwise!

Java, LDAP and Active Directory April 20, 2009

Posted by Phill in Other Stuff.
Tags: , ,
comments closed

I was trying to connect up to a Microsoft Active Directory server using Jxplorer. I kept getting the error message:

LdapErr: DSID-0C090334, comment: AcceptSecurityContext error

It seems that in the “User DN” field I was entering the username. This doesn’t work. Instead, you must use the fully qualified name, i.e. username@domain.com.

Just a quick post, hopefully this will be useful to someone else!