Want to test that a parameter value is null in querystring

java

Solution

You need to re-order your comparison a bit, in particular to check for `null` first:

String editType = request.getParameter("t");
if(editType!=null && !editType.isEmpty()){
    //processing here
}

The problem you are having is that Java is trying to call the `isEmpty()` method on a `null` object, which is why you need to check for `null` first.

Java uses Short-circuit evaluation, meaning it will check your conditions from left to right, and as soon as it finds one that would let it decide the result of the entire condition, it will stop evaluating. So if `editType` ends up being null, Java will stop evaluating the entire `if` statement and won't try to call `isEmpty()` (which would result in a `NullPointerException`).

Problem

I am using a servlet to do a range of things. If a particular parameter "t" does not exist I want to do certain types of processing, if it does I want to do different things. I am trying to test the parameter t (which I save as a String called editType), using the following condition: ``` String editType = request.getParameter("t"); if(!editType.isEmpty()||!(editType==null)){ //processing here } ``` How do I do this test properly, because I am getting the problem of a nullpointerexception, because my code always seems to expect a value for "t" I need to be able to create a condition which doesn't expect t (allows it to be null), and do processing in that.

Original source