Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8412983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:49:03+00:00 2026-06-10T00:49:03+00:00

I am modifying some code and I am seeing consistent use of validate for

  • 0

I am modifying some code and I am seeing consistent use of “validate” for error checking.

What is the difference between Validate.notNull(x, "x cannot be empty") and if(null != x){...} and what are the advantages of one over the other?

EDIT: I am using org.apache.commons.lang.Validate

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:49:04+00:00Added an answer on June 10, 2026 at 12:49 am

    edit: assuming you are referring to org.apache.commons.lang.Validate


    The first says that calling the method with a null parameter is entirely illegal, it was a coding mistake on the part of the programmer who used the method.

    The second is just saying that there are different behaviours depending on if x is null or not.

    It becomes just a readability issue if you’re actually doing this:

    if(null != x)
    {
    //...
    } else {
      throw new IllegalArgumentException( "x cannot be empty");
    }
    

    How long is the body of that if going to be? Why is the consequence of calling the method illegally physically separated from the check for if it was called illegally? As soon as you add some more parameters, that have various different legal states, this can get really hard for others to understand. It is much friendlier to other programmers if you explicitly reject every invocation that is known to be absolutely illegal right at the start.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been modifying some code to work between Mac OS X and iPhone OS.
I have some inherited code that I am modifying. However, I am seeing something
I am modifying some code for a Blackfin processor using VisualDSP++ v. 5.0. I
I'm modifying some code that calls enumerate on a list declared via a list
I'm new to C# and directly diving into modifying some code for a project
I'm working on modifying some existing code for a payment gateway and I'm not
I am modifying some code that has a lot of jQuery but I am
However strange it sounds I need to modify some Groovy code by modifying how
I am struggling with modifying some code in Customer registration management module. Instant checkout
I'm modifying some code that I've been left with and want to add some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.