The Artima Developer Community
Sponsored Link

Java Buzz Forum
Funny little code snippet (how not to do it)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
scot mcphee

Posts: 75
Nickname: scotartt
Registered: Feb, 2004

Scot Mcphee is a Java/J2EE developer for Kaz Technology Services in Sydney, Australia.
Funny little code snippet (how not to do it) Posted: Mar 2, 2005 1:52 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by scot mcphee.
Original Post: Funny little code snippet (how not to do it)
Feed Title: SystemExxception()
Feed URL: http://www.autonomous.org/pebble/systemexxception/rss.xml?category=Java
Feed Description: java design and culture by scot mcphee
Latest Java Buzz Posts
Latest Java Buzz Posts by scot mcphee
Latest Posts From SystemExxception()

Advertisement

Here's some code that was discovered this afternoon in a home-grown validation framework. Read it and weep. Tommorrow I just have to review the CVS log to find out the developer responsible. This sort of code is all through certain sections. I kid you not.

    public Collection validateAttribute(String modelName, Object value, Collection errors)
    {
        // ignore nulls
        if (value != null)
        {
            // ensure it is a string
            if (!(value instanceof String))
            {
                try
                {
                    throw (Throwable) new ValidatorException(
                        getModelName()
                            + "."
                            + getAttributeName()
                            + " - FieldLengthRule validation rule only "
                            + "applies to String attributes");
                }
                catch (Throwable e)
                {
                    e.printStackTrace();
                }
            }

            String str = (String) value;

            if (str.length() > getLength())
            {
                errors.add(new MaxFieldLengthError(modelName, this));
            }

        }
 
        return errors;
    }

Read: Funny little code snippet (how not to do it)

Topic: Scammers Previous Topic   Next Topic Topic: [Feb 25, 2005 07:35 PST] 15 Links

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use