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
vote
2 answers

Flutter null safety: The method '[]' can't be unconditionally invoked because the receiver can be 'null'

I am trying to pass data from a GridView builder with index value but getting following error: The method '[]' can't be unconditionally invoked because the receiver can be 'null'. Try making the call conditional (using '?.') or adding a null check…
1
vote
3 answers

How to create null safe block in flutter?

How do I null check or create a null safe block in Flutter? Here is an example: class Dog { final List? breeds; Dog(this.breeds); } void handleDog(Dog dog) { printBreeds(dog.breeds); //Error: The argument type 'List?' can't…
Joel Broström
  • 3,530
  • 1
  • 34
  • 61
1
vote
1 answer

How to write this sentinel loop having a null check in a cleaner, shorter and efficient way?

I am using null as a sentinel/trip value to break out of foreach: public static DataTable ExecuteQuery(string sql) { var conn = new SqlConnection(EnvironmentVariables.GetDbConnectionString()); var adapter = new SqlDataAdapter(sql, conn); …
k_rollo
  • 5,304
  • 16
  • 63
  • 95
1
vote
2 answers

Is this FindBugs nullpointer dereference error valid for spring-data Specification class?

I am getting "Possible null pointer dereference due to return value of called method" FindBugs error on following line. Specification spec = Specification.where(idSpec).and(nameSpec) .and(typeSpec).and(statusSpec); Specification is Spring data…
Smile
  • 3,832
  • 3
  • 25
  • 39
1
vote
0 answers

Can method return value nullability be inferred from the method argument nullability in JSR-305?

Suppose I have a method to parse a number and whose return value nullability contract should be inferred from its argument: @... public static Integer tryParse(@Nullable final String in, @... final Integer defaultValue) { if ( in == null ) { …
1
vote
2 answers

Short cut for a check for null and assigning a value to it if it is?

With the new C# 8 capabilities is there a short cut now for this code structure: if (App.selectedPhrases == null) App.selectedPhrases = App.DB.GetSelectedPhrases();
Alan2
  • 23,493
  • 79
  • 256
  • 450
1
vote
2 answers

Check if list is null before using linq

Using LINQ I want to check if myList != null and then perform a Where. I know I can write if (myList != null { myList.Where(p => p.x == 2 && p.y == 3); } But I want to use: myList?.Where(p => p.x == 2 && p.y == 3); Does this work? If not, what are…
Zen Zac
  • 136
  • 1
  • 9
1
vote
0 answers

Checking for nils with luascript on redis calls is not working

I want to be able to check a value from a redis hash, date, to see if it is nil (in other words, the account is active) local account = {} local accountIds = redis.call('smembers', accounts) for i, v in ipairs (accountIds) local accountDetails…
dk40149
  • 99
  • 1
  • 10
1
vote
1 answer

Nullcheck Children Chain in Typescript

Using strict null checking is great, but it's also resulting in this sort of silliness: if (x) if (x.y) if (x.y.z) if (x.y.z.stringProperty) console.log(x.y.z.stringProperty) Is there a way to do this null checking without…
calben
  • 1,328
  • 3
  • 18
  • 33
1
vote
4 answers

Is there any function difference between using != null and != undefined in javascript?

In javascript, is there any functional difference between using != null and != undefined? Is there a value you can assign to myVar which will cause these two lines of code to evaluate to different results? console.log(myVar !=…
joehinkle11
  • 491
  • 1
  • 4
  • 9
1
vote
2 answers

IsNull() function not recognized in pentaho modified java script

I am trying to assign a value to and output field based on an input field inside the modified Javascript step. I have coded as: if ( !(person_id.isNull()) ) person_nm = substr(another_field,1,10) else person_nm = ""; When I run this I get the…
KKISHORE
  • 55
  • 1
  • 1
  • 6
1
vote
4 answers

Swift: How to check a variable exists (esp. index of array)

I'm trying to check whether a variable (or rather a particular index of an array) exists in Swift. If I use if let mydata = array[1] { I get an error if the index has a value, and a crash if it doesn't. If I use if array[1] != nil { I get compiler…
benwiggy
  • 1,440
  • 17
  • 35
1
vote
4 answers

Is null check required here?

I come across this line of code in my project: String statusRecoTime = sdf.format(cal.getTime()); Then there is a null check like if (statusRecoTime != null) { //do something } I think that the statusRecoTime will never be null and there is…
Prakruti Pathik
  • 392
  • 4
  • 17
1
vote
2 answers

Insert Error Message column based on null columns in SQL

I have a table created below. CREATE TABLE TEST_NULL ( ID INT, NAME VARCHAR(10), PLACE VARCHAR(10), ADDRESS VARCHAR(10), ERRORMESSAGE VARCHAR(100) ) INSERT INTO TEST_NULL VALUES (1, 'ABC', 'BLR', 'WHT', NULL), (2, 'DEF', 'BLR', NULL, NULL), (3,…
Emraan
  • 143
  • 1
  • 12
1
vote
1 answer

Java 8 Optional / functional code optimization

There is a method that receives "someObj" and its purpose is to check the var ASet of type Set<>, iterate through it and replace its objects with the database object. For that I written the following…
Als
  • 37
  • 6