Questions tagged [null-check]

A check to see that an object has been instantiated.

A check to see that an object has been instantiated.

Typically, in a OO programming language, this is to see whether an object has been created or not.

e.g (Java example)

public void doStuff(Object obj) {
    if (obj != null) {
        // Do stuff with the object
    }
}
217 questions
-1
votes
2 answers

Check for a Null String in Java Apart from StringUtils

Is there any gun shot method to find and check for a null string without getting into exceptions?? Please do not suggest StringUtils class please. I tried everything but i am a not able to compile that with the project. I am using Tomcat and I am…
Abhijeet
  • 84
  • 1
  • 3
  • 9
-2
votes
3 answers

Is it valid to add a Null check and access the Integer value in the same line of if condition in Java

Say class Person{ Integer height; integer weight; } is it valid to check like this? Person p = new Person(); if (p.height !=null && p.height >= 1 && p.weight >=1 ){}
Ember user
  • 15
  • 2
-2
votes
1 answer

Null Guard for Nested Objects With Hierarchy Path Recognition in C#

I'm trying to create a nested Guard method (or find an existing Guard library) that would throw an exception if any object in a nested hierarchy is NULL and include the name of the object hierarchy path up to and including NULL. I also want to avoid…
AlexVPerl
  • 7,652
  • 8
  • 51
  • 83
-3
votes
2 answers

How to check a Float variable is empty or null IN JAVA

I have a Float variable which is initialised from a function returning the Float value, and there can be chance to return null in some cases. So I need to check the value in the variable is null or empty. If the value is empty I need to initialise…
Senchu Thomas
  • 518
  • 3
  • 9
  • 24
-3
votes
2 answers

A null check on two entity fields

I am working on a JAVA EE application. I am creating a form using itext. This would be saved as a pdf file. I have two fields (ID Number and Passport Number). I am currently struggling with performing a null check on them. For instance, if the ID…
akin
  • 1
  • 6
-4
votes
1 answer

How can I check if my variable is equal to NULL ? C

I have to write code which will be checking if input in my code is correct. I have to prevent entering letters, NULLs etc. I tried simple if(*tab == NULL).. but I can't compare float and void values. int avg(const float* tab, unsigned int size,…
ice592
  • 27
  • 2
  • 7
-4
votes
1 answer

While checking if a string is null in Java if (str == null ) is not right then why is (str != null && !str.isEmpty()) considered to be right

There are many answers and blogs which say that the correct way to check for null or empty string in Java is as below if(str != null && !str.isEmpty()) But then many answers say if(str == null) is a wrong way to check for null value of string as…
Sourabh
  • 119
  • 1
  • 8
1 2 3
14
15