james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter M. Goldstein" <peter_m_goldst...@yahoo.com>
Subject RE: String.equalsIgnoreCase Considered Evil :-)
Date Mon, 05 Aug 2002 15:28:17 GMT

Dan,

Actually this isn't any safer.  The trim() doesn't return null, so
command would only be null if commandRaw were null, which would've
triggered a NullPointerException.

Your point about the use of repeated String literals (or magic strings
as I usually call them) is well taken.  There will be some reordering
and redefinition of these constants in the near future. 

--Peter

> -----Original Message-----
> From: Rollo, Dan [mailto:drollo@ets.org]
> Sent: Monday, August 05, 2002 7:13 AM
> To: 'James Developers List'
> Subject: RE: String.equalsIgnoreCase Considered Evil :-)
> 
> Isn't it safer to do:
> 
> String command = commandRaw.trim().toUpperCase();
> if ("USER".equals(command)) ...
> 
> This way, you avoid NullPointerExceptions if "command" is null.
> Also, shouldn't any repeated literals be declared as constants, ie:
> CmdConst.USER or something similar?
> 
> Dan
> 
> -----Original Message-----
> From: Noel J. Bergman [mailto:noel@devtech.com]
> Sent: Saturday, August 03, 2002 11:59 PM
> To: James-Dev Mailing List
> Subject: String.equalsIgnoreCase Considered Evil :-)
> 
> 
> There are many places in James where we have lengthy sets of
comparisons
> of
> an unknown string value to a known string value.  These are many of
these
> of
> the form:
> 
> 	string.equalsIgnoreCase(<literal>)
> 
> This use is terribly inefficient.  Each and every call iterates
through
> both
> the string and the literal, uppercasing both as it compares them.
> 
> Please, as you are working on code (Peter will apply these to
POP3Handler
> and SMTPHandler), if you see this pattern, please change it to:
> 
> 	string = string.to[Upper|Lower]Case();  // chose depending upon
your
> literals
> 
> 	string.equals(<literal>)
> 
> For example, in SMTPHandler and POP3Handler:
> 
>       String command = commandRaw.trim();
>  becomes
> 	String command = commandRaw.trim().toUpperCase();
> 
> and the test for "USER" (for example) becomes:
> 
>         if (command.equals("USER")) ...
> 
> Actually, I believe that we should add a command-map model to the
> handlers,
> but that's a seperate issue for a separate thread.  The change
proposed in
> this e-mail is simple.
> 
> 	--- Noel
> 
> P.S.  Brownie points for whomever recognizes the origin of the subject
> header
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:james-dev-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:james-dev-
> help@jakarta.apache.org>
> 
> 
> 
>
************************************************************************
**
> This e-mail and any files transmitted with it may contain privileged
or
> confidential information. It is solely for use by the individual for
whom
> it is intended, even if addressed incorrectly. If you received this
e-mail
> in error, please notify the sender; do not disclose, copy, distribute,
or
> take any action in reliance on the contents of this information; and
> delete
> it from your system. Any other use of this e-mail is prohibited. Thank
you
> for your compliance.
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:james-dev-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:james-dev-
> help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <mailto:james-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:james-dev-help@jakarta.apache.org>


Mime
View raw message